phpratingdrupal-fivestar

Integrating a weight into 5 star voting system?


I already have a 5 star rating system in place (user votes 1-5...and average score is displayed - i have a page where they vote and it inserts into the DB there username and vote), however I now want to improve it by integrating some sort of weight which functions solely to increase the impact your vote has on the average score of the content. It makes your vote "weigh" more than it would otherwise.

I currently have a $level (which is a number between 1-10 each user has...where 10 is the highest therefore having the most effect) which I'd like to use for consideration.

I'm just not sure on how to go by doing this.


Solution

  • If a user has level X, you can make his/her vote weigh X level 1 votes. You can add another field "weight" to the table, and show an average of vote*weight:

    SELECT AVG(weight * vote)
    FROM rating
    WHERE item = ? 
    

    (where ? is you needed id)

    If you think this is too complicated for your needs (and you already store the user that made the vote), you can use this query:

    SELECT AVG(r.weight * u.level)
    FROM rating
    JOIN user ON r.user_id = u.id
    WHERE r.item = ?