Merge pull request #799 from eileenmcnaughton/CRM-12659
[civicrm-core.git] / CRM / Report / Form / Contribute / Summary.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28 */
29
30 /**
31 *
32 * @package CRM
33 * @copyright CiviCRM LLC (c) 2004-2013
34 * $Id$
35 *
36 */
37 class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
38 protected $_addressField = FALSE;
39
40 protected $_charts = array(
41 '' => 'Tabular',
42 'barChart' => 'Bar Chart',
43 'pieChart' => 'Pie Chart',
44 );
45 protected $_customGroupExtends = array('Contribution');
46 protected $_customGroupGroupBy = TRUE;
47
48 public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report');
49
50 function __construct() {
51
52 // Check if CiviCampaign is a) enabled and b) has active campaigns
53 $config = CRM_Core_Config::singleton();
54 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
55 if ($campaignEnabled) {
56 $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
57 $this->activeCampaigns = $getCampaigns['campaigns'];
58 asort($this->activeCampaigns);
59 }
60
61 $this->_columns = array(
62 'civicrm_contact' =>
63 array(
64 'dao' => 'CRM_Contact_DAO_Contact',
65 'fields' =>
66 array(
67 'sort_name' =>
68 array('title' => ts('Contact Name'),
69 'no_repeat' => TRUE,
70 ),
71 'postal_greeting_display' =>
72 array('title' => ts('Postal Greeting')),
73 'id' =>
74 array(
75 'no_display' => TRUE,
76 'required' => TRUE,
77 ),
78 ),
79 'grouping' => 'contact-fields',
80 'group_bys' =>
81 array(
82 'id' =>
83 array('title' => ts('Contact ID')),
84 'sort_name' =>
85 array('title' => ts('Contact Name'),
86 ),
87 ),
88 ),
89 'civicrm_email' =>
90 array(
91 'dao' => 'CRM_Core_DAO_Email',
92 'fields' =>
93 array(
94 'email' =>
95 array('title' => ts('Email'),
96 'no_repeat' => TRUE,
97 ),
98 ),
99 'grouping' => 'contact-fields',
100 ),
101 'civicrm_phone' =>
102 array(
103 'dao' => 'CRM_Core_DAO_Phone',
104 'fields' =>
105 array(
106 'phone' =>
107 array('title' => ts('Phone'),
108 'no_repeat' => TRUE,
109 ),
110 ),
111 'grouping' => 'contact-fields',
112 ),
113 'civicrm_financial_type' =>
114 array('dao' => 'CRM_Financial_DAO_FinancialType',
115 'fields' => array('financial_type' => null,),
116 'grouping' => 'contri-fields',
117 'group_bys' => array(
118 'financial_type' => array('title' => ts('Financial Type')),
119 ),
120 ),
121 'civicrm_contribution' =>
122 array(
123 'dao' => 'CRM_Contribute_DAO_Contribution',
124 //'bao' => 'CRM_Contribute_BAO_Contribution',
125 'fields' =>
126 array(
127 'contribution_source' => array('title' => ts('Source'),
128 ),
129 'currency' =>
130 array('required' => TRUE,
131 'no_display' => TRUE,
132 ),
133 'total_amount' =>
134 array('title' => ts('Amount Statistics'),
135 'default' => TRUE,
136 'required' => TRUE,
137 'statistics' =>
138 array('sum' => ts('Aggregate Amount'),
139 'count' => ts('Donations'),
140 'avg' => ts('Average'),
141 ),
142 ),
143 ),
144 'grouping' => 'contri-fields',
145 'filters' =>
146 array(
147 'receive_date' =>
148 array('operatorType' => CRM_Report_Form::OP_DATE),
149 'contribution_status_id' =>
150 array('title' => ts('Donation Status'),
151 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
152 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
153 'default' => array(1),
154 'type' => CRM_Utils_Type::T_INT,
155 ),
156 'currency' =>
157 array('title' => 'Currency',
158 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
159 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
160 'default' => NULL,
161 'type' => CRM_Utils_Type::T_STRING,
162 ),
163 'financial_type_id' =>
164 array('title' => ts('Financial Type'),
165 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
166 'options' => CRM_Contribute_PseudoConstant::financialType(),
167 'type' => CRM_Utils_Type::T_INT,
168 ),
169 'total_amount' =>
170 array('title' => ts('Donation Amount'),
171 ),
172 'total_sum' =>
173 array('title' => ts('Aggregate Amount'),
174 'type' => CRM_Report_Form::OP_INT,
175 'dbAlias' => 'civicrm_contribution_total_amount_sum',
176 'having' => TRUE,
177 ),
178 'total_count' =>
179 array('title' => ts('Donation Count'),
180 'type' => CRM_Report_Form::OP_INT,
181 'dbAlias' => 'civicrm_contribution_total_amount_count',
182 'having' => TRUE,
183 ),
184 'total_avg' =>
185 array('title' => ts('Average'),
186 'type' => CRM_Report_Form::OP_INT,
187 'dbAlias' => 'civicrm_contribution_total_amount_avg',
188 'having' => TRUE,
189 ),
190 ),
191 'group_bys' =>
192 array(
193 'receive_date' =>
194 array(
195 'frequency' => TRUE,
196 'default' => TRUE,
197 'chart' => TRUE,
198 ),
199 'contribution_source' => NULL,
200 ),
201 ),
202 'civicrm_group' =>
203 array(
204 'dao' => 'CRM_Contact_DAO_GroupContact',
205 'alias' => 'cgroup',
206 'filters' =>
207 array(
208 'gid' =>
209 array(
210 'name' => 'group_id',
211 'title' => ts('Group'),
212 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
213 'group' => TRUE,
214 'options' => CRM_Core_PseudoConstant::group(),
215 'type' => CRM_Utils_Type::T_INT,
216 ),
217 ),
218 ),
219 ) + $this->addAddressFields();
220
221 // If we have a campaign, build out the relevant elements
222 $this->_tagFilter = TRUE;
223 if ($campaignEnabled && !empty($this->activeCampaigns)) {
224 $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array(
225 'title' => 'Campaign',
226 'default' => 'false',
227 );
228 $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'),
229 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
230 'options' => $this->activeCampaigns,
231 );
232 $this->_columns['civicrm_contribution']['grouping']['campaign_id'] = 'contri-fields';
233 $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
234 }
235
236 $this->_currencyColumn = 'civicrm_contribution_currency';
237 parent::__construct();
238 }
239
240 function preProcess() {
241 parent::preProcess();
242 }
243
244 function setDefaultValues($freeze = TRUE) {
245 return parent::setDefaultValues($freeze);
246 }
247
248 function select() {
249 $select = array();
250 $this->_columnHeaders = array();
251 foreach ($this->_columns as $tableName => $table) {
252 if (array_key_exists('group_bys', $table)) {
253 foreach ($table['group_bys'] as $fieldName => $field) {
254 if ($tableName == 'civicrm_address') {
255 $this->_addressField = TRUE;
256 }
257 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
258 switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
259 case 'YEARWEEK':
260 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
261 $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
262 $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
263 $field['title'] = 'Week';
264 break;
265
266 case 'YEAR':
267 $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1) AS {$tableName}_{$fieldName}_start";
268 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
269 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
270 $field['title'] = 'Year';
271 break;
272
273 case 'MONTH':
274 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
275 $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
276 $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
277 $field['title'] = 'Month';
278 break;
279
280 case 'QUARTER':
281 $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
282 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
283 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
284 $field['title'] = 'Quarter';
285 break;
286 }
287 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
288 $this->_interval = $field['title'];
289 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
290 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
291 $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['group_by'] = $this->_params['group_bys_freq'][$fieldName];
292
293 // just to make sure these values are transfered to rows.
294 // since we need that for calculation purpose,
295 // e.g making subtotals look nicer or graphs
296 $this->_columnHeaders["{$tableName}_{$fieldName}_interval"] = array('no_display' => TRUE);
297 $this->_columnHeaders["{$tableName}_{$fieldName}_subtotal"] = array('no_display' => TRUE);
298 }
299 }
300 }
301 }
302
303 if (array_key_exists('fields', $table)) {
304 foreach ($table['fields'] as $fieldName => $field) {
305 if ($tableName == 'civicrm_address') {
306 $this->_addressField = TRUE;
307 }
308 if (CRM_Utils_Array::value('required', $field) ||
309 CRM_Utils_Array::value($fieldName, $this->_params['fields'])
310 ) {
311
312 // only include statistics columns if set
313 if (CRM_Utils_Array::value('statistics', $field)) {
314 foreach ($field['statistics'] as $stat => $label) {
315 switch (strtolower($stat)) {
316 case 'sum':
317 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
318 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
319 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
320 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
321 break;
322
323 case 'count':
324 $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
325 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
326 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
327 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
328 break;
329
330 case 'avg':
331 $select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}";
332 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
333 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
334 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
335 break;
336 }
337 }
338 }
339 else {
340 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
341 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
342 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
343 }
344 }
345 }
346 }
347 }
348
349 $this->_select = "SELECT " . implode(', ', $select) . " ";
350 }
351
352 static function formRule($fields, $files, $self) {
353 $errors = $grouping = array();
354 //check for searching combination of dispaly columns and
355 //grouping criteria
356 $ignoreFields = array('total_amount', 'sort_name');
357 $errors = $self->customDataFormRule($fields, $ignoreFields);
358
359 if (!CRM_Utils_Array::value('receive_date', $fields['group_bys'])) {
360 if (CRM_Utils_Array::value('receive_date_relative', $fields) ||
361 CRM_Utils_Date::isDate($fields['receive_date_from']) ||
362 CRM_Utils_Date::isDate($fields['receive_date_to'])
363 ) {
364 $errors['receive_date_relative'] = ts("Do not use filter on Date if group by Receive Date is not used ");
365 }
366 }
367 if (!CRM_Utils_Array::value('total_amount', $fields['fields'])) {
368 foreach (array(
369 'total_count_value', 'total_sum_value', 'total_avg_value') as $val) {
370 if (CRM_Utils_Array::value($val, $fields)) {
371 $errors[$val] = ts("Please select the Amount Statistics");
372 }
373 }
374 }
375
376 return $errors;
377 }
378
379 function from() {
380 $this->_from = "
381 FROM civicrm_contact {$this->_aliases['civicrm_contact']}
382 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
383 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND
384 {$this->_aliases['civicrm_contribution']}.is_test = 0
385 LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
386 ON {$this->_aliases['civicrm_contribution']}.financial_type_id ={$this->_aliases['civicrm_financial_type']}.id
387 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
388 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
389 {$this->_aliases['civicrm_email']}.is_primary = 1)
390
391 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
392 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
393 {$this->_aliases['civicrm_phone']}.is_primary = 1)";
394
395 if ($this->_addressField) {
396 $this->_from .= "
397 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
398 ON {$this->_aliases['civicrm_contact']}.id =
399 {$this->_aliases['civicrm_address']}.contact_id AND
400 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
401 }
402 }
403
404 function groupBy() {
405 $this->_groupBy = "";
406 $append = FALSE;
407 if (is_array($this->_params['group_bys']) &&
408 !empty($this->_params['group_bys'])
409 ) {
410 foreach ($this->_columns as $tableName => $table) {
411 if (array_key_exists('group_bys', $table)) {
412 foreach ($table['group_bys'] as $fieldName => $field) {
413 if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
414 if (CRM_Utils_Array::value('chart', $field)) {
415 $this->assign('chartSupported', TRUE);
416 }
417
418 if (CRM_Utils_Array::value('frequency', $table['group_bys'][$fieldName]) &&
419 CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])
420 ) {
421
422 $append = "YEAR({$field['dbAlias']}),";
423 if (in_array(strtolower($this->_params['group_bys_freq'][$fieldName]),
424 array('year')
425 )) {
426 $append = '';
427 }
428 $this->_groupBy[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
429 $append = TRUE;
430 }
431 else {
432 $this->_groupBy[] = $field['dbAlias'];
433 }
434 }
435 }
436 }
437 }
438
439 if (!empty($this->_statFields) &&
440 (($append && count($this->_groupBy) <= 1) || (!$append)) && !$this->_having
441 ) {
442 $this->_rollup = " WITH ROLLUP";
443 }
444 $this->_groupBy = "GROUP BY " . implode(', ', $this->_groupBy) . " {$this->_rollup} ";
445 }
446 else {
447 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contact']}.id";
448 }
449 }
450
451 function statistics(&$rows) {
452 $statistics = parent::statistics($rows);
453
454 if (!$this->_having) {
455 $select = "
456 SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
457 SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as amount,
458 ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg, {$this->_aliases['civicrm_contribution']}.currency as currency
459 ";
460 $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
461 $sql = "{$select} {$this->_from} {$this->_where}{$group}";
462
463 $dao = CRM_Core_DAO::executeQuery($sql);
464 $totalAmount = $average = array();
465 $count = 0;
466 while ($dao->fetch()) {
467 $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
468 $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
469 $count += $dao->count;
470 }
471
472 $statistics['counts']['amount'] = array(
473 'title' => ts('Total Amount'),
474 'value' => implode(', ', $totalAmount),
475 'type' => CRM_Utils_Type::T_STRING,
476 );
477 $statistics['counts']['count'] = array(
478 'title' => ts('Total Donations'),
479 'value' => $count,
480 );
481 $statistics['counts']['avg'] = array(
482 'title' => ts('Average'),
483 'value' => implode(', ', $average),
484 'type' => CRM_Utils_Type::T_STRING,
485 );
486
487 }
488 return $statistics;
489 }
490
491 function postProcess() {
492 $this->buildACLClause($this->_aliases['civicrm_contact']);
493 parent::postProcess();
494 }
495
496 function buildChart(&$rows) {
497 $graphRows = array();
498 $count = 0;
499
500 if (CRM_Utils_Array::value('charts', $this->_params)) {
501 foreach ($rows as $key => $row) {
502 if ($row['civicrm_contribution_receive_date_subtotal']) {
503 $graphRows['receive_date'][] = $row['civicrm_contribution_receive_date_start'];
504 $graphRows[$this->_interval][] = $row['civicrm_contribution_receive_date_interval'];
505 $graphRows['value'][] = $row['civicrm_contribution_total_amount_sum'];
506 $count++;
507 }
508 }
509
510 if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys'])) {
511
512 // build the chart.
513 $config = CRM_Core_Config::Singleton();
514 $graphRows['xname'] = $this->_interval;
515 $graphRows['yname'] = "Amount ({$config->defaultCurrency})";
516 CRM_Utils_OpenFlashChart::chart($graphRows, $this->_params['charts'], $this->_interval);
517 $this->assign('chartType', $this->_params['charts']);
518 }
519 }
520 }
521
522 function alterDisplay(&$rows) {
523 // custom code to alter rows
524 $entryFound = FALSE;
525
526 foreach ($rows as $rowNum => $row) {
527 // make count columns point to detail report
528 if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys']) &&
529 CRM_Utils_Array::value('civicrm_contribution_receive_date_start', $row) &&
530 CRM_Utils_Array::value('civicrm_contribution_receive_date_start', $row) &&
531 CRM_Utils_Array::value('civicrm_contribution_receive_date_subtotal', $row)
532 ) {
533
534 $dateStart = CRM_Utils_Date::customFormat($row['civicrm_contribution_receive_date_start'], '%Y%m%d');
535 $endDate = new DateTime($dateStart);
536 $dateEnd = array();
537
538 list($dateEnd['Y'], $dateEnd['M'], $dateEnd['d']) = explode(':', $endDate->format('Y:m:d'));
539
540 switch (strtolower($this->_params['group_bys_freq']['receive_date'])) {
541 case 'month':
542 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 1,
543 $dateEnd['d'] - 1, $dateEnd['Y']
544 ));
545 break;
546
547 case 'year':
548 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
549 $dateEnd['d'] - 1, $dateEnd['Y'] + 1
550 ));
551 break;
552
553 case 'yearweek':
554 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
555 $dateEnd['d'] + 6, $dateEnd['Y']
556 ));
557 break;
558
559 case 'quarter':
560 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 3,
561 $dateEnd['d'] - 1, $dateEnd['Y']
562 ));
563 break;
564 }
565 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
566 "reset=1&force=1&receive_date_from={$dateStart}&receive_date_to={$dateEnd}",
567 $this->_absoluteUrl,
568 $this->_id,
569 $this->_drilldownReport
570 );
571 $rows[$rowNum]['civicrm_contribution_receive_date_start_link'] = $url;
572 $rows[$rowNum]['civicrm_contribution_receive_date_start_hover'] = ts('List all contribution(s) for this date unit.');
573 $entryFound = TRUE;
574 }
575
576 // make subtotals look nicer
577 if (array_key_exists('civicrm_contribution_receive_date_subtotal', $row) &&
578 !$row['civicrm_contribution_receive_date_subtotal']
579 ) {
580 $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
581 $entryFound = TRUE;
582 }
583
584 // convert display name to links
585 if (array_key_exists('civicrm_contact_sort_name', $row) &&
586 array_key_exists('civicrm_contact_id', $row)
587 ) {
588 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
589 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
590 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
591 );
592 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
593 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("Lists detailed contribution(s) for this record.");
594 $entryFound = TRUE;
595 }
596
597 // If using campaigns, convert campaign_id to campaign title
598 if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
599 if ($value = $row['civicrm_contribution_campaign_id']) {
600 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value];
601 }
602 $entryFound = TRUE;
603 }
604
605 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;
606
607 // skip looking further in rows, if first row itself doesn't
608 // have the column we need
609 if (!$entryFound) {
610 break;
611 }
612 }
613 }
614 }
615