function views_aggregator_group_and_compress in Views Aggregator Plus 7
Same name and namespace in other branches
- 8 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()
- views_aggregator_plugin_style_table::aggregate_groups in views/
views_aggregator_plugin_style_table.inc - Aggregate and compress the View's rows into groups.
3 string references to 'views_aggregator_group_and_compress'
- views_aggregator_plugin_style_table::aggregate_groups in views/
views_aggregator_plugin_style_table.inc - Aggregate and compress the View's rows into groups.
- views_aggregator_plugin_style_table::collect_aggregation_functions in views/
views_aggregator_plugin_style_table.inc - Collect the aggregation functions from the Views UI.
- views_aggregator_plugin_style_table::options_validate in views/
views_aggregator_plugin_style_table.inc - Overrides options_validate().
File
Code
function views_aggregator_group_and_compress($view_results, $field_handler, $case = 'case-sensitive') {
$groups = array();
$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;
}