CommunityServer: Adding the "Post Date" Sort Order
I've made a handful of modifications to the Community Server software that I use as a back-end to a website of mine (TheDailyWTF.com). Since quite a few people seem to be using this software, I thought I'd share what I've done. If you find this post valuable, let me know in the comments and I'll post more in the future.
One of the first things I noticed when switching from .TEXT to CommunityServer::Blogs Beta 2 was that it lacked the ability to sort threads by the date of the first post. Since I have a custom RSS feed that displays the ten most recent posts, this definitely would not do. So I'll explain how I added this very easy change ...
Step one is to edit the Enumerations\SortThreadsBy.cs (in CommunityServerComponents) and add the emboldened code:
public enum SortThreadsBy {
PostDate,
LastPost,
ThreadAuthor,
TotalReplies,
TotalViews,
TotalRatings,
Subject }
Next, we need to change the data access code. This is in ForumsSqlDataProvider.cs in the SqlDataProvider class. Go the the overloaded "public override ThreadSet GetThreads" method and locate the region "#region Order By and Active Topics". Just add the following block under "switch (sortBy)":
case SortThreadsBy.PostDate:if (sortOrder == SortOrder.Ascending)
orderClause.Append("PostDate");
else
orderClause.Append("PostDate DESC");
break;
Finally, we need to add the option to the picklist. This change is appropriately in Controls\Utility\ThreadSortDropDownList.cs in the CommunityServerForums project. The items are added in the constructor, so you can easily modify it to this:
public ThreadSortDropDownList() {
// Add countries //
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_LastPost"), ((int) SortThreadsBy.LastPost).ToString()));
Items.Add(new ListItem("Post Date", ((int) SortThreadsBy.PostDate).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_StartedBy"), ((int) SortThreadsBy.ThreadAuthor).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Ratings"), ((int) SortThreadsBy.TotalRatings).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Views"), ((int) SortThreadsBy.TotalViews).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Replies"), ((int) SortThreadsBy.TotalReplies).ToString()));
}
Note how I didn't add it to the resource file and the subsequent code to do that. Since I don't plan on supporting more than one language on the site, there's really no need to do this.
And that's that. Told ya it was an easy modifcation ;-).