Kentico CMS 6.0 Developer's Guide

Using the Content rating web part

Using the Content rating web part

Previous topic Next topic Mail us feedback on this topic!  

Using the Content rating web part

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

The Content rating web part is stored in the Content rating web part category. The web part can be added to any web part zone on any page of your website, enabling users of the website to rate the content of the currently displayed document. It has three default appearance modes:

 

Stars

Radio-buttons

Drop-down list

devguide_clip0515

devguide_clip0516

devguide_clip0517

 

It is also possible to create other appearance modes by creating your custom controls. These must be placed in ~/CMSAdminControls/ContentRating/Controls/ and inherit from ExtendedControls.AbstractRatingControl.cs, just like the default ones.

 

Below is a list of specific properties of the web part:

 

Rating value - this property can be used to set the displayed rating value explicitly. A value from the <0,1> interval can be used, while 0 represents the lowest rating and 1 represents the highest rating on the scale defined by the Max rating value. If blank, the real rating calculated as an average value of particular ratings is displayed.

Rating type - appearance of the web part. Stars, Radio-buttons or Drop-down list can be chosen, as depicted above.

Max rating value - size of the rating scale. For example, if 7 is entered, rating will be possible on a scale from 1 to 7.

 

Show results - if checked, overall rating results will be displayed. If unchecked, users can rate, but don't see the results.

Result message - message showing overall rating results. The {0} macro shows overall rating (for one decimal rounding, you can use {0:0.#} ). {1} displays the total number of votes.

Message after rating - text message displayed after a user submits their rating. Macros that can be used: {0} your rating, {1} overall rating, {2} overall number of votes.

 

Check permissions - if checked, permissions set by the Allow for public and Hide to unauthorized roles properties will be checked.

Allow zero value - if checked, users are allowed to submit ratings with zero value (no rating value selected).

Error message - message displayed to users who try to submit a rating with zero value. Applied only if the Allow zero value option is disabled.

Anonymous users can rate - if checked, rating will be allowed to public unauthorized users. If unchecked, only authenticated users will be allowed to rate.

Check if user rated - if checked, users will be allowed to vote only once. To indicate that the user already voted, Kentico CMS stores a DocRated cookie in your web browser, the cookie contains NodeIDs of the rated documents separated by the tube character (e.g. |4|61|229|230|228|369|).

Hide to unauthorized users - if checked, the web part will be hidden to unauthorized users.

 

Example: Adding news ratings

 

You can place the web part on any page of your website to enable users to rate the content of this particular page. In the following example, we will add the web part to news items on the sample Corporate Site. A similar result can also be achieved using transformations, as described in Displaying ratings in transformations.

 

1. Sign in to CMS Desk as administrator (blank password by default). Switch to the Design mode and select News -> Your first news from the content tree.

 

2. Click the Add web part (AddWebPart) icon at the top right corner of the zoneLeft web part zone. Select the Content rating\Content rating web part and click OK.

 

3. In the Web part properties window, just configure the following property:

 

Show for document types: cms.news; this ensures that the web part will be displayed only for the particular news items and not for the list of news on the title page of the News section.

 

Leave the rest of the properties at their default values and click OK.

 

4. Now go to the live site and view the Your first news news item. You should see the web part below the news text as in the screenshot below. Now try rating!

 

devguide_clip0518

 

5. If you switch back to CMS Desk and view Properties of the news item, you should see the Rating property on the General tab. This property reflects the current rating of the selected document. All ratings are recalculated to 10 step scale and displayed as stars here, no matter what the settings of the web part are. You can reset the value using the Reset button.

 

devguide_clip0546