Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { | |
36 | ||
6a488035 TO |
37 | protected $_charts = array( |
38 | '' => 'Tabular', | |
39 | 'barChart' => 'Bar Chart', | |
40 | 'pieChart' => 'Pie Chart', | |
41 | ); | |
42 | ||
49e1ea9f | 43 | protected $_customGroupExtends = array( |
44 | 'Contact', | |
45 | 'Individual', | |
46 | 'Contribution', | |
47 | ); | |
48 | ||
6a488035 TO |
49 | public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report'); |
50 | ||
51 | protected $lifeTime_from = NULL; | |
430ae6dd TO |
52 | protected $lifeTime_where = NULL; |
53 | ||
74cf4551 | 54 | /** |
74cf4551 | 55 | */ |
00be9182 | 56 | public function __construct() { |
49e1ea9f | 57 | $this->_autoIncludeIndexedFieldsAsOrderBys = 1; |
9d72cede | 58 | $yearsInPast = 10; |
6a488035 | 59 | $yearsInFuture = 1; |
9d72cede EM |
60 | $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture); |
61 | $count = $date['maxYear']; | |
6a488035 TO |
62 | while ($date['minYear'] <= $count) { |
63 | $optionYear[$date['minYear']] = $date['minYear']; | |
64 | $date['minYear']++; | |
65 | } | |
66 | ||
d62fab33 RN |
67 | // Check if CiviCampaign is a) enabled and b) has active campaigns |
68 | $config = CRM_Core_Config::singleton(); | |
69 | $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); | |
70 | if ($campaignEnabled) { | |
71 | $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); | |
72 | $this->activeCampaigns = $getCampaigns['campaigns']; | |
73 | asort($this->activeCampaigns); | |
f813f78e | 74 | } |
d62fab33 | 75 | |
6a488035 | 76 | $this->_columns = array( |
a130e045 DG |
77 | 'civicrm_contact' => array( |
78 | 'dao' => 'CRM_Contact_DAO_Contact', | |
79 | 'grouping' => 'contact-field', | |
80 | 'fields' => array( | |
81 | 'sort_name' => array( | |
82 | 'title' => ts('Donor Name'), | |
83 | 'default' => TRUE, | |
84 | 'required' => TRUE, | |
6a488035 | 85 | ), |
a130e045 DG |
86 | 'first_name' => array( |
87 | 'title' => ts('First Name'), | |
88 | ), | |
49e1ea9f | 89 | 'middle_name' => array( |
90 | 'title' => ts('Middle Name'), | |
91 | ), | |
a130e045 DG |
92 | 'last_name' => array( |
93 | 'title' => ts('Last Name'), | |
94 | ), | |
49e1ea9f | 95 | 'id' => array( |
96 | 'no_display' => TRUE, | |
97 | 'required' => TRUE, | |
98 | ), | |
99 | 'gender_id' => array( | |
100 | 'title' => ts('Gender'), | |
101 | ), | |
102 | 'birth_date' => array( | |
103 | 'title' => ts('Birth Date'), | |
104 | ), | |
105 | 'age' => array( | |
106 | 'title' => ts('Age'), | |
107 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', | |
108 | ), | |
109 | 'contact_type' => array( | |
110 | 'title' => ts('Contact Type'), | |
111 | ), | |
112 | 'contact_sub_type' => array( | |
113 | 'title' => ts('Contact Subtype'), | |
114 | ), | |
115 | ), | |
116 | 'grouping' => 'contact-fields', | |
117 | 'order_bys' => array( | |
118 | 'sort_name' => array( | |
119 | 'title' => ts('Last Name, First Name'), | |
120 | 'default' => '1', | |
121 | 'default_weight' => '0', | |
122 | 'default_order' => 'ASC', | |
123 | ), | |
124 | 'first_name' => array( | |
125 | 'name' => 'first_name', | |
126 | 'title' => ts('First Name'), | |
127 | ), | |
128 | 'gender_id' => array( | |
129 | 'name' => 'gender_id', | |
130 | 'title' => ts('Gender'), | |
131 | ), | |
132 | 'birth_date' => array( | |
133 | 'name' => 'birth_date', | |
134 | 'title' => ts('Birth Date'), | |
135 | ), | |
a130e045 DG |
136 | 'contact_type' => array( |
137 | 'title' => ts('Contact Type'), | |
138 | ), | |
139 | 'contact_sub_type' => array( | |
140 | 'title' => ts('Contact Subtype'), | |
6a488035 TO |
141 | ), |
142 | ), | |
a130e045 DG |
143 | 'filters' => array( |
144 | 'sort_name' => array( | |
145 | 'title' => ts('Donor Name'), | |
146 | 'operator' => 'like', | |
6a488035 | 147 | ), |
49e1ea9f | 148 | 'id' => array( |
149 | 'title' => ts('Contact ID'), | |
150 | 'no_display' => TRUE, | |
151 | ), | |
152 | 'gender_id' => array( | |
153 | 'title' => ts('Gender'), | |
154 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
155 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), | |
156 | ), | |
157 | 'birth_date' => array( | |
158 | 'title' => ts('Birth Date'), | |
159 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
160 | ), | |
161 | 'contact_type' => array( | |
162 | 'title' => ts('Contact Type'), | |
163 | ), | |
164 | 'contact_sub_type' => array( | |
165 | 'title' => ts('Contact Subtype'), | |
166 | ), | |
6a488035 | 167 | ), |
a130e045 DG |
168 | ), |
169 | 'civicrm_email' => array( | |
170 | 'dao' => 'CRM_Core_DAO_Email', | |
171 | 'grouping' => 'contact-field', | |
172 | 'fields' => array( | |
173 | 'email' => array( | |
174 | 'title' => ts('Email'), | |
175 | 'default' => TRUE, | |
6a488035 TO |
176 | ), |
177 | ), | |
a130e045 DG |
178 | ), |
179 | 'civicrm_phone' => array( | |
180 | 'dao' => 'CRM_Core_DAO_Phone', | |
181 | 'grouping' => 'contact-field', | |
182 | 'fields' => array( | |
183 | 'phone' => array( | |
184 | 'title' => ts('Phone'), | |
185 | 'default' => TRUE, | |
186 | ), | |
187 | ), | |
188 | ), | |
ae5ffbb7 TO |
189 | ); |
190 | $this->_columns += $this->addAddressFields(); | |
191 | $this->_columns += array( | |
a130e045 DG |
192 | 'civicrm_contribution' => array( |
193 | 'dao' => 'CRM_Contribute_DAO_Contribution', | |
194 | 'fields' => array( | |
195 | 'contact_id' => array( | |
196 | 'title' => ts('contactId'), | |
197 | 'no_display' => TRUE, | |
198 | 'required' => TRUE, | |
199 | 'no_repeat' => TRUE, | |
200 | ), | |
201 | 'total_amount' => array( | |
202 | 'title' => ts('Total Amount'), | |
203 | 'no_display' => TRUE, | |
204 | 'required' => TRUE, | |
205 | 'no_repeat' => TRUE, | |
6a488035 | 206 | ), |
a130e045 DG |
207 | 'receive_date' => array( |
208 | 'title' => ts('Year'), | |
209 | 'no_display' => TRUE, | |
210 | 'required' => TRUE, | |
211 | 'no_repeat' => TRUE, | |
6a488035 TO |
212 | ), |
213 | ), | |
a130e045 DG |
214 | 'filters' => array( |
215 | 'yid' => array( | |
216 | 'name' => 'receive_date', | |
217 | 'title' => ts('This Year'), | |
218 | 'operatorType' => CRM_Report_Form::OP_SELECT, | |
219 | 'options' => $optionYear, | |
220 | 'default' => date('Y'), | |
221 | ), | |
222 | 'financial_type_id' => array( | |
223 | 'title' => ts('Financial Type'), | |
224 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
225 | 'options' => CRM_Contribute_PseudoConstant::financialType(), | |
226 | ), | |
227 | 'contribution_status_id' => array( | |
228 | 'title' => ts('Contribution Status'), | |
229 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
230 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
231 | 'default' => array('1'), | |
232 | ), | |
233 | ), | |
234 | ), | |
235 | ); | |
6a488035 | 236 | |
d62fab33 RN |
237 | // If we have a campaign, build out the relevant elements |
238 | if ($campaignEnabled && !empty($this->activeCampaigns)) { | |
239 | $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( | |
240 | 'title' => ts('Campaign'), | |
241 | 'default' => 'false', | |
242 | ); | |
9d72cede EM |
243 | $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( |
244 | 'title' => ts('Campaign'), | |
d62fab33 RN |
245 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
246 | 'options' => $this->activeCampaigns, | |
247 | ); | |
248 | } | |
249 | ||
16e2e80c | 250 | $this->_groupFilter = TRUE; |
6a488035 TO |
251 | $this->_tagFilter = TRUE; |
252 | parent::__construct(); | |
253 | } | |
254 | ||
00be9182 | 255 | public function preProcess() { |
6a488035 TO |
256 | parent::preProcess(); |
257 | } | |
258 | ||
00be9182 | 259 | public function select() { |
6a488035 TO |
260 | |
261 | $this->_columnHeaders = $select = array(); | |
262 | $current_year = $this->_params['yid_value']; | |
263 | $previous_year = $current_year - 1; | |
264 | ||
6a488035 TO |
265 | foreach ($this->_columns as $tableName => $table) { |
266 | ||
267 | if (array_key_exists('fields', $table)) { | |
268 | foreach ($table['fields'] as $fieldName => $field) { | |
269 | ||
9d72cede EM |
270 | if (!empty($field['required']) || |
271 | !empty($this->_params['fields'][$fieldName]) | |
272 | ) { | |
6a488035 TO |
273 | if ($fieldName == 'total_amount') { |
274 | $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}"; | |
275 | ||
276 | $this->_columnHeaders["{$previous_year}"]['type'] = $field['type']; | |
277 | $this->_columnHeaders["{$previous_year}"]['title'] = $previous_year; | |
278 | ||
279 | $this->_columnHeaders["civicrm_life_time_total"]['type'] = $field['type']; | |
280 | $this->_columnHeaders["civicrm_life_time_total"]['title'] = 'LifeTime';; | |
281 | } | |
282 | elseif ($fieldName == 'receive_date') { | |
9d72cede EM |
283 | $select[] = self::fiscalYearOffset($field['dbAlias']) . |
284 | " as {$tableName}_{$fieldName} "; | |
6a488035 TO |
285 | } |
286 | else { | |
287 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName} "; | |
288 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
289 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); | |
290 | } | |
291 | ||
a7488080 | 292 | if (!empty($field['no_display'])) { |
6a488035 TO |
293 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = TRUE; |
294 | } | |
295 | } | |
296 | } | |
297 | } | |
298 | } | |
299 | ||
300 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
301 | } | |
302 | ||
00be9182 | 303 | public function from() { |
6a488035 TO |
304 | |
305 | $this->_from = " | |
306 | FROM civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
1c44e08e | 307 | INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
6a488035 | 308 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id |
a27c90f2 NG |
309 | {$this->_aclFrom}"; |
310 | ||
311 | if ($this->isTableSelected('civicrm_email')) { | |
312 | $this->_from .= " | |
1c44e08e | 313 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} |
a27c90f2 NG |
314 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id |
315 | AND {$this->_aliases['civicrm_email']}.is_primary = 1"; | |
316 | } | |
317 | if ($this->isTableSelected('civicrm_phone')) { | |
318 | $this->_from .= " | |
1c44e08e | 319 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
6a488035 | 320 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND |
a27c90f2 NG |
321 | {$this->_aliases['civicrm_phone']}.is_primary = 1"; |
322 | } | |
72a9af52 | 323 | $this->addAddressFromClause(); |
6a488035 TO |
324 | } |
325 | ||
00be9182 | 326 | public function where() { |
6a488035 | 327 | $this->_statusClause = ""; |
9d72cede EM |
328 | $clauses = array($this->_aliases['civicrm_contribution'] . '.is_test = 0'); |
329 | $current_year = $this->_params['yid_value']; | |
330 | $previous_year = $current_year - 1; | |
6a488035 TO |
331 | |
332 | foreach ($this->_columns as $tableName => $table) { | |
333 | if (array_key_exists('filters', $table)) { | |
334 | foreach ($table['filters'] as $fieldName => $field) { | |
335 | $clause = NULL; | |
336 | if ($fieldName == 'yid') { | |
49e1ea9f | 337 | $clause = "contribution_civireport.contact_id NOT IN |
338 | (SELECT distinct contri.contact_id FROM civicrm_contribution contri | |
339 | WHERE contri.is_test = 0 AND " . | |
340 | self::fiscalYearOffset('contri.receive_date') . " = $current_year) AND contribution_civireport.contact_id IN (SELECT distinct contri.contact_id FROM civicrm_contribution contri | |
341 | WHERE " . self::fiscalYearOffset('contri.receive_date') . | |
e463c072 | 342 | " = $previous_year AND contri.is_test = 0) AND " . self::fiscalYearOffset('contribution_civireport.receive_date') . " = $previous_year"; |
6a488035 | 343 | } |
84178120 | 344 | elseif (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE |
9d72cede | 345 | ) { |
6a488035 | 346 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); |
9d72cede EM |
347 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
348 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 TO |
349 | |
350 | if ($relative || $from || $to) { | |
351 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); | |
352 | } | |
353 | } | |
354 | else { | |
355 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
356 | if ($op) { | |
357 | $clause = $this->whereClause($field, | |
358 | $op, | |
359 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
360 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
361 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
362 | ); | |
9d72cede EM |
363 | if (($fieldName == 'contribution_status_id' || |
364 | $fieldName == 'financial_type_id') && !empty($clause) | |
365 | ) { | |
6a488035 TO |
366 | $this->_statusClause .= " AND " . $clause; |
367 | } | |
368 | } | |
369 | } | |
370 | ||
371 | if (!empty($clause)) { | |
372 | $clauses[] = $clause; | |
373 | } | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | $this->_where = 'WHERE ' . implode(' AND ', $clauses); | |
379 | ||
380 | if ($this->_aclWhere) { | |
381 | $this->_where .= " AND {$this->_aclWhere} "; | |
382 | } | |
383 | } | |
384 | ||
00be9182 | 385 | public function groupBy() { |
ae5ffbb7 | 386 | $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contribution']}.contact_id, " . |
9d72cede EM |
387 | self::fiscalYearOffset($this->_aliases['civicrm_contribution'] . |
388 | '.receive_date') . " WITH ROLLUP"; | |
6a488035 TO |
389 | $this->assign('chartSupported', TRUE); |
390 | } | |
391 | ||
74cf4551 EM |
392 | /** |
393 | * @param $rows | |
394 | * | |
395 | * @return array | |
396 | */ | |
00be9182 | 397 | public function statistics(&$rows) { |
6a488035 TO |
398 | $statistics = parent::statistics($rows); |
399 | if (!empty($rows)) { | |
e463c072 | 400 | $select = "SELECT SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as amount "; |
401 | $where = "WHERE {$this->_aliases['civicrm_contact']}.id IN (" . implode(',', $this->_contactIds) . ") | |
402 | AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause}"; | |
6a488035 | 403 | |
e463c072 | 404 | $sql = "{$select} {$this->_from} {$where}"; |
6a488035 TO |
405 | $dao = CRM_Core_DAO::executeQuery($sql); |
406 | if ($dao->fetch()) { | |
407 | $statistics['counts']['amount'] = array( | |
408 | 'value' => $dao->amount, | |
409 | 'title' => 'Total LifeTime', | |
410 | 'type' => CRM_Utils_Type::T_MONEY, | |
411 | ); | |
412 | } | |
413 | } | |
414 | ||
415 | return $statistics; | |
416 | } | |
417 | ||
00be9182 | 418 | public function postProcess() { |
6a488035 TO |
419 | |
420 | // get ready with post process params | |
421 | $this->beginPostProcess(); | |
422 | ||
423 | // get the acl clauses built before we assemble the query | |
424 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
425 | $this->select(); | |
426 | $this->from(); | |
427 | $this->where(); | |
428 | $this->groupBy(); | |
429 | ||
e463c072 | 430 | $rows = $this->_contactIds = array(); |
431 | $this->limit(); | |
432 | $getContacts = "SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid {$this->_from} {$this->_where} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_limit}"; | |
6a488035 | 433 | |
e463c072 | 434 | $dao = CRM_Core_DAO::executeQuery($getContacts); |
6a488035 | 435 | |
e463c072 | 436 | while ($dao->fetch()) { |
437 | $this->_contactIds[] = $dao->cid; | |
438 | } | |
439 | $dao->free(); | |
440 | if (empty($this->_params['charts'])) { | |
6a488035 TO |
441 | $this->setPager(); |
442 | } | |
443 | ||
e463c072 | 444 | if (!empty($this->_contactIds) || !empty($this->_params['charts'])) { |
445 | $sql = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . implode(',', $this->_contactIds) . ") | |
446 | AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} "; | |
6a488035 | 447 | |
9d72cede EM |
448 | $dao = CRM_Core_DAO::executeQuery($sql); |
449 | $current_year = $this->_params['yid_value']; | |
6a488035 TO |
450 | $previous_year = $current_year - 1; |
451 | ||
452 | while ($dao->fetch()) { | |
453 | ||
454 | if (!$dao->civicrm_contribution_contact_id) { | |
455 | continue; | |
456 | } | |
457 | ||
458 | $row = array(); | |
459 | foreach ($this->_columnHeaders as $key => $value) { | |
460 | if (property_exists($dao, $key)) { | |
461 | $rows[$dao->civicrm_contribution_contact_id][$key] = $dao->$key; | |
462 | } | |
463 | } | |
464 | ||
465 | if ($dao->civicrm_contribution_receive_date) { | |
466 | if ($dao->civicrm_contribution_receive_date == $previous_year) { | |
467 | $rows[$dao->civicrm_contribution_contact_id][$dao->civicrm_contribution_receive_date] = $dao->civicrm_contribution_total_amount; | |
468 | } | |
469 | } | |
470 | else { | |
471 | $rows[$dao->civicrm_contribution_contact_id]['civicrm_life_time_total'] = $dao->civicrm_contribution_total_amount; | |
472 | } | |
473 | } | |
474 | $dao->free(); | |
475 | } | |
476 | ||
477 | $this->formatDisplay($rows, FALSE); | |
478 | ||
479 | // assign variables to templates | |
480 | $this->doTemplateAssignment($rows); | |
481 | ||
482 | // do print / pdf / instance stuff if needed | |
483 | $this->endPostProcess($rows); | |
484 | } | |
485 | ||
74cf4551 EM |
486 | /** |
487 | * @param $rows | |
488 | */ | |
00be9182 | 489 | public function buildChart(&$rows) { |
6a488035 TO |
490 | |
491 | $graphRows = array(); | |
9d72cede EM |
492 | $count = 0; |
493 | $display = array(); | |
6a488035 TO |
494 | |
495 | $current_year = $this->_params['yid_value']; | |
496 | $previous_year = $current_year - 1; | |
497 | $interval[$previous_year] = $previous_year; | |
498 | $interval['life_time'] = 'Life Time'; | |
499 | ||
500 | foreach ($rows as $key => $row) { | |
9d72cede EM |
501 | $display['life_time'] = CRM_Utils_Array::value('life_time', $display) + |
502 | $row['civicrm_life_time_total']; | |
ae5ffbb7 | 503 | $display[$previous_year] = CRM_Utils_Array::value($previous_year, $display) + $row[$previous_year]; |
6a488035 TO |
504 | } |
505 | ||
9d72cede | 506 | $config = CRM_Core_Config::Singleton(); |
6a488035 | 507 | $graphRows['value'] = $display; |
9d72cede EM |
508 | $chartInfo = array( |
509 | 'legend' => ts('Lybunt Report'), | |
6a488035 TO |
510 | 'xname' => ts('Year'), |
511 | 'yname' => ts('Amount (%1)', array(1 => $config->defaultCurrency)), | |
512 | ); | |
513 | if ($this->_params['charts']) { | |
514 | // build chart. | |
515 | CRM_Utils_OpenFlashChart::reportChart($graphRows, $this->_params['charts'], $interval, $chartInfo); | |
516 | $this->assign('chartType', $this->_params['charts']); | |
517 | } | |
518 | } | |
519 | ||
74cf4551 | 520 | /** |
ced9bfed EM |
521 | * Alter display of rows. |
522 | * | |
523 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
524 | * such as rendering contacts as links. | |
525 | * | |
526 | * @param array $rows | |
527 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 528 | */ |
00be9182 | 529 | public function alterDisplay(&$rows) { |
72a9af52 NG |
530 | $entryFound = FALSE; |
531 | ||
6a488035 TO |
532 | foreach ($rows as $rowNum => $row) { |
533 | //Convert Display name into link | |
534 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
535 | array_key_exists('civicrm_contribution_contact_id', $row) | |
536 | ) { | |
537 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', | |
9d72cede EM |
538 | 'reset=1&force=1&id_op=eq&id_value=' . |
539 | $row['civicrm_contribution_contact_id'], | |
6a488035 TO |
540 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport |
541 | ); | |
542 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
543 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); | |
72a9af52 | 544 | $entryFound = TRUE; |
6a488035 | 545 | } |
d62fab33 RN |
546 | |
547 | // convert campaign_id to campaign title | |
548 | if (array_key_exists('civicrm_contribution_campaign_id', $row)) { | |
549 | if ($value = $row['civicrm_contribution_campaign_id']) { | |
550 | $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; | |
551 | $entryFound = TRUE; | |
552 | } | |
553 | } | |
a27c90f2 | 554 | |
72a9af52 NG |
555 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s)') ? TRUE : $entryFound; |
556 | ||
49e1ea9f | 557 | //handle gender |
558 | if (array_key_exists('civicrm_contact_gender_id', $row)) { | |
559 | if ($value = $row['civicrm_contact_gender_id']) { | |
560 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); | |
561 | $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value]; | |
562 | } | |
563 | $entryFound = TRUE; | |
564 | } | |
565 | ||
566 | // display birthday in the configured custom format | |
567 | if (array_key_exists('civicrm_contact_birth_date', $row)) { | |
568 | $birthDate = $row['civicrm_contact_birth_date']; | |
569 | if ($birthDate) { | |
570 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); | |
571 | } | |
572 | $entryFound = TRUE; | |
573 | } | |
574 | ||
72a9af52 NG |
575 | // skip looking further in rows, if first row itself doesn't |
576 | // have the column we need | |
577 | if (!$entryFound) { | |
578 | break; | |
a27c90f2 | 579 | } |
6a488035 TO |
580 | } |
581 | } | |
582 | ||
74cf4551 | 583 | /** |
4f1f1f2a | 584 | * Override "This Year" $op options |
74cf4551 EM |
585 | * @param string $type |
586 | * @param null $fieldName | |
587 | * | |
588 | * @return array | |
589 | */ | |
00be9182 | 590 | public function getOperationPair($type = "string", $fieldName = NULL) { |
6a488035 | 591 | if ($fieldName == 'yid') { |
9d72cede EM |
592 | return array( |
593 | 'calendar' => ts('Is Calendar Year'), | |
21dfd5f5 | 594 | 'fiscal' => ts('Fiscal Year Starting'), |
9d72cede | 595 | ); |
6a488035 TO |
596 | } |
597 | return parent::getOperationPair($type, $fieldName); | |
598 | } | |
96025800 | 599 | |
6a488035 | 600 | } |