Exemplo n.º 1
0
        public double CalculatePopularity(ThreadPart threadPart)
        {
            double questionScore = 0D;
            IList<double> answerScores = new List<double>();

            var posts = _postService.Get(threadPart).ToArray();

            var question = posts.Where(o => o.IsParentThread()).First();
            var questionScoreRecord = _votingService.Get(vote => vote.ContentItemRecord == question.Record.ContentItemRecord && vote.Dimension == VotingConstants.RatingConstant).FirstOrDefault();
            if (questionScoreRecord != null) {
                questionScore = questionScoreRecord.Value;

                foreach (var answer in posts.Where(o => !o.IsParentThread())) {
                    var answerScoreRecord = _votingService.Get(vote => vote.ContentItemRecord == answer.Record.ContentItemRecord && vote.Dimension == VotingConstants.RatingConstant).FirstOrDefault();
                    if (answerScoreRecord != null)
                        answerScores.Add(answerScoreRecord.Value);
                }
            }

            var resultRecord = _votingService.GetResult(threadPart.ContentItem.Id, "count", VotingConstants.ViewConstant);
            var totalViews = resultRecord == null ? 0 : (int)resultRecord.Value;

            var threadCreatedDate = threadPart.As<ICommonPart>().CreatedUtc;
            var threadModifiedDate = threadPart.As<ICommonPart>().ModifiedUtc;

            var top = ((Math.Log(totalViews) * 4) + ((threadPart.PostCount * questionScore) / 5) + answerScores.Sum());
            var bottom = Math.Pow(Convert.ToDouble((threadCreatedDate.GetValueOrDefault(DateTime.Now).AddHours(1).Hour) - ((threadCreatedDate.GetValueOrDefault(DateTime.Now).Subtract(threadModifiedDate.GetValueOrDefault(DateTime.Now))).Hours / 2)), 1.5);

            return top / bottom;
        }
Exemplo n.º 2
0
        public PostPart GetPositional(ThreadPart threadPart, bool includeInappropriate, VersionOptions versionOptions,
                                      ThreadPostPositional positional) {
            var query = GetParentQuery(threadPart, versionOptions);

            if (positional == ThreadPostPositional.First)
                query = query.OrderBy(o => o.PublishedUtc);

            if (positional == ThreadPostPositional.Latest)
                query = query.OrderByDescending(o => o.PublishedUtc );

            if (!includeInappropriate)
            {
                var postPart = query.Join<PostPartRecord>().Where(post => post.IsInappropriate == false);
                return postPart
                .ForPart<PostPart>()
                .Slice(1)
                .SingleOrDefault();
            }
            // else 

            return query.ForPart<PostPart>()
                .Slice(1)
                .SingleOrDefault();


        }
Exemplo n.º 3
0
        public void UpdateForumPartCounters(ThreadPart threadPart)
        {
            var commonPart = threadPart.As<CommonPart>();
            if (commonPart != null && commonPart.Record.Container != null)
            {

                var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                // TODO: Refactor this to do the count in the DB and not make 3 DB calls.
                var threads = _threadService.Get(forumPart, false, VersionOptions.Published).ToList();
                forumPart.ThreadCount = threads.Count();
                
                var threadIds = threads.Select(t => t.Id).ToList();
                forumPart.PostCount = _contentManager.Query<PostPart, PostPartRecord>(VersionOptions.Published).Where(p => p.IsInappropriate == false)
                                            .Join<CommonPartRecord>().Where(c => threadIds.Contains(c.Container.Id) ).List().Count();
                /*
                 forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published);
                 forumPart.PostCount = _threadService
                    .Get(forumPart, VersionOptions.Published)
                    .Sum(publishedThreadPart => _postService
                        .Count(publishedThreadPart, VersionOptions.Published));
                 */
                    
            }
        }
Exemplo n.º 4
0
        public IEnumerable<IUser> GetUsersPosted(ThreadPart part) {
            var users = _commonRepository.Table.Where(o => o.Container.Id == part.Id)
                             .Select(o => o.OwnerId)
                             .Distinct();

            return _contentManager
                .GetMany<IUser>(users, VersionOptions.Published, new QueryHints())
                .ToList();
        }
