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