You are here

public function views_handler_field_numeric::render in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 handlers/views_handler_field_numeric.inc \views_handler_field_numeric::render()
  2. 6.2 handlers/views_handler_field_numeric.inc \views_handler_field_numeric::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

2 calls to views_handler_field_numeric::render()
views_handler_field_node_new_comments::render in modules/comment/views_handler_field_node_new_comments.inc
Render the field.
views_handler_field_search_score::render in modules/search/views_handler_field_search_score.inc
Render the field.
3 methods override views_handler_field_numeric::render()
views_handler_field_math::render in handlers/views_handler_field_math.inc
Render the field.
views_handler_field_node_new_comments::render in modules/comment/views_handler_field_node_new_comments.inc
Render the field.
views_handler_field_search_score::render in modules/search/views_handler_field_search_score.inc
Render the field.

File

handlers/views_handler_field_numeric.inc, line 118
Definition of views_handler_field_numeric.

Class

views_handler_field_numeric
Render a field as a numeric value.

Code

public function render($values) {
  $value = $this
    ->get_value($values);

  // Output nothing if the value is null.
  if (is_null($value)) {
    return '';
  }

  // Hiding should happen before rounding or adding prefix/suffix.
  if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
    return '';
  }
  if (!empty($this->options['set_precision'])) {
    $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
  }
  else {
    $point_position = strpos($value, '.');
    $remainder = $point_position === FALSE ? '' : substr($value, $point_position + 1);
    $value = $value > 0 ? floor($value) : ceil($value);
    $value = number_format($value, 0, '', $this->options['separator']);
    if ($remainder) {

      // The substr may not be locale safe.
      $value .= $this->options['decimal'] . $remainder;
    }
  }

  // Should we format as a plural.
  if (!empty($this->options['format_plural'])) {
    $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']);
  }
  return $this
    ->sanitize_value($this->options['prefix'], 'xss') . $this
    ->sanitize_value($value) . $this
    ->sanitize_value($this->options['suffix'], 'xss');
}