You are here

function fivestar_field_formatter in Fivestar 5

Implementation of hook_field_formatter().

The $node argument is necessary so that filter access can be checked on node preview.

File

./fivestar_field.inc, line 255
Provides CCK integration for fivestar module

Code

function fivestar_field_formatter($field, $item, $formatter, $node) {
  if (empty($item['rating'])) {
    $item['rating'] = 0;
  }
  if (empty($field['stars'])) {
    $field['stars'] = 5;
  }
  switch ($formatter) {
    case 'rating':
      return round(100 / $item['rating'], 1) / $field['stars'];
    case 'percentage':
      return $item['rating'];
    default:
      return theme('fivestar_static', $item['rating'], $field['stars']);
  }
}