You are here

function views_aggregator_count in Views Aggregator Plus 7

Same name and namespace in other branches
  1. 8 views_aggregator_functions.inc \views_aggregator_count()

Aggregates a field group as a count of the number of group members.

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 count groups members in.

string $group_regexp: An optional regexp to count, if omitted all non-empty group values count.

string $column_regexp: An optional regexp to count, if omitted all non-empty group values count.

Return value

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

File

./views_aggregator_functions.inc, line 239
views_aggregator_functions.inc

Code

function views_aggregator_count($groups, $field_handler, $group_regexp = NULL, $column_regexp = NULL) {
  $values = array();
  $count_column = 0;
  $regexp = isset($group_regexp) ? $group_regexp : $column_regexp;
  if (preg_match('/[a-zA-Z0-9_]+/', $regexp)) {

    // Interpret omitted brace chars in the regexp as a verbatim text match.
    $regexp = "/{$regexp}/";
  }
  foreach ($groups as $group => $rows) {
    $count = 0;
    foreach ($rows as $num => $row) {
      $cell = views_aggregator_get_cell($field_handler, $num, TRUE);
      if (isset($cell) && $cell != '' && (empty($regexp) || preg_match($regexp, $cell))) {
        $count++;
      }
    }
    $values[$group] = $count;
    $count_column += $count;
  }
  $values['column'] = $count_column;
  return $values;
}