Search code examples
kentico

Kentico: How to work with content rating through API?


I have gone through the code and webparts but couldn't figure out how rating works. All I know is the rating control provided.

I want to show rating history through an API. I also need to allow users to rate using API.

I can get rating value of a document with the query:

select DocumentRatings, DocumentRatingValue from CMS_Document WHERE [DocumentNodeID] = 123

But how to see rating history?

How rating is calculated internally?

Which are the other tables involved?


Solution

  • In Kentico, there are two different types of content ratings, both count towards the document's content rating:

    • Ratings without message
      • increments the rating value and count directly in the Document table.
    • Ratings with message (uses Message Board functionality)
      • adds a message with rating to [Board_Message] table, grouped together by a board representing the page stored in [Board_Board]
      • also increments the rating value and count directly in the Document table.

    If you're wanting to have full rating history, and be able to expose it via an API, you're probably best looking at using Message Board functionality. To do this, you can check the API documentation here or investigate how Kentico's Message Board webparts work, try checking:

    • CMS\CMSModules\MessageBoards\Controls\MessageBoard.ascx.cs
    • CMS\CMSModules\MessageBoards\Controls\Messages\MessageEdit.ascx.cs (btnOk_Click event)