Jump to content

Developer Documentation

Supporting content rating in Content Items

Ratings allow members to rate content items out of 5 or 10 (depending on settings) stars.

 

How to implement ratings

First, you need to implement the rating interface in your content item model, like so:

implements \IPS\Content\Ratings

Next, add the following keys to the $databaseColumnMap property of your model. These are optional, but adding them will make your application much more efficient at returning the average rating when viewed. As usual, the value of each key should be the name of the database column that holds the value.

  • rating_average - the current average rating of the item
  • rating_total - the total sum of all ratings for the item
  • rating_hits - the number of votes the item has received

Finally, display the rating in your content view template. For example:

{$item->rating()|raw}

 

Additional model methods available

boolean canRate( [ \IPS\Member $member ] )

Indicates whether the member has permission to rate this item.

  • $member (\IPS\Member, optional)
    The member whose permissions should be checked. By default, the currently-logged in member is used.

 

float averageRating()

Returns the average rating of the items (total rating divided by number of votes).

 

string rating()

Displays star icons that indicate the current average rating. If the member has permission to rate the item, these icons will be interactive allowing the member to click them to vote.


  Report Document


×
×
  • Create New...