Fixes QuickMenu and it's query

This commit is contained in:
Shannon
2015-03-03 12:39:51 +11:00
parent 71fba109c4
commit 93fd82abb5
3 changed files with 63 additions and 25 deletions
@@ -18,8 +18,7 @@
var roles = System.Web.Security.Roles.GetRolesForUser();
//TODO: This is apparently for topics that the current user has been active in?? This is certainly not the case.
var latestTopics = topicService.GetAll(maxCount: 100);
var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100);
<div class="close">
<i class="icon-Delete"></i>Close
@@ -78,30 +77,29 @@
@foreach (var topic in latestTopics)
{
if (topic.MemberId == member.Id || topic.LatestReplyAuthor == member.Id)
{
var forum = Umbraco.TypedContent(topic.ParentId);
var forum = Umbraco.TypedContent(topic.ParentId);
<a href="@topic.GetUrl()" class="forum-thread">
<div class="row">
<div class="col-xs-10 col-md-8">
<div class="forum-thread-text">
<h3>@topic.Title</h3>
@if (!string.IsNullOrEmpty(topic.LastReplyAuthorName))
{
<p>Reply by @topic.LastReplyAuthorName @topic.Updated.Day</p>
}
</div>
<a href="@topic.GetUrl()" class="forum-thread">
<div class="row">
<div class="col-xs-10 col-md-8">
<div class="forum-thread-text">
<h3>@topic.Title</h3>
@if (!string.IsNullOrEmpty(topic.LastReplyAuthorName))
{
<p>
Reply by @topic.LastReplyAuthorName <br />
@topic.Updated.ConvertToRelativeTime()
</p>
}
</div>
<div class="col-xs-2 col-md-4">
<div class="category frontend"><span class="cat">@forum.Name</span></div>
</div>
</div>
</a>
}
<div class="col-xs-2 col-md-4">
<div class="category frontend"><span class="cat">@forum.Name</span></div>
</div>
</div>
</a>
}
</div>
+1 -1
View File
@@ -74,7 +74,7 @@ namespace our.Examine
{
var ts = new TopicService(ApplicationContext.Current.DatabaseContext);
foreach (var topic in ts.GetAll(maxCount:int.MaxValue))
foreach (var topic in ts.QueryAll(maxCount:int.MaxValue))
{
//Add the item to the index..
var simpleDataSet = new SimpleDataSet { NodeDefinition = new IndexedNode(), RowData = new Dictionary<string, string>() };
+42 -2
View File
@@ -48,6 +48,43 @@ namespace uForum.Services
return _databaseContext.Database.Page<ReadOnlyTopic>(page, take, sql);
}
/// <summary>
/// Returns an in-memory collection of topics that a given member has participated in
/// </summary>
/// <param name="memberId"></param>
/// <param name="ignoreSpam"></param>
/// <param name="maxCount"></param>
/// <returns></returns>
public IEnumerable<ReadOnlyTopic> GetLatestTopicsForMember(int memberId, bool ignoreSpam = true, int maxCount = 100)
{
var sql = new Sql().Select("TOP " + maxCount + " " +
@"forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName,
forumComments.body as commentBody, forumComments.created as commentCreated, forumComments.haschildren,
forumComments.id as commentId, forumComments.isSpam as commentIsSpam, forumComments.memberId as commentMemberId, forumComments.parentCommentId,
forumComments.position, forumComments.score, forumComments.topicId")
.From("forumTopics")
.LeftOuterJoin("forumComments").On("forumTopics.id = forumComments.topicId")
.LeftOuterJoin("umbracoNode u1").On("(forumTopics.latestReplyAuthor = u1.id AND u1.nodeObjectType = '39EB0F98-B348-42A1-8662-E7EB18487560')")
.LeftOuterJoin("umbracoNode u2").On("(forumTopics.memberId = u2.id AND u2.nodeObjectType = '39EB0F98-B348-42A1-8662-E7EB18487560')")
.Where<Topic>(topic => topic.LatestReplyAuthor == memberId || topic.MemberId == memberId);
if (ignoreSpam)
{
sql.Where<Topic>(x => x.IsSpam != true);
sql.Where("forumComments.id IS NULL OR (forumComments.isSpam <> 1)");
}
sql
.OrderByDescending<Topic>(x => x.Updated)
.OrderByDescending<Comment>(comment => comment.Created);
var result = _databaseContext.Database.Fetch<ReadOnlyTopic, ReadOnlyComment, ReadOnlyTopic>(
new TopicCommentRelator().Map,
sql);
return result;
}
/// <summary>
/// Returns a READER of all topics to be iterated over
/// </summary>
@@ -56,7 +93,7 @@ namespace uForum.Services
/// Default is 1000
/// </param>
/// <returns></returns>
public IEnumerable<ReadOnlyTopic> GetAll(bool ignoreSpam = true, int maxCount = 1000)
public IEnumerable<ReadOnlyTopic> QueryAll(bool ignoreSpam = true, int maxCount = 1000)
{
var sql = new Sql().Select("TOP " + maxCount + " " +
@"forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName,
@@ -76,7 +113,10 @@ namespace uForum.Services
sql.Where("forumComments.id IS NULL OR (forumComments.[parentCommentId] = 0)");
sql.OrderBy<Topic>(x => x.Updated).OrderByDescending<Comment>(comment => comment.Created);
//start with the most recent
sql
.OrderByDescending<Topic>(x => x.Updated)
.OrderByDescending<Comment>(comment => comment.Created);
var result = _databaseContext.Database.Query<ReadOnlyTopic, ReadOnlyComment, ReadOnlyTopic>(
new TopicCommentRelator().Map,