Hi,

Fivestar module has multi axis voting capability to assign multiple voting types per node, such as runner, walker, ...
At this point, in Views, I couldn't find out how to average the overall votes for a node given for each axis. For example,

runner: 80 %
walker: 40 %
overall vote: 40 + 80 / 2 = 60 %

Tried relationship with no filter for axis, it provides lists the same content multiple times in the view and it does not provide overall vote correctly.

Please let me know if there is a solution for this problem.

Thx

Comments

x-drup’s picture

Subscribe!

ymeiner’s picture

If you only need the number you can actualy use math field. add the fields, exclude them and calculate the result.

huslabs’s picture

same issue !!
need to make a view sort the results by ( Who is the best !! ) ??

subscribed :)

x-drup’s picture

/**
* Implementation of hook_votingapi_results_alter().
*/

function mymodule_votingapi_results_alter(&$results, $content_type, $content_id) {
$vote_avg_sum = 0;
$vote_avg_count = 0;
$vote_tags = 0;

foreach($results as $tag => $data) {
if($tag != 'vote') {
$vote_avg_sum += $data['percent']['average'];
$vote_avg_count += $data['percent']['count'];
$vote_tags++;
}
}
if($vote_tags > 0) {
$results['vote']['percent']['average'] = $vote_avg_sum/$vote_tags;
$results['vote']['percent']['count'] = $vote_avg_count/$vote_tags;
}
}

it works for me. in views with relation ships by axis, and sortable by votes results.

Louis Bob’s picture

Is this code ok for the D7 version of the module?

legolasbo’s picture

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

Drupal 6 is no longer supported. Closing old issues to clean up the issue queue.

Please reopen and update this issue if this is still an issue in the D7 or D8 version.