Exemplo n.º 5
0
 public IEnumerable<PostPart> Get(ThreadPart threadPart, int skip, int count, VersionOptions versionOptions)
 {
     return _contentManager
         .Query(versionOptions, ContentPartConstants.Post)
         .Join<CommonPartRecord>().Where(cpr => cpr.Container == threadPart.ContentItem.Record)
         .Slice(skip, count)
         .ToList()
         .Select(ci => ci.As<PostPart>());
 }
Exemplo n.º 6
0
        private void UpdateForumPartCounters(ThreadPart threadPart) {
            var commonPart = threadPart.As<CommonPart>();
            if (commonPart != null && commonPart.Record.Container != null) {

                var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                // TODO: Refactor this to do the count in the DB and not make 3 DB calls.
                forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published);
                forumPart.PostCount = _threadService
                    .Get(forumPart, VersionOptions.Published)
                    .Sum(publishedThreadPart => _postService
                        .Count(publishedThreadPart, VersionOptions.Published));
            }
        }
Exemplo n.º 7
0
        private void UpdateThreadPartCounters(PostPart postPart)
        {
            var commonPart = postPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                ThreadPart threadPart = postPart.ThreadPart ??
                                        _threadService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                threadPart.PostCount = _postService.Count(threadPart, VersionOptions.Published);

                UpdateForumPartCounters(threadPart);
            }
        }
Exemplo n.º 8
0
        public PostPart GetPositional(ThreadPart threadPart, VersionOptions versionOptions,
                                      ThreadPostPositional positional) {
            var query = GetParentQuery(threadPart, versionOptions);

            if (positional == ThreadPostPositional.First)
                query = query.OrderBy(o => o.PublishedUtc);

            if (positional == ThreadPostPositional.Latest)
                query = query.OrderByDescending(o => o.PublishedUtc);

            return query
                .ForPart<PostPart>()
                .Slice(1)
                .SingleOrDefault();
        }
Exemplo n.º 9
0
        private void UpdateForumPartCounters(ThreadPart threadPart) {
            var commonPart = threadPart.As<CommonPart>();
            if (commonPart != null &&
                commonPart.Record.Container != null) {

                ForumPart forumPart = threadPart.ForumPart ??
                                      _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published);
                forumPart.PostCount = _threadService
                    .Get(forumPart, VersionOptions.Published)
                    .Sum(publishedThreadPart => 
                        publishedThreadPart.PostCount);
            }
        }
Exemplo n.º 10
0
        protected static void PropertySetHandlers(ActivatedContentContext context, ThreadPart part)
        {
            // add handlers that will update records when part properties are set

            part.ClosedByField.Setter(user => {
                part.Record.ClosedById = user == null
                    ? 0
                    : user.ContentItem.Id;
                return user;
            });

            // Force call to setter if we had already set a value
            if (part.ClosedByField.Value != null)
                part.ClosedByField.Value = part.ClosedByField.Value;
        }
Exemplo n.º 11
0
        private void UpdateForumPartCounters(ThreadPart threadPart)
        {
            var commonPart = threadPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                ForumPart forumPart = threadPart.ForumPart ??
                                      _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published);
                forumPart.PostCount   = _threadService
                                        .Get(forumPart, VersionOptions.Published)
                                        .Sum(publishedThreadPart =>
                                             publishedThreadPart.PostCount);
            }
        }
Exemplo n.º 12
0
        protected void PropertyHandlers(ActivatedContentContext context, ThreadPart part) {
            // Add handlers that will update records when part properties are set

            part.ClosedByField.Setter(user => {
                part.Record.ClosedById = user == null
                    ? 0
                    : user.ContentItem.Id;
                return user;
            });

            // Force call to setter if we had already set a value
            if (part.ClosedByField.Value != null)
                part.ClosedByField.Value = part.ClosedByField.Value;

            // Setup FirstPost & LatestPost fields
            part.FirstPostField.Loader(() => _postService.GetPositional(part, ThreadPostPositional.First));
            part.LatestPostField.Loader(() => _postService.GetPositional(part, ThreadPostPositional.Latest));
        }
