You are here

function _fivestar_get_element_default_value in Fivestar 7.2

Helper function to get the correct default value for a fivestar element.

Parameters

$element: The fivestar element

Return value

The default value for the element.

1 call to _fivestar_get_element_default_value()
fivestar_expand in ./fivestar.module
Process callback for fivestar_element -- see fivestar_element()

File

./fivestar.module, line 802

Code

function _fivestar_get_element_default_value($element) {
  if (isset($element['#default_value'])) {
    $default_value = $element['#default_value'];
  }
  else {
    switch ($element['#settings']['style']) {
      case 'average':
        $default_value = $element['#values']['average'];
        break;
      case 'user':
        $default_value = $element['#values']['user'];
        break;
      case 'smart':
        $default_value = !empty($element['#values']['user']) ? $element['#values']['user'] : $element['#values']['average'];
        break;
      case 'dual':
        $default_value = $element['#values']['user'];
        break;
      default:
        $default_value = $element['#values']['average'];
    }
  }
  for ($i = 0; $i <= $element['#stars']; $i++) {
    $this_value = ceil($i * 100 / $element['#stars']);
    $next_value = ceil(($i + 1) * 100 / $element['#stars']);

    // Round up the default value to the next exact star value if needed.
    if ($this_value < $default_value && $next_value > $default_value) {
      $default_value = $next_value;
    }
  }
  return $default_value;
}