diff --git theme.inc theme.inc index b5b3fad..6635063 100644 --- theme.inc +++ theme.inc @@ -71,21 +71,21 @@ $vars['rows'] = array(); return; } - + drupal_add_css(drupal_get_path('module', 'views_calc') .'/views_calc.css'); - + // We need the raw data for this grouping, which is passed in as $vars['rows']. // However, the template also needs to use for the rendered fields. We // therefore swap the raw data out to a new variable and reset $vars['rows'] // so that it can get rebuilt. $result = $vars['rows']; $vars['rows'] = array(); - + $options = $view->style_plugin->options; $handler = $view->style_plugin; $vars['options'] = $options; $hide_details = $options['detailed_values']; - + $fields = &$view->field; $columns = $handler->sanitize_columns($options['columns'], $fields); @@ -164,11 +164,15 @@ // Add totals. $vars['totals'] = array(); $vars['sub_totals'] = array(); + $vars['group_totals'] = array(); + if (isset($view->group_total)) { + views_calc_table_total($vars, 'group_totals', $view->group_total); + } if ($view->total_rows > $view->pager['items_per_page'] && $view->sub_totals) { views_calc_table_total($vars, 'sub_totals', $view->sub_totals); } - if ($view->totals) { + if ($view->totals && $view->last_group) { views_calc_table_total($vars, 'totals', $view->totals); } @@ -231,12 +235,7 @@ // Identify which is the sub total and which the grand total // when both are provided. if (empty($added_label[$calc])) { - if ($key == 'sub_totals') { - $label = t("Page !Calculation", array("!Calculation" => $calc)); - } - else { - $label = t("Total !Calculation", array("!Calculation" => $calc)); - } + $label = theme('views_calc_summary_label', $key, $calc); $vars[$key][$calc][$column] = $label; $added_label[$calc] = TRUE; } @@ -247,4 +246,33 @@ } } } +} + +/** + * Returns the label for the Views Calc summary row. + * + * @param $total_type + * One of the following strings: + * 'sub_total': This is a page sub-total. + * 'group_total': This is a group sub-total. + * 'total': This is a grand total. + * @param $calc_type + * The type of summary calculation, such as 'SUM', 'COUNT', etc. + * + * @return + * A label for the summary row. + */ +function theme_views_calc_summary_label($total_type = 'total', $calc_type = 'SUM') { + switch ($total_type) { + case 'sub_totals': + return t("Page !Calculation", array("!Calculation" => $calc_type)); + + case 'group_totals': + return t("Subtotal !Calculation", array("!Calculation" => $calc_type)); + + case 'totals': + default: + return t("Total !Calculation", array("!Calculation" => $calc_type)); + + } }