Jump to content

Developer Documentation

Implementing the reviews model

How to implement reviews

Instead of extending \IPS\Content\Comment, your model should extend \IPS\Content\Review (which itself extends \IPS\Content\Comment but adds additional functionality specific to reviews).

class _YourClass extends \IPS\Content\Reviews
{
	//...
}

There are a number of additional keys you need to add to your model's $databaseColumnMap. Each value should be the database column name in your table that holds the value for each property.

  • rating
    Required. The rating value submitted with the review.
  • votes_total
    Required. The total number of helpful/unhelpful votes received.
  • votes_helpful
    Required. The number of votes that indicated the review was helpful.
  • votes_data
    Required. A JSON object containing details about who has voted helpful/unhelpful (as well as what their vote was).

 

Changes required to the content item model

You'll also need to make changes to the content item model. For comments you added a $commentClass property to the model, but for reviews this is named $reviewClass:

public static $reviewClass = 'IPS\yourapp\YourClass';

You'll also need to add elements to the content item model's $databaseColumnMap. Below, we show the key you used for comments, and how it differs in name for reviews. Note that if your applications uses both comments and reviews, you should add both the comment and review keys to the column map.

  • num_comments becomes num_reviews
  • last_comment becomes last_review
  • last_comment_by becomes last_review_by
  • unapproved_comments becomes unapproved_reviews

In addition, some model properties and methods have different names to reflect their use with reviews. As above, if your application uses both comments and reviews, you should declare/implement both types. Consult the comments documentation for implementation details; aside from the property/method name, the implementation is identical.

  • static $commentsPerPage becomes static $reviewsPerPage
  • commentPageCount() becomes reviewPageCount()
  • commentPagination() becomes reviewPagination()
  • comments() becomes reviews()
  • commentForm() becomes reviewForm()
  • lastCommentPageUrl() becomes lastReviewPageUrl()
  • canComment() becomes canReview()
  • moderateNewComments() becomes moderateNewReviews()
  • canViewHiddenComments() becomes canViewHiddenReviews()

There is one additional method available to the content item model that is present only when reviews are used:

 

integer averageReviewRating()

Returns the average rating for all reviews on the item.


  Report Document


×
×
  • Create New...