Implementing Content Ratings for Sharepoint via site template Part 1

contentrating
I had a request to create the typical content rating system you see on the web but for Sharepoint 2007-the catch? I needed to deploy as a site template that could be deployed easily by site collection owners.
 
What did I come up with you ask? 
 
First, it’s amazing what the new aggregate data sources in Sharepoint 2007 and x-path can do:)
 
You can use the new linked datasouces to access data in other lists, web services, and even SQL sources.
 
Then using X-path, XSL, javascript, and customizing the dataview web-part you have some options for doing interesting things in site templates that you might not have thought about before or would immediately consider server-side code a requirement.  
 

The Approach
Displaying the ratings from within your list/document library. 
 
The basic approach is to tie your custom list to a second list that stores the rating using a common id.  You can use javascript for this.
Then on your custom list use an x-path query to get a handle to the rows you want and then render the star rating appropriately.   
 
Warning: I haven’t provided all the steps here and there are a few to getting the different parts of the solution connected and working together-this example covers only the bare essentials of displaying the ratings from within your list/document library but should get you off to a good start.
 
Coming in Part 2: The custom XSL for displaying data on the view ratings page.
Coming in Part 3: Pre-populating the ratings fields and filtering the results set by adding parameters to the aggregate datasource select query. 
Coming in Part 4: How to configure a datasource to be easily deployed as part of a site template deployed within a site collection on a different server.

 

Displaying the aggregated rating for a specific list item or document:
Once I linked to the list where I stored all my ratings it was a matter of building an x-path query to aggregate data from the ratings list in order to display my star ratings in the custom list:
 
From the row item template on a custom list contained with a DVWP in XSLT format:
 
<xsl:template name="dvt_1.rowview">
  <xsl:param name="ParentPath" />
  <xsl:param name="SrcPos" />
  <xsl:variable name="dvt_1ParentRow" select="current()" />
  <xsl:variable name="FilteredRatedQuestions" select="../../../Call_Question_Ratings/Rows/Row[@QuestionID=$dvt_1ParentRow/@ID]" />
 
Once I had a handle to a proper rowset then I could perform whatever calculations I deem necessary to display the appropriate star ratings:
 
In my scenario a five star rating based on a simple average sufficed and used the images already available in the layouts directory.
 
<xsl:choose>
          <xsl:when test="../../../Call_Question_Ratings/Rows/Row/@QuestionID=$dvt_1ParentRow/@ID">
          
             <xsl:variable name="dvt_1RowRating" select="format-number(sum($FilteredRatedQuestions/@Rating)div (@_x0023_Rated), &quot;###0.0;-###0.0&quot;)"/>
            <xsl:if test="$dvt_1RowRating &gt;= ‘2’ and $dvt_1RowRating  &lt; ‘3’">
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
             </xsl:if>
             
             <xsl:if test="$dvt_1RowRating &gt;= ‘3’ and $dvt_1RowRating  &lt; ‘4’">
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
             </xsl:if>
            
             <xsl:if test="$dvt_1RowRating &gt;= ‘4’ and $dvt_1RowRating  &lt; ‘5’">
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
             </xsl:if>
            
             <xsl:if test="$dvt_1RowRating &gt;= ‘5’ and $dvt_1RowRating  &lt; ‘6’">
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
              <img src="\_layouts\images\addtofavorites.gif" border="0" align="absmiddle"/>
             </xsl:if> 
           
                    
         </xsl:when>
         <xsl:otherwise>
             <img src="\_layouts\images\addtofavorites.gif" border="0"/>
            </xsl:otherwise>
         </xsl:choose>
 
Cheers!
Advertisements

3 thoughts on “Implementing Content Ratings for Sharepoint via site template Part 1

  1. It seems to be exactly what I need!It\’s very interesting, but where are the part 2,3 and 4?

  2. ileana,
     
    check out the recent posts section on my blog\’s homepage:
    Re-Publish Implementing Content Ratings for Sharepoint via SP Designer-Part II Step by Step Content Rating Part III-adding a customized sort expression Sharepoint Content Rating Site Template Update (this is an .stp site template that can be uploaded and used on MOSS 2007 site collection using the collaboration portal template. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s