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']) {
Comment | File | Size | Author |
---|---|---|---|
#1 | rate-fivestar-one-star-for-no-rating-2196455-1.patch | 554 bytes | alesr |
Comments
Comment #1
alesr CreditAttribution: alesr commentedPatch attached.
Comment #2
alesr CreditAttribution: alesr commented