Index: views_calc_table.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/views_calc/views_calc_table.inc,v retrieving revision 1.17 diff -u -r1.17 views_calc_table.inc --- views_calc_table.inc 13 Jun 2009 17:05:38 -0000 1.17 +++ views_calc_table.inc 4 Oct 2010 09:12:29 -0000 @@ -98,7 +98,7 @@ && !empty($this->view->pager['items_per_page'])) { $nids = array(); foreach ($this->view->result as $delta => $value) { - $nids[] = $value->nid; + $nids[] = $value->{$this->view->base_field}; } // Add sub_total rows to the results. // TODO Looks like we have problems unless we @@ -116,7 +116,36 @@ } } } - + + // When grouping the views_calc table is sent to the theme layer multiple times + // On each table output we want to overwrite the grand totals with the grouped totals + // this snippet prepares the necessary array with extra fieldreferences + $grouping = $this->view->style_options['grouping']; + if($grouping) { + $field_alias = $this->view->field[$grouping]->field_alias; + $nids = array(); + foreach ($this->view->result as $delta => $value) { + $nids[$value->{$field_alias}][] = $value->{$this->view->base_field}; + } + + // Add group_total rows to the results. + foreach ($calc_fields as $calc => $field) { + foreach($nids as $group_field_alias => $group_nids) { + if ($summary_view = views_get_view($this->view->name, TRUE)) { + //$summary_view->set_display($this->view->current_display); + $summary_view->set_arguments($this->view->args); + $summary_view->views_calc_calculation = $calc; + $summary_view->views_calc_nids = $group_nids; + $summary_view->views_calc_group_total = TRUE; + $summary_view->is_cacheable = FALSE; + $summary_view->preview(); + $this->view->group_totals[$group_field_alias][] = array_shift($summary_view->result); + $this->query(); + } + } + } + } + // Add grand totals to the results. foreach ($calc_fields as $calc => $field) { if ($summary_view = views_get_view($this->view->name)) { @@ -148,6 +177,9 @@ if (!empty($this->view->views_calc_sub_total)) { $this->query_sub_total(); } + elseif (!empty($this->view->views_calc_group_total)) { + $this->query_sub_total(); + } else { $this->query_total(); } @@ -186,7 +218,7 @@ } // TODO This won't work right with relationships, need a fix here. if (!empty($this->view->views_calc_nids)) { - $this->view->query->add_where(NULL, "node.nid IN (%s)", implode(',', $this->view->views_calc_nids)); + $this->view->query->add_where(NULL, "%s.%s IN (%s)", $this->view->base_table, $this->view->base_field, implode(',', $this->view->views_calc_nids)); } } Index: theme.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/views_calc/theme.inc,v retrieving revision 1.9 diff -u -r1.9 theme.inc --- theme.inc 23 Apr 2009 18:32:48 -0000 1.9 +++ theme.inc 4 Oct 2010 09:12:29 -0000 @@ -172,7 +172,17 @@ foreach ($process_available as $process) { $vars[$process] = array(); $added_label = array(); - foreach ($columns as $field => $column) { + + // grouping support + $grouping = $view->style_options['grouping']; + $grouping_alias = $fields[$grouping]->field_alias; + if($grouping && $process == 'totals') { + $first_result = array_shift($result); + $current_group = $first_result->{$grouping_alias}; + $totals = $group_totals[$current_group]; + } + + foreach ($columns as $field => $column) { $field_alias = $fields[$field]->field_alias; if ($field == $column && empty($fields[$field]->options['exclude'])) { foreach ($$process as $num => $row) {