function views_aggregator_range in Views Aggregator Plus 7
Same name and namespace in other branches
- 8 views_aggregator_functions.inc \views_aggregator_range()
Aggregates a field group as a range. Example: 5.5 - 14.9.
Parameters
array $groups: An array of groups of rows, each group indexed by group value.
object $field_handler: The handler for the view column.
string $separator_group: The range separator between minimum and maximum values of the group range, not used here.
string $separator_column: The range separator between minimum and maximum values of the column range, not used here.
Return value
array An array of ranges, one for each group and one for the 'column'. Each range is an array of two elements, so they can be individually rendered.
File
Code
function views_aggregator_range($groups, $field_handler, $separator_group = NULL, $separator_column = NULL) {
$values = array();
foreach ($groups as $group => $rows) {
$is_first = TRUE;
foreach ($rows as $num => $row) {
$value = views_aggregator_get_cell($field_handler, $num, FALSE);
if ($is_first) {
$minimum = $maximum = $value;
$is_first = FALSE;
}
elseif (isset($value) && $value < $minimum) {
$minimum = $value;
}
elseif (isset($value) && $value > $maximum) {
$maximum = $value;
}
}
$values[$group] = $minimum == $maximum ? $minimum : array(
$minimum,
$maximum,
);
if (!isset($minimum_column) || $minimum < $minimum_column) {
$minimum_column = $minimum;
}
if (!isset($maximum_column) || $maximum > $maximum_column) {
$maximum_column = $maximum;
}
}
$values['column'] = $minimum_column == $maximum_column ? $minimum_column : array(
$minimum_column,
$maximum_column,
);
return $values;
}