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; }
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(); }
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)); */ } }
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(); }
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>()); }
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)); } }
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); } }
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(); }
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); } }
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; }
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); } }
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)); }
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()); } }
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(); }
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 })); }
public IEnumerable<PostPart> Get(ThreadPart threadPart, VersionOptions versionOptions) { return (Get(threadPart, false, 0, 0, versionOptions)); }
public IEnumerable<PostPart> Get(ThreadPart threadPart, bool isthreaded, int skip, int count) { return Get(threadPart, isthreaded, skip, count, VersionOptions.Published); }
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); }
public IEnumerable<PostPart> Get(ThreadPart threadPart) { return Get(threadPart, VersionOptions.Published); }
public int Count(ThreadPart threadPart, VersionOptions versionOptions) { return GetParentQuery(threadPart, versionOptions).Count(); }
/* Thread */ public static string ThreadForAdmin(this UrlHelper urlHelper, ThreadPart threadPart) { return urlHelper.Action("Item", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea }); }
public PostPart GetFirstPost(ThreadPart threadPart, VersionOptions versionOptions) { return GetQuery(threadPart, versionOptions).List().FirstOrDefault(o => o.IsParentThread()); }
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() })); }
/* Thread */ public static string ThreadForAdmin(this UrlHelper urlHelper, ThreadPart threadPart) { return(urlHelper.Action("Item", "ThreadAdmin", new { threadId = threadPart.Id, area = Constants.LocalArea })); }
public PostPart GetLatestPost(ThreadPart threadPart, VersionOptions versionOptions) { return _contentManager .Query<PostPart, PostPartRecord>(versionOptions) .Join<CommonPartRecord>().Where(cpr => cpr.Container == threadPart.ContentItem.Record) .List() .LastOrDefault(); }
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() }); }
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 }); }
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() }); }
public void OpenThread(ThreadPart threadPart) { threadPart.IsClosed = false; }
private void OnThreadRemoved(RemoveContentContext context, ThreadPart part) { _countersService.UpdateForumPartCounters(part); var userId = _orchardServices.WorkContext.CurrentUser.Id; _subscriptionService.DeleteSubscription(userId, part.Id); }
public void CloseThread(ThreadPart threadPart) { threadPart.IsClosed = true; }
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() })); }
private void SetModelProperties(BuildShapeContext context, ThreadPart threadPart) { context.Shape.Forum = threadPart.ForumPart; context.Shape.StickyClass = threadPart.IsSticky ? "Sticky" : string.Empty; }
public void Delete(ThreadPart threadPart) { Get(threadPart, VersionOptions.AllVersions) .ToList() .ForEach(post => _contentManager.Remove(post.ContentItem)); }
/* 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)); }
public PostPart GetLatestPost(ThreadPart threadPart, VersionOptions versionOptions) { return GetQuery(threadPart, versionOptions).List().LastOrDefault(); }