Exemplo n.º 13
0
        private void UpdateForumPartCounters(ThreadPart threadPart)
        {
            CommonPart commonPart = threadPart.As<CommonPart>();
            if (commonPart != null &&
                commonPart.Record.Container != null) {

                ForumPart forumPart = threadPart.ForumPart ??
                                      _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As<ForumPart>();

                forumPart.ContentItem.ContentManager.Flush();

                forumPart.ThreadCount = _threadService.Get(forumPart, VersionOptions.Published).Count();
                forumPart.PostCount = _threadService
                    .Get(forumPart, VersionOptions.Published)
                    .Sum(publishedThreadPart => _postService
                        .Get(publishedThreadPart, VersionOptions.Published)
                        .Count());
            }
        }
Exemplo n.º 14
0
        public IEnumerable<PostPart> Get(ThreadPart threadPart, bool isthreaded, int skip, int count, VersionOptions versionOptions)
        {
            if (isthreaded) {
                var query = _contentManager.Query<PostPart, PostPartRecord>(versionOptions);
                // Order by the Replied on, then by the published date... That should be good enough
                var pp = query
                    .Join<CommonPartRecord>()//.OrderBy(c => c.PublishedUtc)
                    .Where(cpr => cpr.Container == threadPart.ContentItem.Record)
                    .Join<PostPartRecord>()
                    .OrderBy(p => p.RepliedOn)
                        .Slice(skip, count)
                        .ToList();

                return pp;
            }

            return GetQuery(threadPart, versionOptions)
                        .Slice(skip, count)
                        .ToList();
        }
Exemplo n.º 15
0
 public static string ThreadView(this UrlHelper urlHelper, ThreadPart threadPart, Pager pager)
 {
     return(urlHelper.Action("Item", "Thread", new { forumId = threadPart.ForumPart.Id, threadId = threadPart.Id, page = pager.Page, area = Constants.LocalArea }));
 }
Exemplo n.º 16
0
 public IEnumerable<PostPart> Get(ThreadPart threadPart, VersionOptions versionOptions)
 {
     return (Get(threadPart, false, 0, 0, versionOptions));
 }
Exemplo n.º 17
0
 public IEnumerable<PostPart> Get(ThreadPart threadPart, bool isthreaded, int skip, int count)
 {
     return Get(threadPart, isthreaded, skip, count, VersionOptions.Published);
 }
Exemplo n.º 18
0
 private IContentQuery<PostPart, CommonPartRecord> GetQuery(ThreadPart threadPart, VersionOptions versionOptions)
 {
     return _contentManager.Query<PostPart, PostPartRecord>(versionOptions)
         .Join<CommonPartRecord>()
         .Where(cpr => cpr.Container == threadPart.ContentItem.Record)
         .OrderBy(c => c.CreatedUtc);
 }
Exemplo n.º 19
0
 public IEnumerable<PostPart> Get(ThreadPart threadPart)
 {
     return Get(threadPart, VersionOptions.Published);
 }
Exemplo n.º 20
0
 public int Count(ThreadPart threadPart, VersionOptions versionOptions) {
     return GetParentQuery(threadPart, versionOptions).Count();
 }
Exemplo n.º 21
0
        /* Thread */

        public static string ThreadForAdmin(this UrlHelper urlHelper, ThreadPart threadPart) {
            return urlHelper.Action("Item", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea });
        }
Exemplo n.º 22
0
 public PostPart GetFirstPost(ThreadPart threadPart, VersionOptions versionOptions)
 {
     return GetQuery(threadPart, versionOptions).List().FirstOrDefault(o => o.IsParentThread());
 }
Exemplo n.º 23
0
 public static string ThreadOpenForAdmin(this UrlHelper urlHelper, ThreadPart threadPart)
 {
     return(urlHelper.Action("Open", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea, returnUrl = urlHelper.RequestContext.HttpContext.Request.ToUrlString() }));
 }
