Merge pull request #941 from kurund/CRM-12711
[civicrm-core.git] / tools / extensions / org.civicrm.report.baykeeper / Baykeeper.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.1 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2010 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2010
32 * $Id$
33 *
34 */
35
36require_once 'CRM/Report/Form.php';
37require_once 'CRM/Contribute/PseudoConstant.php';
38require_once 'CRM/Core/OptionGroup.php';
39require_once 'CRM/Event/BAO/Participant.php';
40require_once 'CRM/Contact/BAO/Contact.php';
41class CRM_Report_Form_Contribute_Baykeeper extends CRM_Report_Form {
42 protected $_addressField = FALSE;
43
44 protected $_emailField = FALSE;
45
46 protected $_summary = NULL;
47
48 protected $_customGroupExtends = array('Contact', 'Contribution'); function __construct() {
49 $this->_columns = array('civicrm_contact' =>
50 array('dao' => 'CRM_Contact_DAO_Contact',
51 'fields' =>
52 array('display_name' =>
53 array('title' => ts('Contact Name'),
54 'required' => TRUE,
55 'no_repeat' => TRUE,
56 ),
57 'id' =>
58 array('no_display' => FALSE,
59 'title' => ts('Contact ID'),
60 'required' => TRUE,
61 ),
62 'contact_id' =>
63 array('title' => ts('Contact ID'),
64 'name' => 'id',
65 'default' => FALSE,
66 'no_repeat' => TRUE,
67 'required' => TRUE,
68 ),
69 'addressee_display' => array('title' => ts('Addressee Name')),
70 'postal_greeting_display' => array('title' => ts('Greeting')),
71 'display_name_creditor' =>
72 array('title' => ts('Soft Credit Name'),
73 'name' => 'display_name',
74 'alias' => 'soft_credit',
75 'no_repeat' => TRUE,
76 ),
77 'id_creditor' =>
78 array('title' => ts('Soft Credit Id'),
79 'name' => 'id',
80 'alias' => 'soft_credit',
81 ),
82 'employer_name' =>
83 array('title' => ts('Employer Name'),
84 'name' => 'display_name',
85 'alias' => 'employer_company',
86 ),
87 'employer_id' =>
88 array('title' => ts('Employer Id'),
89 'name' => 'employer_id',
90 ),
91 'do_not_mail' => array('title' => ts('Do Not Mail')),
92 ),
93 'filters' =>
94 array('sort_name' =>
95 array('title' => ts('Contact Name'),
96 'operator' => 'like',
97 ),
98 'id' =>
99 array('title' => ts('Contact ID'),
100 'no_display' => TRUE,
101 ),
102 ),
103 'grouping' => 'contact-fields',
104 ),
105 'civicrm_email' =>
106 array('dao' => 'CRM_Core_DAO_Email',
107 'fields' =>
108 array('email' =>
109 array('title' => ts('Email'),
110 'default' => TRUE,
111 'no_repeat' => TRUE,
112 ),
113 ),
114 'grouping' => 'contact-fields',
115 ),
116 'civicrm_phone' =>
117 array('dao' => 'CRM_Core_DAO_Phone',
118 'fields' =>
119 array('phone' =>
120 array('title' => ts('Phone'),
121 'default' => TRUE,
122 'no_repeat' => TRUE,
123 ),
124 ),
125 'grouping' => 'contact-fields',
126 ),
127 'civicrm_address' =>
128 array('dao' => 'CRM_Core_DAO_Address',
129 'fields' =>
130 array('street_address' => NULL,
131 'supplemental_address_1' => array('title' => ts('Sup Address 1'),
132 ),
133 'supplemental_address_2' => array('title' => ts('Sup Address 2'),
134 ),
135 'city' => NULL,
136 'postal_code' => NULL,
137 'location_type_id' => array('title' => ts('Location Type ID'),
138 ),
139 'state_province_id' =>
140 array('title' => ts('State/Province'),
141 ),
142 'country_id' =>
143 array('title' => ts('Country'),
144 'default' => TRUE,
145 ),
146 ),
147 'grouping' => 'contact-fields',
148 'filters' =>
149 array('country_id' =>
150 array('title' => ts('Country'),
151 'type' => CRM_Utils_Type::T_INT,
152 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
153 'options' => CRM_Core_PseudoConstant::country(),
154 ),
155 'state_province_id' =>
156 array('title' => ts('State/Province'),
157 'type' => CRM_Utils_Type::T_INT,
158 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
159 'options' => CRM_Core_PseudoConstant::stateProvince(),
160 ),
161 ),
162 ),
163 'civicrm_contribution' =>
164 array('dao' => 'CRM_Contribute_DAO_Contribution',
165 'fields' =>
166 array(
167 'contribution_id' => array(
168 'name' => 'id',
169 'no_display' => TRUE,
170 'required' => TRUE,
171 ),
172 'contribution_type_id' => array('title' => ts('Contribution Type'),
173 'default' => TRUE,
174 ),
175 'trxn_id' => NULL,
176 'receive_date' => array('default' => TRUE),
177 'receipt_date' => NULL,
178 'source' => array('title' => ts('Source')),
179 'fee_amount' => NULL,
180 'net_amount' => NULL,
181 'non_deductible_amount' => array('title' => ts('Non Deductible Amount')),
182 'total_amount' => array('title' => ts('Total Amount'),
183 'required' => TRUE,
184 ),
185 'honor_contact_id' => array('title' => ts('Honor Contact ID'),
186 ),
187 'honor_type_id' => array('title' => ts('Hon/Mem Type')),
188 ),
189 'filters' =>
190 array('receive_date' =>
191 array('operatorType' => CRM_Report_Form::OP_DATE),
192 'contribution_type_id' =>
193 array('title' => ts('Contribution Type'),
194 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
195 'options' => CRM_Contribute_PseudoConstant::contributionType(),
196 ),
197 'contribution_status_id' =>
198 array('title' => ts('Contribution Status'),
199 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
200 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
201 ),
202 'total_amount' =>
203 array('title' => ts('Contribution Amount')),
204 ),
205 'grouping' => 'contri-fields',
206 ),
207 'civicrm_contact_hon_mem' =>
208 array('dao' => 'CRM_Contact_DAO_Contact',
209 'alias' => 'hon_mem',
210 'fields' =>
211 array('id' => array('title' => ts('Hon/Mem Contact ID'),
212 'required' => TRUE,
213 'no_display' => TRUE,
214 ),
215 'display_name' => array('title' => ts('In Honor Of'),
216 'required' => FALSE,
217 ),
218 ),
219 'grouping' => 'contri-fields',
220 ),
221 'civicrm_note' =>
222 array('dao' => 'CRM_Core_DAO_Note',
223 'fields' =>
224 array(
225 'note' =>
226 array('title' => ts('Note'),
227 'default' => TRUE,
228 'no_repeat' => FALSE,
229 ),
230 ),
231 'grouping' => 'contri-fields',
232 ),
233 'civicrm_contribution_soft' =>
234 array('dao' => 'CRM_Contribute_DAO_ContributionSoft',
235 'fields' =>
236 array('contribution_id' =>
237 array('title' => ts('Contribution ID'),
238 'no_display' => TRUE,
239 'default' => TRUE,
240 ),
241 'contact_id' =>
242 array('title' => ts('Contact ID'),
243 'no_display' => TRUE,
244 'default' => TRUE,
245 ),
246 'id' =>
247 array('default' => TRUE,
248 'no_display' => TRUE,
249 ),
250 ),
251 'grouping' => 'softcredit-fields',
252 ),
253 'civicrm_group_field' =>
254 array('dao' => 'CRM_Contact_DAO_Group',
255 'fields' =>
256 array('title' =>
257 array('title' => ts('Groups')),
258 ),
259 ),
260 'civicrm_group' =>
261 array('dao' => 'CRM_Contact_DAO_GroupContact',
262 'alias' => 'cgroup',
263 'fields' =>
264 array(,
265 ),
266 'filters' =>
267 array('gid' =>
268 array('name' => 'group_id',
269 'title' => ts('Group'),
270 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
271 'group' => TRUE,
272 'options' => CRM_Core_PseudoConstant::group(),
273 ),
274 ),
275 ),
276 'civicrm_contribution_ordinality' =>
277 array('dao' => 'CRM_Contribute_DAO_Contribution',
278 'alias' => 'cordinality',
279 'filters' =>
280 array('ordinality' =>
281 array('title' => ts('Contribution Ordinality'),
282 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
283 'options' => array(0 => 'First by Contributor',
284 1 => 'Second or Later by Contributor',
285 ),
286 ),
287 ),
288 ),
289 );
290
291 $this->_options = array('first_contribution' => array('title' => ts('First Contribution'),
292 'type' => 'checkbox',
293 ),
294 'last_contribution' => array('title' => ts('Last Contribution'),
295 'type' => 'checkbox',
296 ),
297 'include_nondonors' => array('title' => ts('Include non-donors?'),
298 'type' => 'checkbox',
299 ),
300 );
301
302 $this->_tagFilter = TRUE;
303 parent::__construct();
304 }
305
306 function preProcess() {
307 parent::preProcess();
308 }
309
310 function select() {
311 $select = array();
312
313 $this->_columnHeaders = array();
314 foreach ($this->_columns as $tableName => $table) {
315 if (array_key_exists('fields', $table)) {
316 foreach ($table['fields'] as $fieldName => $field) {
317 if (CRM_Utils_Array::value('required', $field) ||
318 CRM_Utils_Array::value($fieldName, $this->_params['fields'])
319 ) {
320 if ($tableName == 'civicrm_address') {
321 $this->_addressField = TRUE;
322 }
323 elseif ($tableName == 'civicrm_email') {
324 $this->_emailField = TRUE;
325 }
326 /*
327 if ( $tableName == 'civicrm_group_field' && $fieldName == 'title' ) {
328 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
329 } else {
330 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
331 }
332 */
333
334
335 // only include statistics columns if set
336 if (CRM_Utils_Array::value('statistics', $field)) {
337 foreach ($field['statistics'] as $stat => $label) {
338 switch (strtolower($stat)) {
339 case 'sum':
340 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
341 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
342 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
343 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
344 break;
345
346 case 'count':
347 $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
348 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
349 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
350 break;
351
352 case 'avg':
353 $select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}";
354 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
355 $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
356 $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
357 break;
358 }
359 }
360 }
361 elseif ($tableName == 'civicrm_group_field' && $fieldName == 'title') {
362 $select[] = " GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} SEPARATOR ' | <br>') as {$tableName}_{$fieldName} ";
363 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
364 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
365 }
366 else {
367 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
368 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
369 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
370 }
371 }
372 }
373 }
374 }
375
376 // insert first and last contribution at end
377 if (CRM_Utils_Array::value('first_contribution', $this->_params['options'])) {
378 $select[] = " '' as first_contribution";
379 $this->_columnHeaders['first_contribution']['title'] = ts('First Contribution');
380 }
381
382 if (CRM_Utils_Array::value('last_contribution', $this->_params['options'])) {
383 $select[] = " '' as last_contribution";
384 $this->_columnHeaders['last_contribution']['title'] = ts('Last Contribution');
385 }
386
387
388 $this->_select = "SELECT " . implode(', ', $select) . " ";
389 }
390
391 function from() {
392 $alias_constituent = 'constituentname';
393 $alias_creditor = 'soft_credit';
394 $alias_employer = "employer_company";
395
396 $this->_from = NULL;
397
398 $hackValue = CRM_Utils_Array::value('include_nondonors', $this->_params['options'], 0);
399 $contribJoin = $hackValue ? "LEFT" : "INNER";
400
401 $this->_from = "
402 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
403 $contribJoin JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
404 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND {$this->_aliases['civicrm_contribution']}.is_test = 0
405 $contribJoin JOIN (SELECT c.id, IF(COUNT(oc.id) = 0, 0, 1) AS ordinality FROM civicrm_contribution c LEFT JOIN civicrm_contribution oc ON c.contact_id = oc.contact_id AND oc.receive_date < c.receive_date GROUP BY c.id) {$this->_aliases['civicrm_contribution_ordinality']}
406 ON {$this->_aliases['civicrm_contribution_ordinality']}.id = {$this->_aliases['civicrm_contribution']}.id
407 LEFT JOIN civicrm_note {$this->_aliases['civicrm_note']}
408 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_note']}.contact_id AND
409 {$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_note']}.entity_id )
410 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
411 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
412 {$this->_aliases['civicrm_phone']}.is_primary = 1)
413 LEFT JOIN civicrm_contact {$alias_employer}
414 ON {$this->_aliases['civicrm_contact']}.employer_id =
415 {$alias_employer}.id
416 LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
417 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
418 {$this->_aliases['civicrm_contribution']}.id
419 LEFT JOIN civicrm_contact {$alias_creditor}
420 ON {$this->_aliases['civicrm_contribution_soft']}.contact_id =
421 {$alias_creditor}.id
422 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_hon_mem']}
423 ON {$this->_aliases['civicrm_contribution']}.honor_contact_id = {$this->_aliases['civicrm_contact_hon_mem']}.id
424 ";
425 // add group - concatenated
426 $this->_from .= " LEFT JOIN civicrm_group_contact gc ON {$this->_aliases['civicrm_contact']}.id = gc.contact_id AND gc.status = 'Added'
427 LEFT JOIN civicrm_group {$this->_aliases['civicrm_group_field']} ON {$this->_aliases['civicrm_group_field']}.id = gc.group_id ";
428
429 if ($this->_addressField OR (!empty($this->_params['state_province_id_value']) OR !empty($this->_params['country_id_value']))) {
430 $this->_from .= "
431 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
432 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
433 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
434 }
435
436 if ($this->_emailField) {
437 $this->_from .= "
438 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
439 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
440 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
441 }
442 }
443
444 function groupBy() {
445 $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.id ";
446 }
447
448 function orderBy() {
449 $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.receive_date ";
450 }
451
452 function statistics(&$rows) {
453 $statistics = parent::statistics($rows);
454 // because the query returns groups, the amount is multiplied by the number of groups a contact is in
455 // that's why this is disabled
456 /* SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount, */
457
458
459 $select = "
460 SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
461 ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg
462 ";
463 $sql = "{$select} {$this->_from} {$this->_where}";
464 $dao = CRM_Core_DAO::executeQuery($sql);
465
466 if ($dao->fetch()) {
467 // because the query returns groups, the amount is multiplied by the number of groups a contact is in
468 // that's why this is disabled
469 /* SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount, */
470
471
472 /*
473 $statistics['counts']['amount'] = array( 'value' => $dao->amount,
474 'title' => 'Total Amount',
475 'type' => CRM_Utils_Type::T_MONEY );
476 $statistics['counts']['avg'] = array( 'value' => $dao->avg,
477 'title' => 'Average',
478 'type' => CRM_Utils_Type::T_MONEY );
479 */
480 }
481
482 return $statistics;
483 }
484
485 function postProcess() {
486 // get the acl clauses built before we assemble the query
487 $this->buildACLClause($this->_aliases['civicrm_contact']);
488 parent::postProcess();
489 }
490
491 function alterDisplay(&$rows) {
492
493 require_once 'CRM/Contribute/BAO/Contribution/Utils.php';
494 require_once 'CRM/Utils/Money.php';
495 require_once 'CRM/Utils/Date.php';
496
497 $config = &CRM_Core_Config::singleton();
498
499 // custom code to alter rows
500 $checkList = array();
501 $entryFound = FALSE;
502 $display_flag = $prev_cid = $cid = 0;
503 $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
504
505 foreach ($rows as $rowNum => $row) {
506 if (!empty($this->_noRepeats) &&
507 $this->_outputMode != 'csv'
508 ) {
509 // don't repeat contact details if its same as the previous row
510 if (array_key_exists('civicrm_contact_id', $row)) {
511 if ($cid = $row['civicrm_contact_id']) {
512 if ($rowNum == 0) {
513 $prev_cid = $cid;
514 }
515 else {
516 if ($prev_cid == $cid) {
517 $display_flag = 1;
518 $prev_cid = $cid;
519 }
520 else {
521 $display_flag = 0;
522 $prev_cid = $cid;
523 }
524 }
525
526 if ($display_flag) {
527 foreach ($row as $colName => $colVal) {
528 if (in_array($colName, $this->_noRepeats)) {
529 unset($rows[$rowNum][$colName]);
530 }
531 }
532 }
533 $entryFound = TRUE;
534 }
535 }
536 }
537
538 if (array_key_exists('first_contribution', $row) ||
539 array_key_exists('last_contribution', $row)
540 ) {
541 $details = CRM_Contribute_BAO_Contribution_Utils::getFirstLastDetails($row['civicrm_contact_id']);
542 if ($details['first']) {
543 $rows[$rowNum]['first_contribution'] = CRM_Utils_Money::format($details['first']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['first']['receive_date'], $config->dateformatFull);
544 }
545 if ($details['last']) {
546 $rows[$rowNum]['last_contribution'] = CRM_Utils_Money::format($details['last']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['last']['receive_date'], $config->dateformatFull);
547 }
548 }
549
550 // handle state province
551 if (array_key_exists('civicrm_address_state_province_id', $row)) {
552 if ($value = $row['civicrm_address_state_province_id']) {
553 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
554
555 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
556 "reset=1&force=1&" .
557 "state_province_id_op=in&state_province_id_value={$value}",
558 $this->_absoluteUrl, $this->_id
559 );
560 $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url;
561 $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("List all contribution(s) for this State.");
562 }
563 $entryFound = TRUE;
564 }
565
566 // handle country
567 if (array_key_exists('civicrm_address_country_id', $row)) {
568 if ($value = $row['civicrm_address_country_id']) {
569 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE);
570
571 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
572 "reset=1&force=1&" .
573 "country_id_op=in&country_id_value={$value}",
574 $this->_absoluteUrl, $this->_id
575 );
576 $rows[$rowNum]['civicrm_address_country_id_link'] = $url;
577 $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("List all contribution(s) for this Country.");
578 }
579
580 $entryFound = TRUE;
581 }
582
583 // convert display name to links
584 if (array_key_exists('civicrm_contact_display_name', $row) &&
585 CRM_Utils_Array::value('civicrm_contact_display_name', $rows[$rowNum]) &&
586 array_key_exists('civicrm_contact_id', $row)
587 ) {
588 $url = CRM_Utils_System::url("civicrm/contact/view",
589 'reset=1&cid=' . $row['civicrm_contact_id'],
590 $this->_absoluteUrl
591 );
592 $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
593 $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact.");
594 }
595
596 // convert soft credit id to link
597 if (array_key_exists('soft_credit_display_name', $row) &&
598 CRM_Utils_Array::value('soft_credit_display_name', $rows[$rowNum]) &&
599 array_key_exists('id', $row)
600 ) {
601 $url = CRM_Utils_System::url("civicrm/contact/view",
602 'reset=1&cid=' . $row['id'],
603 $this->_absoluteUrl
604 );
605 $rows[$rowNum]['soft_credit_display_name_creditor_link'] = $url;
606 $rows[$rowNum]['soft_credit_display_name_creditor_hover'] = ts("View Contact Summary for this Soft Credit.");
607 }
608
609 // convert hon/mem contact to link
610 if (array_key_exists('civicrm_contact_hon_mem_display_name', $row) &&
611 CRM_Utils_Array::value('civicrm_contribution_honor_contact_id', $rows[$rowNum]) &&
612 array_key_exists('civicrm_contribution_honor_contact_id', $row)
613 ) {
614 $url = CRM_Utils_System::url("civicrm/contact/view",
615 'reset=1&cid=' . $row['civicrm_contribution_honor_contact_id'],
616 $this->_absoluteUrl
617 );
618 $rows[$rowNum]['civicrm_contact_hon_mem_display_name_link'] = $url;
619 $rows[$rowNum]['civicrm_contact_hon_mem_display_name_hover'] = ts("View Contact Summary for this Honor/Memory Contribution.");
620 }
621
622 // honor of/memory of type
623 if ($value = CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $row) &&
624 CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $rows[$rowNum])
625 ) {
626 // rather than do a join, just change the output here, since there these values are pretty static
627
628
629 if ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 1) {
630 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Honor Of";
631 }
632 elseif ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 2) {
633 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Memory Of";
634 }
635 else {
636 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "n/a";
637 }
638 }
639
640 if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) {
641 $rows[$rowNum]['civicrm_contribution_contribution_type_id'] = $contributionTypes[$value];
642 $entryFound = TRUE;
643 }
644
645 if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount', $row)) &&
646 CRM_Core_Permission::check('access CiviContribute')
647 ) {
648 $url = CRM_Utils_System::url("civicrm/contact/view/contribution",
649 "reset=1&id=" .
650 $row['civicrm_contribution_contribution_id'] .
651 "&cid=" .
652 $row['civicrm_contact_id'] .
653 "&action=view&context=contribution&selectedChild=contribute",
654 $this->_absoluteUrl
655 );
656 $rows[$rowNum]['civicrm_contribution_total_amount_link'] = $url;
657 $rows[$rowNum]['civicrm_contribution_total_amount_hover'] = ts("View Details of this Contribution.");
658 $entryFound = TRUE;
659 }
660
661 // skip looking further in rows, if first row itself doesn't
662 // have the column we need
663 if (!$entryFound) {
664 break;
665 }
666 $lastKey = $rowNum;
667 }
668 }
669}
670