function views_aggregator_range in Views Aggregator Plus 8
Same name and namespace in other branches
- 7 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.
1 string reference to 'views_aggregator_range'
- ViewsAggregatorResultsTest::testColumnResultFunctions in tests/
src/ Functional/ Plugin/ ViewsAggregatorResultsTest.php - Test the column functions.
File
Code
function views_aggregator_range(array $groups, $field_handler, $separator_group = NULL, $separator_column = NULL) {
$values = [];
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 : [
$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 : [
$minimum_column,
$maximum_column,
];
return $values;
}