You are here

function views_plugin_style_lineage_nested::render in Taxonomy Lineage 7

Same name and namespace in other branches
  1. 6 views_plugin_style_lineage_nested.inc \views_plugin_style_lineage_nested::render()

Render the display in this style.

Overrides views_plugin_style::render

File

plugins/views_plugin_style_lineage_nested.inc, line 105
Views style plugin that allows a view to be rendered as a nested list, based on Lineage's term hierarchy.

Class

views_plugin_style_lineage_nested
Implements views_plugin_style.

Code

function render() {
  if ($this
    ->uses_row_plugin() && empty($this->row_plugin)) {
    vpr('views_plugin_style_default: Missing row plugin');
    return;
  }
  $output = '';

  // First group the rows according to the grouping field, if specified.
  $sets = $this
    ->render_grouping($this->view->result, $this->options['grouping']);
  foreach ($sets as $title => $records) {
    if ($this
      ->uses_row_plugin()) {
      $rendered = array();
      foreach ($records as $row_index => $row) {
        $this->view->row_index = $row_index;
        $rendered[$row_index] = $this->row_plugin
          ->render($row);
      }
    }

    // If the user specified a filter for the nesting, remove other levels.
    $term_name = FALSE;
    if ($this->options['filter']) {

      // Option is either a filter or an argument, marked by f and a.
      // If it's an argument
      if ($arg_name = strstr($this->options['filter'], "a_")) {
        $arg_name = substr($arg_name, 2);
        $arg = $this->display->handler->handlers['argument'][$arg_name];
        $term = $arg->argument;
      }
      elseif ($filter_name = strstr($this->options['filter'], "f_")) {
        $filter_name = substr($filter_name, 2);
        $filter = $this->display->handler->handlers['filter'][$filter_name];
        $terms = $filter->value;
        $term = array_pop($terms);
      }
      if (is_numeric($term)) {
        $term_obj = taxonomy_get_term($term);
        $term_name = $term_obj->name;
      }
      else {
        $term_name = $term;
      }
    }

    // Now, nest each grouping by the nesting field.
    $nested_set = $this
      ->render_nesting($records, $rendered, $this->options['nesting'], $term_name);

    // Determine the starting depth of the header.
    // If the user has defined a start depth, use that.
    if ($this->options['start_depth']) {
      $depth = $this->options['start_depth'];
    }
    else {
      $depth = LINEAGE_START_DEPTH;
    }

    // @todo Provide theming.
    $output .= $this
      ->nested_list($nested_set, $title, $this->options['type'], $depth);
  }
  unset($this->view->row_index);
  return $output;
}