function views_aggregator_group_and_compress in Views Aggregator Plus 8
Same name and namespace in other branches
- 7 views_aggregator_functions.inc \views_aggregator_group_and_compress()
Aggregates the supplied view results into grouped rows.
This function must be selected for one column (field) in the results table. Its parameters and return value are different from the other aggregation functions.
Parameters
object $view_results: The result rows as they appear on the view object.
object $field_handler: The handler for the view column to group rows on.
string $case: Whether group-inclusion is case-sensitive (the default).
Return value
array An array of groups, keyed by group value first and row number second.
1 call to views_aggregator_group_and_compress()
- Table::aggregateGroups in src/
Plugin/ views/ style/ Table.php - Aggregate and compress the View's rows into groups.
5 string references to 'views_aggregator_group_and_compress'
- Table::aggregateGroups in src/
Plugin/ views/ style/ Table.php - Aggregate and compress the View's rows into groups.
- Table::collectAggregationFunctions in src/
Plugin/ views/ style/ Table.php - Collect the aggregation functions from the Views UI.
- Table::setAggregatedGroupValues in src/
Plugin/ views/ style/ Table.php - Write the aggregated results back into the View's rendered results.
- Table::validateOptionsForm in src/
Plugin/ views/ style/ Table.php - Validate the options form.
- ViewsAggregatorResultsTest::testGroupResultFunctions in tests/
src/ Functional/ Plugin/ ViewsAggregatorResultsTest.php - Test the group functions.
File
Code
function views_aggregator_group_and_compress($view_results, $field_handler, $case = 'case-sensitive') {
$groups = [];
$is_set = FALSE;
$is_ci = strcasecmp($case, 'case-insensitive') === 0 || $case == t('case-insensitive');
foreach ($view_results as $num => $row) {
// Compression takes place on the rendered values. Two hyperlinks with the
// same display texts but different hrefs will end up in different groups.
$group_value = views_aggregator_get_cell($field_handler, $num, TRUE);
if ($is_ci) {
$is_set = FALSE;
foreach (array_keys($groups) as $existing_group) {
if (strcasecmp($group_value, $existing_group) === 0) {
$groups[$existing_group][$num] = $row;
$is_set = TRUE;
break;
}
}
}
if (empty($is_set)) {
$groups[$group_value][$num] = $row;
}
}
// Caution: experiment!
if (FALSE) {
// For each group remove cells that are identical to the the ones above
// them in the same group.
foreach ($groups as $group_value => &$rows) {
$first_row = NULL;
foreach ($rows as $num => &$row) {
if (!isset($first_row)) {
$first_row = $row;
}
else {
foreach ((array) $row as $field_name => $cell) {
if ($field_name != '_field_data' && $cell == $first_row->{$field_name}) {
unset($row->{$field_name});
}
}
}
}
}
}
return $groups;
}