You are here

protected function ComplexGrouping::complexGroupingRecursiveLimit in Views Complex Grouping 8

Recursively limits the number of rows in nested groups.

File

src/Plugin/views/style/ComplexGrouping.php, line 272

Class

ComplexGrouping
Class ComplexGrouping.

Namespace

Drupal\views_complex_grouping\Plugin\views\style

Code

protected function complexGroupingRecursiveLimit(array &$group_data, $key = NULL, $level = 1) {
  $settings = $this
    ->complexGroupingSettings($level - 1);
  $settings['grouping_limit'] = $settings['grouping_limit'] != 0 ? $settings['grouping_limit'] : NULL;
  $settings['grouping_offset'] = isset($settings['grouping_offset']) ? $settings['grouping_offset'] : 0;

  // Slice up the rows according to the offset and limit.
  $group_data['rows'] = array_slice($group_data['rows'], $settings['grouping_offset'], $settings['grouping_limit'], TRUE);

  // For each row, if it appears to be another grouping, recurse again.
  foreach ($group_data['rows'] as &$data) {
    if (is_array($data) && isset($data['group']) && isset($data['rows'])) {
      $this
        ->complexGroupingRecursiveLimit($data, NULL, $level + 1);
    }
  }
}