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