Core Boxx – Stars Rating Module

TABLE OF CONTENTS

 

DOWNLOAD & INSTALLATION

First, the download links for the module, and also “installation instructions”.

 

LICENSE & DOWNLOAD

GitHubSource Forge

Core Boxx is released under the MIT License. You are free to use it for personal and commercial projects, and modify it as you see fit. On the condition that the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.

 

INSTALLATION

  • Install the Users Module first.
  • Copy/unzip this module into your existing Core Boxx project folder.
  • Access http://your-site.com/install/stars, this will automatically:
    • Import lib/SQL-Stars.sql into your database.
    • Delete PAGE-install-stars.php itself.
  • After installation, access http://your-site.com/stars for the demo page.

 

SORRY FOR THE ADS...

But someone has to pay the bills, and sponsors are paying for it. I insist on not turning Code Boxx into a "paid scripts" business, and I don't "block people with Adblock". Every little bit of support helps.

Buy Me A Coffee Code Boxx eBooks

 

FILES LIST

LIBRARIES

  • lib/LIB-Stars.php The stars rating library.
  • lib/SQL-Stars.sql Stars rating database.

API

  • lib/API-stars.php The stars rating API endpoint.

ASSETS & PAGES

  • pages/PAGE-stars.php Demo page.
  • assets/PAGE-stars.js Simple Javascript for the demo page.
  • assets/stars.webp Dummy product image.

 

 

DEVELOPMENT NOTES

It is possible to open the system up for “public stars rating”, without the need for user registration.

  • Change the user_id to a VARCHAR.
  • Then, generate a random string in the cookie as the “temporary user_id“.

But of course, this is not the safest method – This is very susceptible to spam.

 

DATABASE REFERENCE

There is only one table to store the star ratings. Feel free to add more fields as required.

 

STARS RATING TABLE

Field Description
id Primary key. The ID of the post/product/image/video – Whatever you want to add the star rating to.
user_id The user who made the rating.
rating Number of stars.

P.S. Feel free to modify it to your own needs. For examples:

  • id is currently BIGINT. Change this to VARCHAR, if you are using something like “SKU” for products.
  • If you want to allow “half stars”, change rating to decimal… The smarter way is to just change the total number of stars. E.G. If the max is 5, allowing “half stars” is as good as setting 10 stars.

 

LIBRARY REFERENCE

Lastly, the list of library functions and API endpoints.

 

STARS LIBRARY FUNCTIONS

getAll ($page)

Get all the star ratings.

  • $page Integer, for pagination. Optional.
$stars = $_CORE->Stars->get();
/* $stars = [
  ID => [
    "avg" => AVERAGE RATING,
    "num" => NUMBER OF USERS WHO RATED,
    "user" => CURRENT USER'S RATING, IF SIGNED IN
  ]
] */
get ($id)

Get star ratings for the given ID.

  • $id ID – Product, video, page, post, audio, image, whatever.
$stars = $_CORE->Stars->get(123);
/* $stars = [
  "avg" => AVERAGE RATING,
  "num" => NUMBER OF USERS WHO RATED,
  "user" => CURRENT USER'S RATING, IF SIGNED IN
] */
save ($id, $stars)

Save star rating. User must be signed in.

  • $id ID – Product, video, page, post, audio, image, whatever.
  • $stars Number of stars.
$_CORE->Stars->save(123, 5); // 5 STARS REVIEW FOR 123

 

STARS API FUNCTIONS

api/stars/save/

Save/update a star rating.

  • $_POST["id"] – Int, post/product/video/image ID.
  • $_POST["rating"] – Numer of stars

 

Leave a Comment

Your email address will not be published. Required fields are marked *