Dave Burke : Online Community and Social Business Specialist

Today's Community Server Favorites - by Post and Section

I'm Day One into a new client project updating a customized CS2008 site to CS2008.5 SP2.  It's interesting what unanticipated issues you encounter when upgrading a working site.  Today it was the display of User Favorites by "Post" and "Section," two criteria that don't exist anymore.

In CS2008, separate favorite lists were achieved with a UserData FavoritesShared property of type FavoriteType - Post, Section, None or User.  The FavoriteType enum still exists, but it's been removed from the User object, which is probably the right call.  In CS2008, separate Post and Section favorite lists were displayed like so.

<CSControl:PostList runat="server" ShowHeaderFooterOnNone="true"
     ID="FavoritePosts">
    <DisplayConditions>
        <CSControl:UserPropertyValueComparison runat="server" Operator="Contains"
             ComparisonProperty="FavoritesShared" ComparisonValue="Post" />
    </DisplayConditions>


The IFavoriteContent object still has a FavoriteType, but it's more granular now. WeblogPost, ForumPost, Forum, and so on.  To bring back the old days of the Post and Section I created a custom FavorableContentList control and its own FavorableContentQuery to include a FavoriteType Query override that I could tap into.



The User Profile page with the custom control and queryoverride looks like this.



The filtering is performed in the FavorableContentList DataSource.  I'm not completely happy with this approach, but it's very few lines of code and I'm pretty sure it will do the job. Community Server naming conventions have gotten really solid and we're only tagging Post and Section objects, so looking for "post" will put this issue to bed and enable us to keep the site conversion process moving forward.



This is one of those instances where I'm sure that I am missing some Chameleon trick, as I didn't think I had to go outside of the system on this one.  Or maybe I did.

Comments (5) | Post RSS RSS comment feed

Posted on 6/12/2009 7:52:31 PM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (5) -

6/13/2009 1:45:06 AM Permalink

I really like the custom query implementation route.  Create a class implementing QueryImplementationBase , get the query in the original queryoverrides by casting the query object to the appropiate type.  Do your stuff then return your results.  Then just implement your custom query implementation by adding it to the QueryOverrides

<QueryOverrides>
   <DRIVETongostSectionFavorableContentQuery FavoriteType="Post" runat="server" />
</QueryOverrides>

Alex Crome United Kingdom |

6/13/2009 1:45:59 AM Permalink

hmm, the :p is supposed to be a colon followed by a p - i.e. DRIVE : PostSectionFavorableContentQuery (without the spaces)

Alex Crome United Kingdom |

6/13/2009 9:47:01 AM Permalink

I was hoping Afscrome would stop by!  Thank you!  Sorry about the Smiley. I should probably turn off that extension.

So you're saying the PostSectionFavorableContentQuery is like a post-(as in "after")-query processor.  And it would derive from QueryImplementationBase?

I looked into that class, and it contains an abstract GetQueryResults<T> method and a Render() method.  I was hoping to find some example in the SDK of a control implementing it, but none exist.  If I'm on the right track and you happen to come across any examples, I'd love to follow-up. You're right, it would have been a cleaner approach to have added filtering to a QueryOverride class I could have dropped in the List control.

Always appreciate you stopping by.

daveburke United States |

6/13/2009 11:29:31 AM Permalink

It isn't exactly post query processor - it replaces the actual execution of the query from the list control.  The query that's provided into the GetQueryResults<T> method is the query object built internally by Community Server, but it hasn't been executed yet.

Below is a quick sample - this is based off the SortThreadsByGroupForumSortOrderQueryImplementation (horrible name I know) used for the Improved Active Topics page in my CS addons - alexcrome.co.uk/.../...ved-active-topics-page.aspx .  All the below sample does is reverse the order of posts in a ThreadList control.

public override List<T> GetQueryResults<T>(object query, out int totalResults)
{
    if (query is ForumThreadQuery)
    {
        ThreadSet threadSet = Threads.GetThreads(query as ForumThreadQuery);
        List<Post> posts = threadSet.AllThreads;

        List<Post> orderedPosts = new List<Post>();
        
        posts.Reverse();

        List<T> results = new List<T>();

        if (orderedPosts != null)
        {
            foreach (object o in orderedPosts)
            {
                if (!(o is T))
                    throw new InvalidCastException("The custom query results are not of the expected type.");
                else
                    results.Add(o as T);
            }
        }

        totalResults = threadSet.TotalRecords;
        return results;
    }
    else
    {
        totalResults = 0;
        return null;
    }
}

(N.B. I haven't actually tested this sample - it's a simplified version of the QueryImplementation in my CS Addons to show the main features.  You might also like to look at the source for that for further inspiration.)

Alex United Kingdom |

6/13/2009 1:25:45 PM Permalink

Ahh, okay.  Thanks so much for 'splaining that to me.  It REPLACES the query.  That would still eliminate the need for writing a custom list control, and have it use yet another custom query object.  Use the original List control, but change the query. I'll definitely consider this approach in the future.

Enjoy the rest of your weekend, Alex!

daveburke United States |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke

Copyright © 2013 Dave Burke.  All Rights reserved.