You are here

function views_plugin_style::render_grouping in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 plugins/views_plugin_style.inc \views_plugin_style::render_grouping()
  2. 7.3 plugins/views_plugin_style.inc \views_plugin_style::render_grouping()

Group records as needed for rendering.

Parameters

$records: An array of records from the view to group.

$grouping_field: The field id on which to group. If empty, the result set will be given a single group with an empty string as a label.

Return value

The grouped record set.

2 calls to views_plugin_style::render_grouping()
views_plugin_style::render in plugins/views_plugin_style.inc
Render the display in this style.
views_plugin_style_jump_menu::render in plugins/views_plugin_style_jump_menu.inc
Render the display in this style.

File

plugins/views_plugin_style.inc, line 271

Class

views_plugin_style
Base class to define a style plugin handler.

Code

function render_grouping($records, $grouping_field = '') {

  // Make sure fields are rendered
  $this
    ->render_fields($this->view->result);
  $sets = array();
  if ($grouping_field) {
    foreach ($records as $index => $row) {
      $grouping = '';

      // Group on the rendered version of the field, not the raw.  That way,
      // we can control any special formatting of the grouping field through
      // the admin or theme layer or anywhere else we'd like.
      if (isset($this->view->field[$grouping_field])) {
        $grouping = $this
          ->get_field($index, $grouping_field);
        if ($this->view->field[$grouping_field]->options['label']) {
          $grouping = $this->view->field[$grouping_field]->options['label'] . ': ' . $grouping;
        }
      }
      $sets[$grouping][$index] = $row;
    }
  }
  else {

    // Create a single group with an empty grouping field.
    $sets[''] = $records;
  }
  return $sets;
}