×

Ratings

The rating functionality is added to the car collection. The review button and the rating stars are placed in the first table row.

The rating and review functionality has the following parts:

  • display the rating in catalog or detail
  • entry form for rating and review
  • overview about review and rating
  • master data form to view and release the reviews
  • top chart of the ratings
  • my ratings: list of the user ratings

The rating and review functionality is provided by 2 data definitions:

  • ratings
  • ratingssum

This beta version will be placed soon in the K8 Web Kit download.


Display the rating

masterdata/_init.php

rating_release

  • 0: no approval
  • 1: with approval

Datadefinition

head

The CSS for the rating is added.

head_end

The JavaScript for the rating is added.

masterdata / rating_active

  • 2: rating enabled for looged in user, (only 1 rating allowed)
  • 3: rating enabled for all, even anonymous (test)

The rating is added by reading the recordset. The following fields are added:

  • k8ratings: average of all ratings
  • k8ratecount: count of the ratings

HTML

The rating is added by reading the recordset. The following fields are added:

  • js_review: button for the review form
  • js_k8rating:
    • displays the rating
    • click: shows the rating overview

JavaScript

The function k8rating.datadefAddratings() adds a call back function to the datadefinition settingsexcars. The following events are added:

  • .js_review click: open the review form
  • .js_k8rating click: open the review overview

Entry form for rating and review

rating entry form

The entry form displays the "displaycolumn" of the base table. Just beneath the logged in user is shown. The form allows to enter:

  • review
  • rating

Overview of the ratings

Masterdata

Title of the reviews is the "displaycolumn" of the base table. The reviews are shown in descending order of the review date. Each review is shown with:

  • rating
  • entry date
  • user with picture and username
  • review text

Master data of the ratings

Masterdata

The master data form of the ratings gives you an overview. It allows you to release the reviews.

Top list

Masterdata

The Top list for 'excars' is called here:

Call the chartjs with the datadefID=ratingssum and the datadefID_main for the main data definition:

  • e/chartjs/ratingssum/excars
  • page=chartjs&datadefID=ratingssum &datadefID_main=excars

My ratings

My ragings

The My rating list is called here:

The ratings overview is opened with the mode=1. In this mode the userID is added to the clause:

  • ratings?mode=1
  • page=catalog&datadefID=ratings&mode=1

Depending on the rights of the ratings definition the 'edit' and 'delete' button is shown.

Technical hints

Table: k8ratings

rating table

Additional columns:

  • datecreated (time cutted form datetimecreated)
  • creatorname (username of the creator)
  • image_file (path+name of the creator image
  • rightuser_update ("0": no right)
  • rightuser_delete ("1": right granted)

Special columns:

  • basetype (table of the main data definition)
  • baseID (ID of the main table)
  • basename (displaycolumn of the main data definition

The basetext is added in the table to make it easy to use the rating functionality with different data definitions.

Data access class:

  • getEntries(), columns k8ratings and k8ratecount are added.
  • delete(), records of k8ratings are deleted
  • update(), attention: change of displaycolumn not changing the basetext in k8ratings!