You are here

protected function Table::setAggregatedGroupValues in Views Aggregator Plus 8

Write the aggregated results back into the View's rendered results.

Parameters

array $groups: An array of groups, indexed by group name.

array $values: An array of value arrays, indexed by field name first and group second.

int $group_aggregation_results: Options flag, whether to aggregate the values or not.

1 call to Table::setAggregatedGroupValues()
Table::preRender in src/Plugin/views/style/Table.php
Note that this class being a views_plugin, rather than a views_handler, it does not have a post_execute() function.

File

src/Plugin/views/style/Table.php, line 1129

Class

Table
Style plugin to render each item as a row in a table.

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

protected function setAggregatedGroupValues(array $groups, array $values, $group_aggregation_results) {
  $subtotals = [];
  $label_prefix = $this->options['group_aggregation']['result_label_prefix'] ? $this->options['group_aggregation']['result_label_prefix'] : '';
  $label_suffix = $this->options['group_aggregation']['result_label_suffix'] ? $this->options['group_aggregation']['result_label_suffix'] : '';
  $field_handlers = $this->view->field;
  foreach ($this->options['info'] as $field_name => $options) {
    if (!empty($options['has_aggr']) && in_array('views_aggregator_group_and_compress', $options['aggr'], FALSE)) {
      $field_label = $field_name;
    }
    foreach ($groups as $group => $rows) {
      if ($group != 'column' && isset($values[$field_name][$group])) {
        $current_row = 1;
        foreach ($rows as $num => $row) {
          $separator = $this->options['info'][$field_name]['aggr_par'];
          $group_rows = count(array_keys($rows));
          if ($group_aggregation_results == 1) {
            if ($current_row == $group_rows) {
              if (isset($field_label)) {
                $field_value = $this
                  ->getCell($field_handlers[$field_label], $num, TRUE);
                $subtotals[$num][$field_label] = $this
                  ->t($label_prefix) . trim($field_value) . $this
                  ->t($label_suffix);
              }
              $subtotals[$num][$field_name] = $this
                ->setCell($field_handlers[$field_name], $num, $values[$field_name][$group], $separator);
            }
          }
          else {
            $this
              ->setCell($field_handlers[$field_name], $num, $values[$field_name][$group], $separator);

            // Only need to set on the first member of the group.
            break;
          }
          $current_row++;
        }
      }
    }
  }
  $this->view->subtotals = $subtotals;
}