Jump to content

[Easy] How to build site architecture for "ratings"?


skoskie
 Share

Recommended Posts

Hi. I'm working on building my first processwire site, and I want to make sure I'm getting it right. I'd appreciate any feedback. 

I have a `vendor.php` template/model that will contain companies.

I need to give users the ability to rate (1-5) that vendor. So I think I need to build a `vendor_rating.php` model/template  with fields `rating` (int), `user` (ref), `vendor` (ref), and perhaps a textarea for `review`.  Then, in the vendor template I will call and cache the average vendor rating for display. I don't actually want to display the individual ratings anywhere, so I guess I still need to figure out how to do an ajax call from the front end. 

###

Here's the thing. This structure is almost identical to "comments" with only one extra field for the `rating`. So should I just extend that in some way? Or stick to my current path and make a new model/template?

Thanks!

 

Link to comment
Share on other sites

5 hours ago, skoskie said:

This structure is almost identical to "comments" with only one extra field for the `rating`.

Welcome to the forums @skoskie ?

The Comments fieldtype already includes a star rating option: https://processwire.com/blog/posts/processwire-2.6.21-upgrades-comments-more-on-pw-3.x/#new-star-ratings-for-comments-fields

  • Like 3
Link to comment
Share on other sites

Hi,

here is Rating module what I developed for project but at the end didn't use it (p.s.). and if you want you can use/test it.
It use Ajax POST on front-end and cookie to prevent multiple votes . Inside module global settings you have option to set desired max number of stars for votes (up to 10). For usage and instructions please read README.md file (and do not skip step 5.).

Here are some screenshots

Field in admin backend:

preview-admin-backend.thumb.png.9343e46c8e332cc13c80fa0c03ef6de9.png

Front-end (echo $page->my_rating_field)

preview-website-front-end.png.6ace744f78aab8a12b9ecc719eeb9ff0.png

Clean cookie (for testing)

preview-web-dev-console.thumb.jpg.47aa5a3996f087d4852c1e1e029bf2d2.jpg

 

This is not polished module version, and only what is "complex" is how to include javascript files, but there are instructions how to do that, and if that is a problem I will do some changes or feel free to contact me for free support/assistance.

Regards.

P.S.
I developed this module for project (2018.) where one task was and comments component, and that's was ok but my problem was that I first developed this module, and after that installed Ryan Comments module. I didn't know that Comments module has rating part ? !@#$%...".

 

FieldtypeRating.zip

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...