comparison views_calc_table.inc @ 3:5635080385bd tip

Merge patch with 1.x-dev
author Franck Deroche <franck@defr.org>
date Fri, 07 Aug 2009 15:20:12 +0200
parents cedf71edacf5 b0a976e17cc7
children
comparison
equal deleted inserted replaced
1:cedf71edacf5 3:5635080385bd
1 <?php 1 <?php
2 // $Id: views_calc_table.inc,v 1.15 2009/04/22 02:21:41 karens Exp $ 2 // $Id: views_calc_table.inc,v 1.17 2009/06/13 17:05:38 karens Exp $
3 /** 3 /**
4 * @file 4 * @file
5 * Copied from the table style plugin. 5 * Copied from the table style plugin.
6 */ 6 */
7 7
76 * TODO 76 * TODO
77 * figure out what changes are needed so Views field groups will work. 77 * figure out what changes are needed so Views field groups will work.
78 */ 78 */
79 function pre_render($results) { 79 function pre_render($results) {
80 parent::pre_render($results); 80 parent::pre_render($results);
81 81
82 // If there are no calc fields, do nothing. 82 // If there are no calc fields, do nothing.
83 if (!$calc_fields = $this->get_calc_fields()) { 83 if (!$calc_fields = $this->get_calc_fields()) {
84 return; 84 return;
85 } 85 }
86 // If we're not getting a summary row, do nothing. 86 // If we're not getting a summary row, do nothing.
87 if (!empty($this->view->views_calc_calculation)) { 87 if (!empty($this->view->views_calc_calculation)) {
88 return; 88 return;
89 } 89 }
90
91 $this->view->totals = array(); 90 $this->view->totals = array();
92 $this->view->sub_totals = array(); 91 $this->view->sub_totals = array();
93 92
94 // Subtotals and pager totals require a list of the specific 93 // Subtotals and pager totals require a list of the specific
95 // values to include. 94 // values to include.
112 $this->view->totals[] = $this->do_calculation($calc, FALSE); 111 $this->view->totals[] = $this->do_calculation($calc, FALSE);
113 } 112 }
114 } 113 }
115 114
116 function do_calculation($calc, $sub_total, $nids = array()) { 115 function do_calculation($calc, $sub_total, $nids = array()) {
116 // TODO Looks like we have problems unless we
117 // force a non-page display, need to keep an eye on this.
117 if ($summary_view = views_get_view($this->view->name)) { 118 if ($summary_view = views_get_view($this->view->name)) {
118 $summary_view->set_display($this->view->current_display); 119 $summary_view->set_display($this->view->current_display);
119 $summary_view->set_arguments($this->view->args); 120 $summary_view->set_arguments($this->view->args);
120 $summary_view->pager['items_per_page'] = 0; 121 $summary_view->pager['items_per_page'] = 0;
121 $summary_view->views_calc_calculation = $calc; 122 $summary_view->views_calc_calculation = $calc;
122 $summary_view->views_calc_nids = $nids; 123 $summary_view->views_calc_nids = $nids;
123 $summary_view->views_calc_sub_total = $sub_total; 124 $summary_view->views_calc_sub_total = $sub_total;
124 $summary_view->is_cacheable = FALSE; 125 $summary_view->is_cacheable = FALSE;
125 $summary_view->execute(); 126 $summary_view->preview();
126 return array_shift($summary_view->result); 127 return array_shift($summary_view->result);
127 } 128 }
128 return ''; 129 return '';
129 } 130 }
130 131
166 $this->view->query->groupby = array(); 167 $this->view->query->groupby = array();
167 168
168 foreach ($this->view->field as $field) { 169 foreach ($this->view->field as $field) {
169 $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field; 170 $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field;
170 $query_alias = $field->field_alias; 171 $query_alias = $field->field_alias;
172 // Bail if we have a broken handler.
173 if ($query_alias == 'unknown') {
174 continue;
175 }
171 if (in_array($field->field, $fields)) { 176 if (in_array($field->field, $fields)) {
172 // Calculated fields. 177 // Calculated fields.
173 $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); 178 $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias);
174 $this->view->query->add_table($field->table, NULL, NULL, $field->table); 179 $this->view->query->add_table($field->table, NULL, NULL, $field->table);
175 } 180 }
205 $this->view->query->groupby = array(); 210 $this->view->query->groupby = array();
206 211
207 foreach ($this->view->field as $field) { 212 foreach ($this->view->field as $field) {
208 $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field; 213 $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field;
209 $query_alias = $field->field_alias; 214 $query_alias = $field->field_alias;
215 // Bail if we have a broken handler.
216 if ($query_alias == 'unknown') {
217 continue;
218 }
210 $this->view->query->add_table($field->table, NULL, NULL, $field->table); 219 $this->view->query->add_table($field->table, NULL, NULL, $field->table);
211 if (!empty($fields) && in_array($field->field, $fields)) { 220 if (!empty($fields) && in_array($field->field, $fields)) {
212 // Calculated fields. 221 // Calculated fields.
213 $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); 222 $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias);
214 } 223 }