Exemplo n.º 24
0
        /* Thread */

        public static string ThreadForAdmin(this UrlHelper urlHelper, ThreadPart threadPart)
        {
            return(urlHelper.Action("Item", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea }));
        }
Exemplo n.º 25
0
 public PostPart GetLatestPost(ThreadPart threadPart, VersionOptions versionOptions)
 {
     return _contentManager
         .Query<PostPart, PostPartRecord>(versionOptions)
         .Join<CommonPartRecord>().Where(cpr => cpr.Container == threadPart.ContentItem.Record)
         .List()
         .LastOrDefault();
 }
Exemplo n.º 26
0
 public static string ThreadDelete(this UrlHelper urlHelper, ThreadPart threadPart) {
     return urlHelper.Action("Delete", "Post", new { contentId = threadPart.Id, area = Constants.LocalArea, returnUrl = urlHelper.RequestContext.HttpContext.Request.ToUrlString() });
 }
Exemplo n.º 27
0
 public static string ThreadView(this UrlHelper urlHelper, ThreadPart threadPart, Pager pager) {
     return urlHelper.Action("Item", "Thread", new { forumId = threadPart.ForumPart.Id, threadId = threadPart.Id, page = pager.Page, area = Constants.LocalArea });
 }
Exemplo n.º 28
0
 public static string ThreadOpenForAdmin(this UrlHelper urlHelper, ThreadPart threadPart) {
     return urlHelper.Action("Open", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea, returnUrl = urlHelper.RequestContext.HttpContext.Request.ToUrlString() });
 }
Exemplo n.º 29
0
 public void OpenThread(ThreadPart threadPart)
 {
     threadPart.IsClosed = false;
 }
Exemplo n.º 30
0
 private void OnThreadRemoved(RemoveContentContext context, ThreadPart part)
 {
     _countersService.UpdateForumPartCounters(part);
     var userId = _orchardServices.WorkContext.CurrentUser.Id; 
     _subscriptionService.DeleteSubscription(userId, part.Id);
 }
Exemplo n.º 31
0
 public void CloseThread(ThreadPart threadPart)
 {
     threadPart.IsClosed = true;
 }
Exemplo n.º 32
0
 public static string ThreadDelete(this UrlHelper urlHelper, ThreadPart threadPart)
 {
     return(urlHelper.Action("Delete", "Post", new { contentId = threadPart.Id, area = Constants.LocalArea, returnUrl = urlHelper.RequestContext.HttpContext.Request.ToUrlString() }));
 }
Exemplo n.º 33
0
 private void SetModelProperties(BuildShapeContext context, ThreadPart threadPart) {
     context.Shape.Forum = threadPart.ForumPart;
     context.Shape.StickyClass = threadPart.IsSticky ? "Sticky" : string.Empty;
 }
Exemplo n.º 34
0
 public void Delete(ThreadPart threadPart) {
     Get(threadPart, VersionOptions.AllVersions)
         .ToList()
         .ForEach(post => _contentManager.Remove(post.ContentItem));
 }
Exemplo n.º 35
0
        /* refactored into its own service 
        private void UpdateForumPartCounters(ThreadPart threadPart) {
            var commonPart = threadPart.As<CommonPart>();
            if (commonPart != null && commonPart.Record.Container != null) {

                var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published);

                // TODO: Refactor this to do the count in the DB and not make 3 DB calls.
                forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published);
                forumPart.PostCount = _threadService
                    .Get(forumPart, VersionOptions.Published)
                    .Sum(publishedThreadPart => _postService
                        .Count(publishedThreadPart, VersionOptions.Published));
            }
        }
        */
        protected void LazyLoadHandlers(ThreadPart part) {
            // Add handlers that will load content for id's just-in-time
            part.ClosedByField.Loader(() => _contentManager.Get<IUser>(part.Record.ClosedById));
        }
Exemplo n.º 36
0
 public PostPart GetLatestPost(ThreadPart threadPart, VersionOptions versionOptions)
 {
     return GetQuery(threadPart, versionOptions).List().LastOrDefault();
 }