You are here

function theme_fivestar_formatter_rating in Fivestar 7.2

Same name and namespace in other branches
  1. 6.2 includes/fivestar.field.inc \theme_fivestar_formatter_rating()
  2. 6 fivestar_field.inc \theme_fivestar_formatter_rating()

Theme function for 'rating' fivestar field formatter.

File

includes/fivestar.theme.inc, line 132
Provides the theming functions for fivestar.

Code

function theme_fivestar_formatter_rating($variables) {
  $element = $variables['element'];
  if (empty($element['#item']['average'])) {
    $element['#item']['average'] = 0;
  }

  // Get number of stars.
  $stars = empty($element['#instance_settings']['stars']) ? 5 : $element['#instance_settings']['stars'];
  $average = $element['#item']['average'];

  // Rating is X out of Y stars.
  $rating = round($average / 100 * $stars, 1);
  $output = $rating . '/' . $stars;
  return $output;
}