0

I'm using Drupal 7, Voting API and Fivestar.

I try to count the number of votes for each star, and display the percentage, like :

enter image description here

It is at present possible to have only the number of total vote.

How can I achieve this? With Voting API (hook_votingapi_results_alter) or Views ?

For information, i'm using comments for rating nodes.

  • Are you familiar with the Forena module? You could write an SQL, equivalent to the existing answer, and then use it's charting facilities to create a chart (report) from it that looks similar to what you're asking for. – Pierre.Vriens May 16 '17 at 19:49
0

Once i tried to find some function that could do it. But i found just fivestar_get_votes($entity_type, $id, $tag = 'vote', $uid = NULL). It returns full voting score.

You can get some info here or on other sites.

I think it is possible with some sql queries EG:

   $query = db_select('votingapi_vote', 'vote');
   $query->condition('vote.entity_type', 'node');
   $query->condition('vote.entity_id', $nid);
   $query->condition('vote.tag', 'vote');
   $query->condition('vote.value', '60');
   $query->addField('vote', 'uid');
   $three_stars = $query->countQuery()->execute()->fetchField();

Here $nid is your your node's nid and 60 means three stars (20 - 1 star, 40 - 2 stars etc), vote.tag is tag that you assigned for your votes.

  • Thanks Andrew. It's strange that there is not a "simpler" solution. I am going to try but it seems to me heavy for the need... – Hgfdsoiu Dec 1 '16 at 13:01
  • Yes, i had the same issue and just these count queries could help me. It seems any statistics functions are not previewed for the Fivestar module. – Andrew Nim Dec 1 '16 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.