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.

1
  • 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. May 16, 2017 at 19:49

1 Answer 1

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.

2
  • 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, 2016 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, 2016 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.