I would like to calculate the number of people who voted 1, 2, 3, 4, and 5 on a particular node. Is there a way to do this using the existing api or would I need to query the database directly?

Thanks!

Comments

knowledges33ker’s picture

I need this as well. I'm trying to use fivestar with flag and workflow. I can't figure out how to trigger an action on the event of "x" users voting on a node. The events I want to trigger (if possible) are adding a flag and changing the current workflow state to a new state. Does anyone know if this is possible?

venkatd’s picture

Okay, so I hunted around the votingapi module and could not find anything. I decided to write a query somewhat like this:

$query = db_query("SELECT value, COUNT(*) AS count FROM {votingapi_vote}
  WHERE content_id = %d
  AND content_type = 'node'
  AND tag = 'vote'
  GROUP BY value", $nid);

Maybe I should create an issue in votingapi for an aggregate function so that I can call a function like this:

$results = votingapi_aggregate('count', 'value', array('content_id' => $nid, 'tag' => 'vote', 'content_type' => 'node'), 'value');

Where the last parameter 'value' is an optional parameter to group the results. Thoughts?

Edit: I posted a function here that does the trick: http://drupal.org/node/698602.

dbt102’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Drupal 6 is now end of life, and is no longer supported. So Drupal 6 issues for Fivestar are being closed as "Closed (won't fix)". However, we don't want users who are porting from Drupal 6 to 7 to feel unwanted, so if you have any migration issues, please open them as Drupal 8 issues.