(dev/core#491) campaign cleanup for soft credit report and show disabled campaigns...
[civicrm-core.git] / CRM / Report / Form / Contribute / SoftCredit.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 * $Id$
33 *
34 */
35class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
36
37 protected $_emailField = FALSE;
38 protected $_emailFieldCredit = FALSE;
39 protected $_phoneField = FALSE;
40 protected $_phoneFieldCredit = FALSE;
41 protected $_charts = array(
42 '' => 'Tabular',
43 'barChart' => 'Bar Chart',
44 'pieChart' => 'Pie Chart',
f813f78e 45 );
70bea8e2 46
47 protected $_customGroupExtends = array(
48 'Contact',
49 'Individual',
7d793900 50 'Contribution',
70bea8e2 51 );
52
6a488035 53 public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report');
f813f78e 54
1728e9a0 55 /**
56 * This report has not been optimised for group filtering.
57 *
58 * The functionality for group filtering has been improved but not
59 * all reports have been adjusted to take care of it. This report has not
60 * and will run an inefficient query until fixed.
61 *
62 * CRM-19170
63 *
64 * @var bool
65 */
66 protected $groupFilterNotOptimised = TRUE;
67
74cf4551 68 /**
74cf4551 69 */
00be9182 70 public function __construct() {
66ddb273 71 $this->optimisedForOnlyFullGroupBy = FALSE;
d62fab33 72
6a488035 73 $this->_columns = array(
9d72cede 74 'civicrm_contact' => array(
6a488035 75 'dao' => 'CRM_Contact_DAO_Contact',
9d72cede
EM
76 'fields' => array(
77 'display_name_creditor' => array(
78 'title' => ts('Soft Credit Name'),
6a488035
TO
79 'name' => 'sort_name',
80 'alias' => 'contact_civireport',
81 'required' => TRUE,
82 'no_repeat' => TRUE,
83 ),
9d72cede
EM
84 'id_creditor' => array(
85 'title' => ts('Soft Credit Id'),
6a488035
TO
86 'name' => 'id',
87 'alias' => 'contact_civireport',
88 'no_display' => TRUE,
89 'required' => TRUE,
90 ),
9d72cede
EM
91 'display_name_constituent' => array(
92 'title' => ts('Contributor Name'),
6a488035
TO
93 'name' => 'sort_name',
94 'alias' => 'constituentname',
95 'required' => TRUE,
96 ),
9d72cede
EM
97 'id_constituent' => array(
98 'title' => ts('Const Id'),
6a488035
TO
99 'name' => 'id',
100 'alias' => 'constituentname',
101 'no_display' => TRUE,
102 'required' => TRUE,
103 ),
70bea8e2 104 'first_name' => array(
105 'title' => ts('First Name'),
106 ),
107 'middle_name' => array(
108 'title' => ts('Middle Name'),
109 ),
110 'last_name' => array(
111 'title' => ts('Last Name'),
112 ),
113 'gender_id' => array(
114 'title' => ts('Gender'),
115 ),
116 'birth_date' => array(
117 'title' => ts('Birth Date'),
118 ),
119 'age' => array(
120 'title' => ts('Age'),
121 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
122 ),
123 'contact_type' => array(
124 'title' => ts('Contact Type'),
125 ),
126 'contact_sub_type' => array(
127 'title' => ts('Contact Subtype'),
128 ),
129 ),
130 'grouping' => 'contact-fields',
131 'order_bys' => array(
132 'sort_name' => array(
133 'title' => ts('Last Name, First Name'),
134 'default' => '1',
135 'default_weight' => '0',
136 'default_order' => 'ASC',
137 ),
138 'first_name' => array(
139 'name' => 'first_name',
140 'title' => ts('First Name'),
141 ),
142 'gender_id' => array(
143 'name' => 'gender_id',
144 'title' => ts('Gender'),
145 ),
146 'birth_date' => array(
147 'name' => 'birth_date',
148 'title' => ts('Birth Date'),
149 ),
150 'age_at_event' => array(
151 'name' => 'age_at_event',
152 'title' => ts('Age at Event'),
153 ),
9d72cede 154 'contact_type' => array(
30f85891
RN
155 'title' => ts('Contact Type'),
156 ),
9d72cede 157 'contact_sub_type' => array(
b8f96eb8 158 'title' => ts('Contact Subtype'),
30f85891 159 ),
6a488035 160 ),
9d72cede
EM
161 'filters' => array(
162 'sort_name' => array(
73f4acb4 163 'name' => 'sort_name',
21dfd5f5 164 'title' => ts('Soft Credit Name'),
73f4acb4 165 ),
70bea8e2 166 'gender_id' => array(
167 'title' => ts('Gender'),
168 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
169 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'),
170 ),
171 'birth_date' => array(
172 'title' => ts('Birth Date'),
173 'operatorType' => CRM_Report_Form::OP_DATE,
174 ),
175 'contact_type' => array(
176 'title' => ts('Contact Type'),
177 ),
178 'contact_sub_type' => array(
179 'title' => ts('Contact Subtype'),
180 ),
73f4acb4 181 ),
6a488035 182 ),
9d72cede 183 'civicrm_email' => array(
6a488035 184 'dao' => 'CRM_Core_DAO_Email',
9d72cede
EM
185 'fields' => array(
186 'email_creditor' => array(
187 'title' => ts('Soft Credit Email'),
6a488035
TO
188 'name' => 'email',
189 'alias' => 'emailcredit',
190 'default' => TRUE,
191 'no_repeat' => TRUE,
192 ),
9d72cede
EM
193 'email_constituent' => array(
194 'title' => ts('Contributor\'s Email'),
6a488035
TO
195 'name' => 'email',
196 'alias' => 'emailconst',
197 ),
198 ),
199 'grouping' => 'contact-fields',
200 ),
9d72cede 201 'civicrm_phone' => array(
6a488035 202 'dao' => 'CRM_Core_DAO_Phone',
9d72cede
EM
203 'fields' => array(
204 'phone_creditor' => array(
205 'title' => ts('Soft Credit Phone'),
6a488035
TO
206 'name' => 'phone',
207 'alias' => 'pcredit',
208 'default' => TRUE,
209 ),
9d72cede
EM
210 'phone_constituent' => array(
211 'title' => ts('Contributor\'s Phone'),
6a488035
TO
212 'name' => 'phone',
213 'alias' => 'pconst',
214 'no_repeat' => TRUE,
215 ),
216 ),
217 'grouping' => 'contact-fields',
218 ),
9d72cede
EM
219 'civicrm_financial_type' => array(
220 'dao' => 'CRM_Financial_DAO_FinancialType',
84178120 221 'fields' => array('financial_type' => NULL),
9d72cede
EM
222 'filters' => array(
223 'id' => array(
6a488035 224 'name' => 'id',
b914f4e8 225 'title' => ts('Financial Type'),
8ee006e7 226 'type' => CRM_Utils_Type::T_INT,
6a488035 227 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
ace6a865 228 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(),
b914f4e8
PN
229 ),
230 ),
6a488035
TO
231 'grouping' => 'softcredit-fields',
232 ),
9d72cede 233 'civicrm_contribution' => array(
6a488035 234 'dao' => 'CRM_Contribute_DAO_Contribution',
9d72cede 235 'fields' => array(
6a488035 236 'contribution_source' => NULL,
c6348f97 237 'currency' => array(
238 'required' => TRUE,
239 'no_display' => TRUE,
240 ),
6a488035
TO
241 ),
242 'grouping' => 'softcredit-fields',
9d72cede
EM
243 'filters' => array(
244 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE),
245 'currency' => array(
fd6a6828 246 'title' => ts('Currency'),
c6348f97 247 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
248 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
d1b0931b 249 'default' => NULL,
c6348f97 250 'type' => CRM_Utils_Type::T_STRING,
251 ),
9d72cede
EM
252 'contribution_status_id' => array(
253 'title' => ts('Contribution Status'),
6a488035
TO
254 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
255 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
256 'default' => array(1),
257 ),
6a488035
TO
258 ),
259 ),
9d72cede 260 'civicrm_contribution_soft' => array(
6a488035 261 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
9d72cede
EM
262 'fields' => array(
263 'contribution_id' => array(
264 'title' => ts('Contribution ID'),
6a488035
TO
265 'no_display' => TRUE,
266 'default' => TRUE,
267 ),
42f0302b 268 'amount' => array(
269 'title' => ts('Amount Statistics'),
270 'default' => TRUE,
271 'statistics' => array(
272 'sum' => ts('Aggregate Amount'),
273 'count' => ts('Contributions'),
274 'avg' => ts('Average'),
275 ),
276 ),
9d72cede 277 'id' => array(
6a488035
TO
278 'default' => TRUE,
279 'no_display' => TRUE,
280 ),
51fa20cb 281 'soft_credit_type_id' => array('title' => ts('Soft Credit Type')),
282 ),
9d72cede
EM
283 'filters' => array(
284 'soft_credit_type_id' => array(
fd6a6828 285 'title' => ts('Soft Credit Type'),
51fa20cb 286 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
287 'options' => CRM_Core_OptionGroup::values('soft_credit_type'),
288 'default' => NULL,
289 'type' => CRM_Utils_Type::T_STRING,
290 ),
42f0302b 291 'amount' => array(
292 'title' => ts('Soft Credit Amount'),
293 ),
6a488035
TO
294 ),
295 'grouping' => 'softcredit-fields',
296 ),
cce8615c
E
297 'civicrm_financial_trxn' => array(
298 'dao' => 'CRM_Financial_DAO_FinancialTrxn',
299 'fields' => array(
5e0343e8 300 'card_type_id' => array(
d72b084a 301 'title' => ts('Credit Card Type'),
5e0343e8 302 'dbAlias' => 'GROUP_CONCAT(financial_trxn_civireport.card_type_id SEPARATOR ",")',
cce8615c
E
303 ),
304 ),
305 'filters' => array(
5e0343e8 306 'card_type_id' => array(
d72b084a 307 'title' => ts('Credit Card Type'),
cce8615c 308 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
5e0343e8 309 'options' => CRM_Financial_DAO_FinancialTrxn::buildOptions('card_type_id'),
cce8615c
E
310 'default' => NULL,
311 'type' => CRM_Utils_Type::T_STRING,
312 ),
313 ),
314 ),
6a488035
TO
315 );
316
d62fab33 317 // If we have a campaign, build out the relevant elements
e542272e 318 $this->addCampaignFields('civicrm_contribution');
d62fab33 319
16e2e80c 320 $this->_groupFilter = TRUE;
6a488035 321 $this->_tagFilter = TRUE;
c6348f97 322
323 $this->_currencyColumn = 'civicrm_contribution_currency';
6a488035
TO
324 parent::__construct();
325 }
326
00be9182 327 public function preProcess() {
6a488035
TO
328 parent::preProcess();
329 }
330
00be9182 331 public function select() {
6a488035
TO
332 $select = array();
333 $this->_columnHeaders = array();
334 foreach ($this->_columns as $tableName => $table) {
335 if (array_key_exists('fields', $table)) {
336 foreach ($table['fields'] as $fieldName => $field) {
9d72cede
EM
337 if (!empty($field['required']) ||
338 !empty($this->_params['fields'][$fieldName])
339 ) {
6a488035
TO
340
341 // include email column if set
342 if ($tableName == 'civicrm_email') {
343 $this->_emailField = TRUE;
344 $this->_emailFieldCredit = TRUE;
345 }
346 elseif ($tableName == 'civicrm_email_creditor') {
347 $this->_emailFieldCredit = TRUE;
348 }
349
350 // include phone columns if set
351 if ($tableName == 'civicrm_phone') {
352 $this->_phoneField = TRUE;
353 $this->_phoneFieldCredit = TRUE;
354 }
355 elseif ($tableName == 'civicrm_phone_creditor') {
356 $this->_phoneFieldCredit = TRUE;
357 }
358
359 // only include statistics columns if set
a7488080 360 if (!empty($field['statistics'])) {
6a488035
TO
361 foreach ($field['statistics'] as $stat => $label) {
362 switch (strtolower($stat)) {
363 case 'sum':
364 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
365 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
366 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
367 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
368 break;
369
370 case 'count':
371 $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
372 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
373 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
374 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
375 break;
376
377 case 'avg':
378 $select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}";
379 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
380 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
381 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
382 break;
383 }
384 }
385 }
386 else {
387 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
388 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
389 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
390 }
391 }
392 }
393 }
394 }
d1641c51 395 $this->selectClause = $select;
6a488035 396
c6348f97 397 $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
6a488035
TO
398 }
399
74cf4551 400 /**
bef4d7ee 401 * @param array $fields
402 * @param array $files
403 * @param CRM_Core_Form $self
74cf4551
EM
404 *
405 * @return array
406 */
00be9182 407 public static function formRule($fields, $files, $self) {
6a488035
TO
408 $errors = $grouping = array();
409 return $errors;
410 }
411
00be9182 412 public function from() {
6a488035 413 $alias_constituent = 'constituentname';
9d72cede
EM
414 $alias_creditor = 'contact_civireport';
415 $this->_from = "
6a488035 416 FROM civicrm_contribution {$this->_aliases['civicrm_contribution']}
f813f78e 417 INNER JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
418 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
6a488035 419 {$this->_aliases['civicrm_contribution']}.id
f813f78e 420 INNER JOIN civicrm_contact {$alias_constituent}
421 ON {$this->_aliases['civicrm_contribution']}.contact_id =
6a488035 422 {$alias_constituent}.id
f813f78e 423 LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
424 ON {$this->_aliases['civicrm_contribution']}.financial_type_id =
6a488035
TO
425 {$this->_aliases['civicrm_financial_type']}.id
426 LEFT JOIN civicrm_contact {$alias_creditor}
f813f78e 427 ON {$this->_aliases['civicrm_contribution_soft']}.contact_id =
428 {$alias_creditor}.id
6a488035
TO
429 {$this->_aclFrom} ";
430
431 // include Constituent email field if email column is to be included
432 if ($this->_emailField) {
433 $alias = 'emailconst';
434 $this->_from .= "
f813f78e 435 LEFT JOIN civicrm_email {$alias}
436 ON {$alias_constituent}.id =
437 {$alias}.contact_id AND
6a488035
TO
438 {$alias}.is_primary = 1\n";
439 }
440
441 // include Creditors email field if email column is to be included
442 if ($this->_emailFieldCredit) {
443 $alias = 'emailcredit';
444 $this->_from .= "
f813f78e 445 LEFT JOIN civicrm_email {$alias}
446 ON {$alias_creditor}.id =
447 {$alias}.contact_id AND
6a488035
TO
448 {$alias}.is_primary = 1\n";
449 }
450
451 // include Constituents phone field if email column is to be included
452 if ($this->_phoneField) {
453 $alias = 'pconst';
454 $this->_from .= "
f813f78e 455 LEFT JOIN civicrm_phone {$alias}
456 ON {$alias_constituent}.id =
6a488035
TO
457 {$alias}.contact_id AND
458 {$alias}.is_primary = 1\n";
459 }
460
461 // include Creditors phone field if email column is to be included
462 if ($this->_phoneFieldCredit) {
463 $alias = 'pcredit';
464 $this->_from .= "
465 LEFT JOIN civicrm_phone pcredit
f813f78e 466 ON {$alias_creditor}.id =
467 {$alias}.contact_id AND
6a488035
TO
468 {$alias}.is_primary = 1\n";
469 }
cce8615c
E
470 // for credit card type
471 $this->addFinancialTrxnFromClause();
6a488035
TO
472 }
473
00be9182 474 public function groupBy() {
9d72cede 475 $this->_rollup = 'WITH ROLLUP';
36d2f4d5 476 $this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($this->selectClause, array("{$this->_aliases['civicrm_contribution_soft']}.contact_id", "constituentname.id"));
9d72cede 477 $this->_groupBy = "
bad98dd5 478GROUP BY {$this->_aliases['civicrm_contribution_soft']}.contact_id, constituentname.id {$this->_rollup}";
6a488035
TO
479 }
480
00be9182 481 public function where() {
6a488035
TO
482 parent::where();
483 $this->_where .= " AND {$this->_aliases['civicrm_contribution']}.is_test = 0 ";
484 }
485
74cf4551
EM
486 /**
487 * @param $rows
488 *
489 * @return array
490 */
00be9182 491 public function statistics(&$rows) {
6a488035
TO
492 $statistics = parent::statistics($rows);
493
494 $select = "
42f0302b 495 SELECT COUNT({$this->_aliases['civicrm_contribution_soft']}.amount ) as count,
496 SUM({$this->_aliases['civicrm_contribution_soft']}.amount ) as amount,
497 ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as avg,
c6348f97 498 {$this->_aliases['civicrm_contribution']}.currency as currency
6a488035
TO
499 ";
500
c6348f97 501 $sql = "{$select} {$this->_from} {$this->_where}
502GROUP BY {$this->_aliases['civicrm_contribution']}.currency
503";
6a488035 504
c6348f97 505 $dao = CRM_Core_DAO::executeQuery($sql);
506 $count = 0;
51fa20cb 507 $totalAmount = $average = array();
c6348f97 508 while ($dao->fetch()) {
28a04ea9 509 $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency) . '(' .
9d72cede
EM
510 $dao->count . ')';
511 $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
c6348f97 512 $count += $dao->count;
6a488035 513 }
c6348f97 514 $statistics['counts']['amount'] = array(
515 'title' => ts('Total Amount'),
516 'value' => implode(', ', $totalAmount),
517 'type' => CRM_Utils_Type::T_STRING,
518 );
519 $statistics['counts']['count'] = array(
be205937 520 'title' => ts('Total Contributions'),
c6348f97 521 'value' => $count,
522 );
523 $statistics['counts']['avg'] = array(
524 'title' => ts('Average'),
525 'value' => implode(', ', $average),
526 'type' => CRM_Utils_Type::T_STRING,
527 );
6a488035
TO
528
529 return $statistics;
530 }
531
00be9182 532 public function postProcess() {
6a488035
TO
533 $this->beginPostProcess();
534
535 $this->buildACLClause(array('constituentname', 'contact_civireport'));
536 $sql = $this->buildQuery();
537
9d72cede
EM
538 $dao = CRM_Core_DAO::executeQuery($sql);
539 $rows = $graphRows = array();
6a488035
TO
540 $count = 0;
541 while ($dao->fetch()) {
542 $row = array();
543 foreach ($this->_columnHeaders as $key => $value) {
544 $row[$key] = $dao->$key;
545 }
546 $rows[] = $row;
547 }
548 $this->formatDisplay($rows);
549
550 // to hide the contact ID field from getting displayed
551 unset($this->_columnHeaders['civicrm_contact_id_constituent']);
552 unset($this->_columnHeaders['civicrm_contact_id_creditor']);
553
554 // assign variables to templates
555 $this->doTemplateAssignment($rows);
556 $this->endPostProcess($rows);
557 }
558
74cf4551 559 /**
ced9bfed
EM
560 * Alter display of rows.
561 *
562 * Iterate through the rows retrieved via SQL and make changes for display purposes,
563 * such as rendering contacts as links.
564 *
565 * @param array $rows
566 * Rows generated by SQL, with an array for each row.
74cf4551 567 */
00be9182 568 public function alterDisplay(&$rows) {
9d72cede 569 $entryFound = FALSE;
6a488035 570 $dispname_flag = $phone_flag = $email_flag = 0;
9d72cede 571 $prev_email = $prev_dispname = $prev_phone = NULL;
6a488035
TO
572
573 foreach ($rows as $rowNum => $row) {
574 // Link constituent (contributor) to contribution detail
575 if (array_key_exists('civicrm_contact_display_name_constituent', $row) &&
576 array_key_exists('civicrm_contact_id_constituent', $row)
577 ) {
578
579 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
9d72cede
EM
580 'reset=1&force=1&id_op=eq&id_value=' .
581 $row['civicrm_contact_id_constituent'],
6a488035
TO
582 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
583 );
584 $rows[$rowNum]['civicrm_contact_display_name_constituent_link'] = $url;
c6348f97 585 $rows[$rowNum]['civicrm_contact_display_name_constituent_hover'] = ts('List all direct contribution(s) from this contact.');
6a488035
TO
586 $entryFound = TRUE;
587 }
588
e1ea3ee3 589 // convert soft credit contact name to link
9d72cede
EM
590 if (array_key_exists('civicrm_contact_display_name_creditor', $row) &&
591 !empty($rows[$rowNum]['civicrm_contact_display_name_creditor']) &&
e1ea3ee3
DG
592 array_key_exists('civicrm_contact_id_creditor', $row)
593 ) {
594 $url = CRM_Utils_System::url("civicrm/contact/view",
595 'reset=1&cid=' . $row['civicrm_contact_id_creditor'],
596 $this->_absoluteUrl
597 );
598 $rows[$rowNum]['civicrm_contact_display_name_creditor_link'] = $url;
599 $rows[$rowNum]['civicrm_contact_display_name_creditor_hover'] = ts("view contact summary");
600 }
601
6a488035
TO
602 // make subtotals look nicer
603 if (array_key_exists('civicrm_contact_id_constituent', $row) &&
604 !$row['civicrm_contact_id_constituent']
605 ) {
606 $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
607 $entryFound = TRUE;
608 }
609
d62fab33
RN
610 // convert campaign_id to campaign title
611 if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
612 if ($value = $row['civicrm_contribution_campaign_id']) {
e542272e 613 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->campaigns[$value];
d62fab33
RN
614 $entryFound = TRUE;
615 }
616 }
617
51fa20cb 618 //convert soft_credit_type_id into label
619 if (array_key_exists('civicrm_contribution_soft_soft_credit_type_id', $rows[$rowNum])) {
7a4192f7 620 $rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id'] = CRM_Core_PseudoConstant::getLabel(
621 'CRM_Contribute_BAO_ContributionSoft',
622 'soft_credit_type_id',
623 $row['civicrm_contribution_soft_soft_credit_type_id']
624 );
51fa20cb 625 }
626
70bea8e2 627 //handle gender
628 if (array_key_exists('civicrm_contact_gender_id', $row)) {
629 if ($value = $row['civicrm_contact_gender_id']) {
630 $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
631 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
632 }
633 $entryFound = TRUE;
634 }
635
636 // display birthday in the configured custom format
637 if (array_key_exists('civicrm_contact_birth_date', $row)) {
638 $birthDate = $row['civicrm_contact_birth_date'];
639 if ($birthDate) {
640 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d');
641 }
642 $entryFound = TRUE;
643 }
644
5e0343e8 645 if (!empty($row['civicrm_financial_trxn_card_type_id']) && !in_array('Subtotal', $rows[$rowNum])) {
646 $rows[$rowNum]['civicrm_financial_trxn_card_type_id'] = $this->getLabels($row['civicrm_financial_trxn_card_type_id'], 'CRM_Financial_DAO_FinancialTrxn', 'card_type_id');
cce8615c
E
647 $entryFound = TRUE;
648 }
649
6a488035
TO
650 // skip looking further in rows, if first row itself doesn't
651 // have the column we need
652 if (!$entryFound) {
653 break;
654 }
655 }
656
657 $this->removeDuplicates($rows);
658 }
96025800 659
6a488035 660}