You are here

function views_aggregator_maximum in Views Aggregator Plus 8

Same name and namespace in other branches
  1. 7 views_aggregator_functions.inc \views_aggregator_maximum()

Aggregates a field group as the maximum across its members.

Using numbers mixed with non-numeric strings is not recommended.

Parameters

array $groups: An array of groups of rows, each group indexed by group value.

object $field_handler: The handler for the view column to find the maximum groups member in.

Return value

array An array of values, one for each group, plus the 'column' group.

1 string reference to 'views_aggregator_maximum'
ViewsAggregatorResultsTest::testColumnResultFunctions in tests/src/Functional/Plugin/ViewsAggregatorResultsTest.php
Test the column functions.

File

./views_aggregator_functions.inc, line 430
views_aggregator_functions.inc

Code

function views_aggregator_maximum(array $groups, $field_handler) {
  $values = [];
  foreach ($groups as $group => $rows) {
    $is_first = TRUE;
    $maximum = NULL;
    foreach ($rows as $num => $row) {
      $value = views_aggregator_get_cell($field_handler, $num, FALSE);
      if (isset($value) && trim($value) != '') {
        if ($is_first) {
          $maximum = $value;
          $is_first = FALSE;
        }
        elseif ($value > $maximum) {
          $maximum = $value;
        }
      }
    }
    if (isset($maximum)) {
      $values[$group] = $maximum;
      if (!isset($maximum_column) || $maximum > $maximum_column) {
        $maximum_column = $maximum;
      }
    }
  }
  if (isset($maximum_column)) {
    $values['column'] = $maximum_column;
  }
  return $values;
}