You are here

function theme_views_calc_table in Views Calc 5

Override the views table theme to add formatting for a more spreadsheet-like appearance.

File

./views_calc.module, line 642
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 theme_views_calc_table($view, $items, $type) {
  $fields = _views_get_fields();
  foreach ($items as $delta => $node) {
    $row = array();
    $set_label = FALSE;
    foreach ($view->field as $delta2 => $field) {

      // Format the calculation rows.
      if (!is_numeric($delta)) {
        if (!empty($node->{$field}['queryname'])) {
          $cell['data'] = theme('views_handle_field', $fields, $field, $node);
        }
        elseif (!$set_label) {
          $cell['data'] = t($delta);
          $set_label = TRUE;
        }
        else {
          $cell['data'] = ' ';
        }

        // give numeric data its own class
        if (is_numeric($cell['data'])) {
          $cell['class'] = 'view-footer-number';
        }
        else {
          $cell['class'] = 'view-footer';
        }
        $cell['id'] = "view-field-{$field['queryname']}-{$delta}";

        // Format the main table rows.
      }
      else {

        // Format calculated row values.
        $cell['data'] = theme('views_handle_field', $fields, $field, $node);

        // Give numeric data its own class.
        if (is_numeric($cell['data'])) {
          if (strstr($field['queryname'], 'row_')) {

            // format calculation columns
            $cell['class'] = 'view-total-number';
          }
          else {

            // format main table columns
            $cell['class'] = 'view-field-number';
          }
        }
        else {
          if (strstr($field['queryname'], 'row_')) {

            // format calculation columns
            $cell['class'] = 'view-total';
          }
          else {

            // format main table columns
            $cell['class'] = 'view-field';
          }
        }
        $cell['id'] = "view-field-{$field['queryname']}";
      }
      $row[] = $cell;
    }
    $rows[] = $row;
  }
  return theme('table', $view->table_header, $rows);
}