It's been a while for a more code-heavy, Operation MindCrime Community Server post. I haven't been giving Queensryche their due.
We're an underground revolution working overtime
There's a job for you in the system boy with nothing to sign
This post addresses a CS Forums Space question on how to sort the Aggregated Post List Sorting by Post Title. Interesting Queensryche topic!
The first thing to remember is that sorting is dictating by the BlogThreadQuery we build in AggregatePostList, which is passed to the Weblog Data Provider. The BlogThreadQuery.SortBy property supports three sort options as listed in the BlogThreadSortBy enum.
public enum BlogThreadSortBy
{
MostRecent = 0,
MostViewed = 1,
MostComments = 2,
PostTitle = 3 // Added
};
We want to sort by title, so we'd need to add an enumator member name and value, say, PostTitle = 3.
The BlogThreadQuery is created with the new query.SortBy = PostTitle value and sent off to the Weblog Data Provider where a @sqlPopulate parameter is created with a helper BuildQuery() method.
public override ThreadSet GetBlogThreads(BlogThreadQuery query)
{
.....
using(SqlCommand command = new SqlCommand(databaseOwner +
".[cs_shared_Threads_GetThreadSet]", connection))
{
command.CommandType = CommandType.StoredProcedure;
.....
command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value =
new BlogThreadQueryBuilder(query,databaseOwner).BuildQuery() ;
This is a sample @sqlPopulate value returned from BuildQuery().
SET Transaction Isolation Level Read UNCOMMITTED Select P.PostID From dbo.cs_Posts P right join dbo.cs_Threads t on (P.ThreadID = T.ThreadID) inner join dbo.cs_Sections S on S.SectionID = P.SectionID where P.SettingsID = 1000 and P.SectionID in (4,17,18,5,3) and S.IsActive = 1 and S.SectionID in (4,17,18,5,3) and S.SectionID = P.SectionID and S.ApplicationType = 1 and P.ApplicationPostType & 1 <> 0 and P.PostConfiguration & 3 = 3 and P.IsApproved = 1 and P.PostDate <= getdate() and P.IsApproved = 1 and P.PostDate <= getdate() Order by P.PostDate desc
What we need to do, of course, is change the "Order by P.PostDate desc." The way to change this is by applying the new BlogThreadSortBy.PostTitle enumerator member to the CS.SqldataProvider.BlogThreadQueryBuilder.cs ApplySort() method switch statement.
switch (query.SortBy) {
case BlogThreadSortBy.MostViewed:
sb.Append(" Order by P.TotalViews");
break;
case BlogThreadSortBy.MostComments:
sb.Append(" Order by TotalReplies");
break;
case BlogThreadSortBy.PostTitle: // Added
sb.Append(" Order by P.Subject");
break;
default:
sb.Append(" Order by P.PostDate");
break;
}
The only thing we'll want to do yet in our scenario to display by post title is to add a query.SortOrder property when building the original query in AggreagtePostlist.cs to display A-Z rather than the default sortby DESC with a Z-A listing.
[Queensryche]