I'm working on a multi-axis rating system and using views custom fields to do the averaging, but I am hoping for some code help to show the rating as something OTHER than stars.

My current averaging code:

$avg = round(($data->appearance+  $data->aroma +  $data->flavor + $data->feel + $data->overall )/5);
print theme('fivestar_static', $avg, '5');

That shows the average rating as stars, but I am looking to show the rating 2 other ways:
1. overall percent, such as: "80"
2. # of stars numerically, such as: "4.75 / 5"

Any thoughts?

Comments

youkho’s picture

Looking for a solution for this too some have an idea?

madaxe’s picture

In Drupal 6 I got my fivestar node vote to print out numerical display with the following code

$avg = votingapi_select_results(array('content_id' => $node->nid,'function' => 'average'));
$votesavg = ($avg[0]['value']);
print number_format($votesavg, 1, '.', '');

This prints out the result with 1 decimal place. To have more decimal places then change the 1 in the last line to whatever number of decimal places you wish

e.g. print number_format($votesavg, 4, '.', ''); would give 4 decimal places.

Anybody feel free to improve this code. I'm not exactly Mr Sheen when it comes to code, I can at times be a bit more of a Charlie Sheen.

dbt102 credited dbt102.

dbt102’s picture

Issue summary: View changes
Status: Active » Fixed
dbt102’s picture

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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.