You are here

protected function views_aggregator_plugin_style_table::format_numeric in Views Aggregator Plus 7

Format a raw numeric value according to the supplied handler settings.

Note: this was taken in part from views_handler_field_math::render($values)

Parameters

object $field_handler:

double $raw_value:

Return value

string Number formatted according to Views handler settings.

1 call to views_aggregator_plugin_style_table::format_numeric()
views_aggregator_plugin_style_table::render_new_value in views/views_aggregator_plugin_style_table.inc
Returns the rendered value for a new (raw) value of a table cell.

File

views/views_aggregator_plugin_style_table.inc, line 746
views_aggregator_plugin_style_table.inc

Class

views_aggregator_plugin_style_table
Style plugin to render each item as a row in a table.

Code

protected function format_numeric($field_handler, $raw_value) {
  if (!empty($field_handler->options['set_precision'])) {
    $value = number_format($raw_value, $field_handler->options['precision'], $field_handler->options['decimal'], $field_handler->options['separator']);
  }
  elseif (isset($field_handler->options['separator'])) {
    $remainder = abs($raw_value) - intval(abs($raw_value));
    $value = $raw_value > 0 ? floor($raw_value) : ceil($raw_value);
    $value = number_format($value, 0, '', $field_handler->options['separator']);
    if ($remainder && isset($field_handler->options['decimal'])) {

      // Note: substr may not be locale safe.
      $value .= $field_handler->options['decimal'] . substr($remainder, 2);
    }
  }
  elseif (is_float($raw_value)) {
    $precision = isset($this->options['column_aggregation']['precision']) ? (int) $this->options['column_aggregation']['precision'] : (int) variable_get('views_aggregator_def_precision', 2);
    $decimal = variable_get('views_aggregator_def_decimal');

    // '.'
    $separator = variable_get('views_aggregator_def_separator');

    // ','
    $value = number_format($raw_value, $precision, $decimal, $separator);
  }
  else {
    $value = $raw_value;
  }

  // Check to see if hiding should happen.
  if ($field_handler->options['hide_empty'] && empty($value) && ($value !== 0 || $field_handler->options['empty_zero'])) {
    return '';
  }

  // Should we format as a plural?
  if (!empty($field_handler->options['format_plural']) && ($value != 0 || !$field_handler->options['empty_zero'])) {
    $value = format_plural($value, $field_handler->options['format_plural_singular'], $field_handler->options['format_plural_plural']);
  }
  if (!isset($value)) {
    return '';
  }
  $prefix = isset($field_handler->options['prefix']) ? $field_handler->options['prefix'] : '';
  $suffix = isset($field_handler->options['suffix']) ? $field_handler->options['suffix'] : '';
  return $field_handler
    ->sanitize_value($prefix . $value . $suffix, 'xss_admin');
}