Update comment counts to be consistent with post count:

In admin, display total # of comments (active+pending) following (optionally) by the number of pending comments

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045979
This commit is contained in:
rpaquay
2010-01-26 05:05:05 +00:00
parent 1b780e242e
commit 99a38bf865
2 changed files with 8 additions and 4 deletions

View File

@@ -9,13 +9,16 @@ namespace Orchard.Comments.Extensions {
string commentText = "";
if (item.Id != 0) {
if (commentCount == 0) {
//
int totalCommentCount = commentCount + pendingCount;
if (totalCommentCount == 0) {
commentText += html.Encode(T("no comments"));
}
else {
commentText +=
html.ActionLink(
T("{0} comment{1}", commentCount, commentCount == 1 ? "" : "s").ToString(),
T("{0} comment{1}", totalCommentCount, totalCommentCount == 1 ? "" : "s").ToString(),
"Details",
new {
Area = "Orchard.Comments",
@@ -26,7 +29,7 @@ namespace Orchard.Comments.Extensions {
}
if (pendingCount > 0) {
commentText += " - ";
commentText += " (";
commentText += html.ActionLink(T("{0} pending", pendingCount).ToString(),
"Details",
new {
@@ -35,6 +38,7 @@ namespace Orchard.Comments.Extensions {
id = item.Id,
returnUrl = html.ViewContext.HttpContext.Request.Url
});
commentText += ") ";
}
}

View File

@@ -25,7 +25,7 @@ namespace Orchard.Comments.Models {
.Where<CommonRecord>(rec => rec.Container == contentItem.Record).List();
// Count comments and create template
int count = parts.Aggregate(0, (seed, item) => seed + (ContentExtensions.Has<HasComments>(item) ? ContentExtensions.As<HasComments>(item).Comments.Count : 0));
int count = parts.Aggregate(0, (seed, item) => seed + (item.Has<HasComments>() ? item.As<HasComments>().Comments.Count : 0));
int pendingCount = parts.Aggregate(0, (seed, item) => seed + (item.Has<HasComments>() ? item.As<HasComments>().PendingComments.Count : 0));
return new CommentCountViewModel { Item = contentItem, CommentCount = count, PendingCount = pendingCount};