You are here

function views_calc_table::pre_render in Views Calc 6

Same name and namespace in other branches
  1. 6.3 views_calc_table.inc \views_calc_table::pre_render()
  2. 7 views_calc_table.inc \views_calc_table::pre_render()

Views Method pre_render().

Build grand total and page sub total. Query calc fields using sub-view and add data.

TODO figure out what changes are needed so Views field groups will work.

File

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

Class

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

Code

function pre_render($results) {
  parent::pre_render($results);

  // If there are no calc fields, do nothing.
  if (!($calc_fields = $this
    ->get_calc_fields())) {
    return;
  }

  // If we're not getting a summary row, do nothing.
  if (!empty($this->view->views_calc_calculation)) {
    return;
  }
  $this->view->totals = array();
  $this->view->sub_totals = array();
  $this->view->views_calc_fields = $calc_fields;
  $this->view->views_calc_calculation = FALSE;

  // Subtotals and pager totals require a list of the specific
  // values to include.
  $paged = FALSE;
  if (!empty($this->view->pager) && !empty($this->view->pager['use_pager']) && !empty($this->view->pager['items_per_page']) && $this->view->total_rows > $this->view->pager['items_per_page']) {
    $ids = array();
    foreach ($this->view->result as $delta => $value) {
      $ids[] = $value->{$this->view->base_field};
    }

    // Add sub_total rows to the results.
    // We need one query per aggregation because theming needs unrenamed views field alias.
    // TODO Looks like we have problems unless we
    // force a non-page display, need to keep an eye on this.
    $this
      ->execute_summary_view($ids);
  }

  // Add grand totals to the results.
  $this
    ->execute_summary_view();
}