In a view where I aggregate results and display AVG for percentage ratings in Fivestar widget it displays One star for aggregated value 0.
No vote was generated for this content and it still shows like I have 20%.

I debugged it and it found out this:

rate.module
function rate_preprocess_rate_template_fivestar(&$variables)
line 1243:
if (round($results['rating'] / $percent_per_star) >= $i && !$results['empty']) {

$results['rating'] is null!
So it tries to divide null with 25 ($percent_per_star = 100 / ($count - 1);) and returns 0
This, together with !$results['empty'] which return TRUE because $results['empty'] = FALSE is enough to pass this check and fill the first of five stars.

My solution is to check if $results['rating'] is not null by adding it to if sentence like this:

if ($results['rating'] && round($results['rating'] / $percent_per_star) >= $i && !$results['empty']) {

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alesr’s picture

Status: Active » Needs review
FileSize
554 bytes

Patch attached.

alesr’s picture

Version: 7.x-1.7 » 7.x-1.x-dev