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') . | |
342 | " = $previous_year AND contri.is_test = 0)"; | |
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)) { | |
400 | $select = " | |
1c44e08e | 401 | SELECT |
6a488035 TO |
402 | SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as amount "; |
403 | ||
404 | $sql = "{$select} {$this->_from} {$this->_where}"; | |
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 | ||
430 | $rows = $contactIds = array(); | |
a7488080 | 431 | if (empty($this->_params['charts'])) { |
6a488035 TO |
432 | $this->limit(); |
433 | $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}"; | |
434 | ||
435 | $dao = CRM_Core_DAO::executeQuery($getContacts); | |
436 | ||
437 | while ($dao->fetch()) { | |
438 | $contactIds[] = $dao->cid; | |
439 | } | |
440 | $dao->free(); | |
441 | $this->setPager(); | |
442 | } | |
443 | ||
8cc574cf | 444 | if (!empty($contactIds) || !empty($this->_params['charts'])) { |
a7488080 | 445 | if (!empty($this->_params['charts'])) { |
6a488035 TO |
446 | $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy}"; |
447 | } | |
448 | else { | |
ae5ffbb7 | 449 | $sql = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . |
9d72cede EM |
450 | implode(',', $contactIds) . |
451 | ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} "; | |
6a488035 TO |
452 | } |
453 | ||
9d72cede EM |
454 | $dao = CRM_Core_DAO::executeQuery($sql); |
455 | $current_year = $this->_params['yid_value']; | |
6a488035 TO |
456 | $previous_year = $current_year - 1; |
457 | ||
458 | while ($dao->fetch()) { | |
459 | ||
460 | if (!$dao->civicrm_contribution_contact_id) { | |
461 | continue; | |
462 | } | |
463 | ||
464 | $row = array(); | |
465 | foreach ($this->_columnHeaders as $key => $value) { | |
466 | if (property_exists($dao, $key)) { | |
467 | $rows[$dao->civicrm_contribution_contact_id][$key] = $dao->$key; | |
468 | } | |
469 | } | |
470 | ||
471 | if ($dao->civicrm_contribution_receive_date) { | |
472 | if ($dao->civicrm_contribution_receive_date == $previous_year) { | |
473 | $rows[$dao->civicrm_contribution_contact_id][$dao->civicrm_contribution_receive_date] = $dao->civicrm_contribution_total_amount; | |
474 | } | |
475 | } | |
476 | else { | |
477 | $rows[$dao->civicrm_contribution_contact_id]['civicrm_life_time_total'] = $dao->civicrm_contribution_total_amount; | |
478 | } | |
479 | } | |
480 | $dao->free(); | |
481 | } | |
482 | ||
483 | $this->formatDisplay($rows, FALSE); | |
484 | ||
485 | // assign variables to templates | |
486 | $this->doTemplateAssignment($rows); | |
487 | ||
488 | // do print / pdf / instance stuff if needed | |
489 | $this->endPostProcess($rows); | |
490 | } | |
491 | ||
74cf4551 EM |
492 | /** |
493 | * @param $rows | |
494 | */ | |
00be9182 | 495 | public function buildChart(&$rows) { |
6a488035 TO |
496 | |
497 | $graphRows = array(); | |
9d72cede EM |
498 | $count = 0; |
499 | $display = array(); | |
6a488035 TO |
500 | |
501 | $current_year = $this->_params['yid_value']; | |
502 | $previous_year = $current_year - 1; | |
503 | $interval[$previous_year] = $previous_year; | |
504 | $interval['life_time'] = 'Life Time'; | |
505 | ||
506 | foreach ($rows as $key => $row) { | |
9d72cede EM |
507 | $display['life_time'] = CRM_Utils_Array::value('life_time', $display) + |
508 | $row['civicrm_life_time_total']; | |
ae5ffbb7 | 509 | $display[$previous_year] = CRM_Utils_Array::value($previous_year, $display) + $row[$previous_year]; |
6a488035 TO |
510 | } |
511 | ||
9d72cede | 512 | $config = CRM_Core_Config::Singleton(); |
6a488035 | 513 | $graphRows['value'] = $display; |
9d72cede EM |
514 | $chartInfo = array( |
515 | 'legend' => ts('Lybunt Report'), | |
6a488035 TO |
516 | 'xname' => ts('Year'), |
517 | 'yname' => ts('Amount (%1)', array(1 => $config->defaultCurrency)), | |
518 | ); | |
519 | if ($this->_params['charts']) { | |
520 | // build chart. | |
521 | CRM_Utils_OpenFlashChart::reportChart($graphRows, $this->_params['charts'], $interval, $chartInfo); | |
522 | $this->assign('chartType', $this->_params['charts']); | |
523 | } | |
524 | } | |
525 | ||
74cf4551 | 526 | /** |
ced9bfed EM |
527 | * Alter display of rows. |
528 | * | |
529 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
530 | * such as rendering contacts as links. | |
531 | * | |
532 | * @param array $rows | |
533 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 534 | */ |
00be9182 | 535 | public function alterDisplay(&$rows) { |
72a9af52 NG |
536 | $entryFound = FALSE; |
537 | ||
6a488035 TO |
538 | foreach ($rows as $rowNum => $row) { |
539 | //Convert Display name into link | |
540 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
541 | array_key_exists('civicrm_contribution_contact_id', $row) | |
542 | ) { | |
543 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', | |
9d72cede EM |
544 | 'reset=1&force=1&id_op=eq&id_value=' . |
545 | $row['civicrm_contribution_contact_id'], | |
6a488035 TO |
546 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport |
547 | ); | |
548 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
549 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); | |
72a9af52 | 550 | $entryFound = TRUE; |
6a488035 | 551 | } |
d62fab33 RN |
552 | |
553 | // convert campaign_id to campaign title | |
554 | if (array_key_exists('civicrm_contribution_campaign_id', $row)) { | |
555 | if ($value = $row['civicrm_contribution_campaign_id']) { | |
556 | $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; | |
557 | $entryFound = TRUE; | |
558 | } | |
559 | } | |
a27c90f2 | 560 | |
72a9af52 NG |
561 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s)') ? TRUE : $entryFound; |
562 | ||
49e1ea9f | 563 | //handle gender |
564 | if (array_key_exists('civicrm_contact_gender_id', $row)) { | |
565 | if ($value = $row['civicrm_contact_gender_id']) { | |
566 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); | |
567 | $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value]; | |
568 | } | |
569 | $entryFound = TRUE; | |
570 | } | |
571 | ||
572 | // display birthday in the configured custom format | |
573 | if (array_key_exists('civicrm_contact_birth_date', $row)) { | |
574 | $birthDate = $row['civicrm_contact_birth_date']; | |
575 | if ($birthDate) { | |
576 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); | |
577 | } | |
578 | $entryFound = TRUE; | |
579 | } | |
580 | ||
72a9af52 NG |
581 | // skip looking further in rows, if first row itself doesn't |
582 | // have the column we need | |
583 | if (!$entryFound) { | |
584 | break; | |
a27c90f2 | 585 | } |
6a488035 TO |
586 | } |
587 | } | |
588 | ||
74cf4551 | 589 | /** |
4f1f1f2a | 590 | * Override "This Year" $op options |
74cf4551 EM |
591 | * @param string $type |
592 | * @param null $fieldName | |
593 | * | |
594 | * @return array | |
595 | */ | |
00be9182 | 596 | public function getOperationPair($type = "string", $fieldName = NULL) { |
6a488035 | 597 | if ($fieldName == 'yid') { |
9d72cede EM |
598 | return array( |
599 | 'calendar' => ts('Is Calendar Year'), | |
21dfd5f5 | 600 | 'fiscal' => ts('Fiscal Year Starting'), |
9d72cede | 601 | ); |
6a488035 TO |
602 | } |
603 | return parent::getOperationPair($type, $fieldName); | |
604 | } | |
96025800 | 605 | |
6a488035 | 606 | } |