You are here

function views_calc_table::execute_summary_view in Views Calc 6

Same name and namespace in other branches
  1. 6.3 views_calc_table.inc \views_calc_table::execute_summary_view()
  2. 7 views_calc_table.inc \views_calc_table::execute_summary_view()
1 call to views_calc_table::execute_summary_view()
views_calc_table::pre_render in ./views_calc_table.inc
Views Method pre_render().

File

./views_calc_table.inc, line 124
Copied from the table style plugin.

Class

views_calc_table
Style plugin to render each item as a row in a table.

Code

function execute_summary_view($ids = array()) {

  // Clone view for local subquery.
  $summary_view = $this->view
    ->clone_view();

  // Rebuild pager information later.
  // Suppress pager functionality completely.
  // We're filtering the page elements by $ids.
  unset($summary_view->pager);

  // Check access to the given display.
  if (!$this->view
    ->access($this->view->current_display)) {
    return NULL;
  }

  // Make sure the view is completely valid.
  $errors = $summary_view
    ->validate();
  if (is_array($errors)) {
    foreach ($errors as $error) {
      drupal_set_message($error, 'error');
    }
    return NULL;
  }

  // intialize summary view
  $is_subtotal = !empty($ids);
  $summary_view->preview = TRUE;
  $summary_view->is_cacheable = FALSE;
  $summary_view->views_calc_calculation = TRUE;
  $summary_view->views_calc_sub_total = $is_subtotal;
  $summary_view->views_calc_ids = $ids;
  $summary_view->views_calc_fields = $this->view->views_calc_fields;

  // set display
  $summary_view
    ->set_display($this->view->current_display);

  // Execute and render the view in preview mode. Note that we only store
  // the result if the executed view query returns any result.
  $summary_view
    ->pre_execute($this->view->args);

  // Don't change any global pager during this query.
  // Else we will loose the global pager from the page view.
  $summary_view->pager['use_pager'] = 0;
  $summary_view
    ->execute();
  $summary_view
    ->post_execute();
  if (!empty($summary_view->result)) {
    if ($is_subtotal) {
      $this->view->sub_totals = array_shift($summary_view->result);
    }
    else {
      $this->view->totals = array_shift($summary_view->result);
    }
  }
}