You are here

function views_calc_views_pre_view in Views Calc 5

Implementation of hook_views_pre_view()

File

./views_calc.module, line 486
This module will allow you to add calculated fields to views tables and compute (SUM, COUNT, AVG, etc) columns of numeric data in a views table.

Code

function views_calc_views_pre_view(&$view, &$items) {
  if (!(_views_calc_is_calc_view($view) && _views_calc_has_items($items))) {
    return;
  }

  // Add summary rows to the table.
  $cols = (array) variable_get('views_calc_' . $view->vid . '_col', '');
  $col_calc = (array) variable_get('views_calc_' . $view->vid . '_col_calc', '');
  $summary_view = drupal_clone($view);
  foreach ($col_calc as $calc) {
    $summary_view->views_calc_calculation = $calc;
    $summary_view->is_cacheable = FALSE;
    $values = views_build_view('items', $summary_view, $summary_view->args);
    $items[$calc] = $values['items'][0];
  }
}