You are here

function views_calc_table::execute_summary_view in Views Calc 7

Same name and namespace in other branches
  1. 6.3 views_calc_table.inc \views_calc_table::execute_summary_view()
  2. 6 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 146
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();
  $summary_view
    ->set_display($this->view->current_display);

  // copy the query object by value not by reference!
  $summary_view->query = clone $this->view->query;
  $summary_view
    ->set_display($this->view->current_display);

  // 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;

  // If it's a subtotal calc, we're filtering the page elements by $ids.
  $summary_view->views_calc_ids = $ids;
  $summary_view->views_calc_fields = $this->view->views_calc_fields;
  $summary_view->build_info = $this->view->build_info;
  $summary_view->field = $this->view->field;

  // Call the method which adds aggregation fields before rendering
  // In an earlier version this was done in the overridden method query() of this class
  // which is not called for some reason here.
  $this
    ->add_aggregation_fields($summary_view);

  // We don't need any offset in the calculation queries because
  // the statement does only return the records with the passed ids
  $summary_view->query->offset = 0;

  // 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);

  // All results of the calculation queries are used, so we don't page them.
  // Else we will loose the global pager from the page view.
  $summary_view
    ->set_items_per_page(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);
    }
  }
}