function views_handler_cumulative_field::render in Views Cumulative Field 7
Render callback handler.
Return the markup that will appear in the rendered field.
Overrides views_handler_field_numeric::render
File
- includes/
views_handler_cumulative_field.inc, line 73 - Custom views handler definition.
Class
- views_handler_cumulative_field
- Custom handler class.
Code
function render($values) {
$datafield = $this->options['data_field'];
$this->additional_fields['cumulative_field_data'] = $values->_field_data['nid']['entity']->{$datafield}['und'][0]['value'] + $this->additional_fields['cumulative_field_data'];
$value = $this->additional_fields['cumulative_field_data'];
// 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 {
$remainder = abs($value) - intval(abs($value));
$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'] . substr($remainder, 2);
}
}
// 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');
}