function views_aggregator_expression in Views Aggregator Plus 7
Aggregates a field in the column aggregation row as a math. expression.
Parameters
array $groups: An array of groups of rows, each group indexed by group value.
object $field_handler: The handler for the view column to evaluate the expression for.
string $group_exp: Currently not supported.
string $column_exp: An optional regexp to count, if omitted all non-empty group values count.
Return value
array An array of values, one for each group and one for the column.
File
Code
function views_aggregator_expression($groups, $field_handler, $group_exp = NULL, $column_exp = NULL) {
$values = array();
ctools_include('math-expr');
// This is meaningful only if some other column aggregation function took
// place before this one.
$this_item = array(
'raw' => array(
'value' => $field_handler->last_render,
),
);
// Based on views_handler_field_math::render()
$tokens = array_map('floatval', $field_handler
->get_render_tokens($this_item));
$value = strtr($column_exp, $tokens);
$expressions = explode(';', $value);
$math = new ctools_math_expr();
foreach ($expressions as $expression) {
if ($expression !== '') {
$value = $math
->evaluate($expression);
}
}
// Should we call: number_format($value, $precision, $decimal, $separator) ?
$values['column'] = $value;
return $values;
}