You are here

protected function TableRowSpan::getColSpanRows in Views Table Rowspan 8

Convert grouping sets into table rows.

Parameters

array $sets: Views grouping sets.

Return value

array An array of rows in table.

1 call to TableRowSpan::getColSpanRows()
TableRowSpan::renderGroupingSets in src/Plugin/views/style/TableRowSpan.php
@inheritdoc

File

src/Plugin/views/style/TableRowSpan.php, line 73

Class

TableRowSpan
Style plugin to merge duplicate row in table.

Namespace

Drupal\views_table_rowspan\Plugin\views\style

Code

protected function getColSpanRows($sets, $level = 0, $parent = NULL) {
  $rows = [];
  $leaf_rows = [];
  $group_field_name = $this->options['grouping'][$level]['field'];
  foreach ($sets as $set) {
    $new_level = $level + 1;
    $leaf_rows = $this
      ->getDeepestRows($set);
    $leaf_rows_index = array_keys($leaf_rows);
    $first_index = $leaf_rows_index[0];
    $this->view->rowspan[$group_field_name][$first_index] = $leaf_rows_index;
    $row = reset($set['rows']);
    if (is_array($row) && isset($row['group'])) {
      $rows += $this
        ->getColSpanRows($set['rows'], $new_level, $set);
    }
    else {
      foreach ($set['rows'] as $index => $set_row) {
        $rows[$index] = $set_row;
      }
    }
  }
  return $rows;
}