You are here

function views_calc_table::pre_render in Views Calc 7

Same name and namespace in other branches
  1. 6.3 views_calc_table.inc \views_calc_table::pre_render()
  2. 6 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.

Overrides views_plugin_style::pre_render

File

./views_calc_table.inc, line 110
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;
  $maxitems = $this->view
    ->get_items_per_page();

  // check if Subtotals are displayed
  if (!empty($maxitems) && $this->view->query->pager
    ->get_total_items() > $maxitems) {
    $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();
}