Merge pull request #8636 from eileenmcnaughton/slow_query
[civicrm-core.git] / CRM / Report / Form / Pledge / Detail.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 27
850e4640 28
9d72cede
EM
29/*
30 * !!!!!!!!!!!!!!!!!!!!
31 * NB: this is named detail but behaves like a summary report.
32 * It is also accessed through the Pledge Summary link in the UI
33 * This should presumably be changed.
34 * ~ Doten
35 * !!!!!!!!!!!!!!!!!!!!
36 *
37 */
2ebf49a4 38
6a488035
TO
39/**
40 *
41 * @package CRM
fa938177 42 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
43 * $Id$
44 *
45 */
46class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form {
47
48 protected $_summary = NULL;
49 protected $_totalPaid = FALSE;
edcb3801 50 protected $_pledgeStatuses = array();
6a488035
TO
51 protected $_customGroupExtends = array(
52 'Pledge',
21dfd5f5 53 'Individual',
6a488035 54 );
74cf4551
EM
55
56 /**
36aff7b7 57 * Class constructor.
74cf4551 58 */
00be9182 59 public function __construct() {
9d72cede
EM
60 $this->_pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
61 // Check if CiviCampaign is a) enabled and b) has active campaigns
62 $config = CRM_Core_Config::singleton();
2ebf49a4
CD
63 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
64 if ($campaignEnabled) {
65 $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
66 $this->activeCampaigns = $getCampaigns['campaigns'];
67 asort($this->activeCampaigns);
68 }
69
6a488035 70 $this->_columns = array(
a130e045
DG
71 'civicrm_contact' => array(
72 'dao' => 'CRM_Contact_DAO_Contact',
73 'fields' => array(
74 'sort_name' => array(
75 'title' => ts('Contact Name'),
76 'required' => TRUE,
77 'no_repeat' => TRUE,
6a488035 78 ),
9d72cede 79 ),
a130e045
DG
80 'filters' => array(
81 'sort_name' => array('title' => ts('Contact Name')),
82 'id' => array('no_display' => TRUE),
83 ),
84 'grouping' => 'contact-fields',
85 ),
86 'civicrm_email' => array(
87 'dao' => 'CRM_Core_DAO_Email',
88 'fields' => array(
89 'email' => array('no_repeat' => TRUE),
90 ),
91 'grouping' => 'contact-fields',
92 ),
93 'civicrm_pledge' => array(
94 'dao' => 'CRM_Pledge_DAO_Pledge',
95 'fields' => array(
96 'id' => array(
97 'no_display' => TRUE,
98 'required' => TRUE,
99 ),
100 'contact_id' => array(
101 'no_display' => TRUE,
102 'required' => TRUE,
103 ),
9e335308 104 'financial_type_id' => array(
105 'title' => ts('Financial Type'),
106 ),
a130e045
DG
107 'amount' => array(
108 'title' => ts('Pledge Amount'),
109 'required' => TRUE,
110 'type' => CRM_Utils_Type::T_MONEY,
111 ),
112 'currency' => array(
113 'required' => TRUE,
114 'no_display' => TRUE,
115 ),
116 'frequency_unit' => array(
117 'title' => ts('Frequency Unit'),
118 ),
119 'installments' => array(
120 'title' => ts('Installments'),
121 ),
122 'pledge_create_date' => array(
123 'title' => ts('Pledge Made Date'),
124 ),
125 'start_date' => array(
126 'title' => ts('Pledge Start Date'),
127 'type' => CRM_Utils_Type::T_DATE,
128 ),
129 'end_date' => array(
130 'title' => ts('Pledge End Date'),
131 'type' => CRM_Utils_Type::T_DATE,
132 ),
133 'status_id' => array(
134 'title' => ts('Pledge Status'),
135 'required' => TRUE,
9d72cede 136 ),
6a488035 137 ),
a130e045
DG
138 'filters' => array(
139 'pledge_create_date' => array(
140 'title' => 'Pledge Made Date',
141 'operatorType' => CRM_Report_Form::OP_DATE,
142 ),
143 'pledge_amount' => array(
144 'title' => ts('Pledged Amount'),
145 'operatorType' => CRM_Report_Form::OP_INT,
146 ),
147 'currency' => array(
148 'title' => 'Currency',
149 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
150 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
151 'default' => NULL,
152 'type' => CRM_Utils_Type::T_STRING,
153 ),
154 'sid' => array(
155 'name' => 'status_id',
156 'title' => ts('Pledge Status'),
8ee006e7 157 'type' => CRM_Utils_Type::T_INT,
a130e045
DG
158 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
159 'options' => CRM_Core_OptionGroup::values('contribution_status'),
160 ),
9e335308 161 'financial_type_id' => array(
162 'title' => ts('Financial Type'),
8ee006e7 163 'type' => CRM_Utils_Type::T_INT,
9e335308 164 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
165 'options' => CRM_Contribute_PseudoConstant::financialType(),
166 ),
850e4640 167
a130e045
DG
168 ),
169 ),
170 'civicrm_pledge_payment' => array(
171 'dao' => 'CRM_Pledge_DAO_PledgePayment',
172 'fields' => array(
173 'total_paid' => array(
174 'title' => ts('Total Amount Paid'),
175 'type' => CRM_Utils_Type::T_MONEY,
176 ),
177 'balance_due' => array(
178 'title' => ts('Balance Due'),
179 'default' => TRUE,
180 'type' => CRM_Utils_Type::T_MONEY,
9d72cede 181 ),
6a488035 182 ),
a130e045
DG
183 ),
184 );
185
186 $this->_columns += $this->getAddressColumns(array('group_by' => FALSE)) + $this->getPhoneColumns();
187
2ebf49a4
CD
188 // If we have a campaign, build out the relevant elements
189 $this->_tagFilter = TRUE;
190 if ($campaignEnabled && !empty($this->activeCampaigns)) {
9d72cede
EM
191 $this->_columns['civicrm_pledge']['fields']['campaign_id'] = array(
192 'title' => 'Campaign',
193 'default' => 'false',
194 );
195 $this->_columns['civicrm_pledge']['filters']['campaign_id'] = array(
196 'title' => ts('Campaign'),
197 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
198 'options' => $this->activeCampaigns,
942b1d01 199 'type' => CRM_Utils_Type::T_INT,
9d72cede
EM
200 );
201 $this->_columns['civicrm_pledge']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
2ebf49a4
CD
202
203 }
6a488035 204
16e2e80c 205 $this->_groupFilter = TRUE;
6a488035 206 $this->_tagFilter = TRUE;
9bf1940a 207 $this->_currencyColumn = 'civicrm_pledge_currency';
6a488035
TO
208 parent::__construct();
209 }
210
00be9182 211 public function preProcess() {
6a488035
TO
212 parent::preProcess();
213 }
214
00be9182 215 public function select() {
6a488035
TO
216 parent::select();
217 }
d424ffde 218
74cf4551 219 /**
fe482240 220 * If we are retrieving total paid we need to define the inclusion of pledge_payment.
d424ffde 221 *
100fef9d 222 * @param string $tableName
74cf4551 223 * @param $tableKey
100fef9d 224 * @param string $fieldName
74cf4551
EM
225 * @param $field
226 *
227 * @return bool|string
228 */
00be9182 229 public function selectClause(&$tableName, $tableKey, &$fieldName, &$field) {
9d72cede 230 if ($fieldName == 'total_paid') {
6a488035
TO
231 $this->_totalPaid = TRUE; // add pledge_payment join
232 $this->_columnHeaders["{$tableName}_{$fieldName}"] = array(
233 'title' => $field['title'],
21dfd5f5 234 'type' => $field['type'],
6a488035 235 );
edcb3801 236 return "COALESCE(sum({$this->_aliases[$tableName]}.actual_amount), 0) as {$tableName}_{$fieldName}";
6a488035 237 }
9d72cede 238 if ($fieldName == 'balance_due') {
edcb3801 239 $cancelledStatus = array_search('Cancelled', $this->_pledgeStatuses);
240 $completedStatus = array_search('Completed', $this->_pledgeStatuses);
6a488035
TO
241 $this->_totalPaid = TRUE; // add pledge_payment join
242 $this->_columnHeaders["{$tableName}_{$fieldName}"] = $field['title'];
243 $this->_columnHeaders["{$tableName}_{$fieldName}"] = array(
244 'title' => $field['title'],
21dfd5f5 245 'type' => $field['type'],
6a488035 246 );
9d72cede 247 return "IF({$this->_aliases['civicrm_pledge']}.status_id IN({$cancelledStatus}, $completedStatus), 0, COALESCE({$this->_aliases['civicrm_pledge']}.amount, 0) - COALESCE(sum({$this->_aliases[$tableName]}.actual_amount),0)) as {$tableName}_{$fieldName}";
6a488035
TO
248 }
249 return FALSE;
250 }
251
00be9182 252 public function groupBy() {
6a488035
TO
253 parent::groupBy();
254 if (empty($this->_groupBy) && $this->_totalPaid) {
d1641c51 255 $groupBy = array("{$this->_aliases['civicrm_pledge']}.id", "{$this->_aliases['civicrm_pledge']}.currency");
b708c08d 256 $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy);
6a488035
TO
257 }
258 }
9d72cede 259
00be9182 260 public function from() {
6a488035
TO
261 $this->_from = "
262 FROM civicrm_pledge {$this->_aliases['civicrm_pledge']}
263 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
264 ON ({$this->_aliases['civicrm_contact']}.id =
265 {$this->_aliases['civicrm_pledge']}.contact_id )
266 {$this->_aclFrom} ";
267
9d72cede 268 if ($this->_totalPaid) {
6a488035
TO
269 $this->_from .= "
270 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']} ON
271 {$this->_aliases['civicrm_pledge']}.id = {$this->_aliases['civicrm_pledge_payment']}.pledge_id
272 AND {$this->_aliases['civicrm_pledge_payment']}.status_id = 1
273 ";
274 }
275
850e4640
E
276 $this->addPhoneFromClause();
277 $this->addAddressFromClause();
6a488035
TO
278 // include email field if email column is to be included
279 if ($this->_emailField) {
280 $this->_from .= "
281 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
282 ON ({$this->_aliases['civicrm_contact']}.id =
283 {$this->_aliases['civicrm_email']}.contact_id) AND
284 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
285 }
286 }
287
74cf4551
EM
288 /**
289 * @param $rows
290 *
291 * @return array
292 */
00be9182 293 public function statistics(&$rows) {
6a488035 294 $statistics = parent::statistics($rows);
9d72cede 295 //regenerate the from field without extra left join on pledge payments
bcb4b43e 296 $totalPaid = $this->_totalPaid;
2d97372d 297 $this->_totalPaid = FALSE;
298 $this->from();
299 $this->customDataFrom();
6a488035 300 if (!$this->_having) {
7a961f19 301 $totalAmount = $average = array();
302 $count = 0;
6a488035 303 $select = "
edcb3801 304 SELECT COUNT({$this->_aliases['civicrm_pledge']}.amount ) as count,
305 SUM({$this->_aliases['civicrm_pledge']}.amount ) as amount,
306 ROUND(AVG({$this->_aliases['civicrm_pledge']}.amount), 2) as avg,
307 {$this->_aliases['civicrm_pledge']}.currency as currency
308 ";
6a488035 309
edcb3801 310 $group = "GROUP BY {$this->_aliases['civicrm_pledge']}.currency";
7a961f19 311 $sql = "{$select} {$this->_from} {$this->_where} {$group}";
6a488035 312 $dao = CRM_Core_DAO::executeQuery($sql);
f0472f17 313 $count = $index = $totalCount = 0;
edcb3801 314 // this will run once per currency
9d72cede 315 while ($dao->fetch()) {
edcb3801 316 $totalAmount = CRM_Utils_Money::format($dao->amount, $dao->currency);
9d72cede 317 $average = CRM_Utils_Money::format($dao->avg, $dao->currency);
edcb3801 318 $count = $dao->count;
f0472f17 319 $totalCount .= $count;
edcb3801 320 $statistics['counts']['amount' . $index] = array(
474f6ca2 321 'title' => ts('Total Pledged') . ' (' . $dao->currency . ')',
edcb3801 322 'value' => $totalAmount,
323 'type' => CRM_Utils_Type::T_STRING,
324 );
325 $statistics['counts']['avg' . $index] = array(
474f6ca2 326 'title' => ts('Average') . ' (' . $dao->currency . ')',
edcb3801 327 'value' => $average,
328 'type' => CRM_Utils_Type::T_STRING,
329 );
f0472f17 330 $statistics['counts']['count' . $index] = array(
474f6ca2 331 'title' => ts('Total No Pledges') . ' (' . $dao->currency . ')',
f0472f17 332 'value' => $count,
333 'type' => CRM_Utils_Type::T_INT,
334 );
9d72cede 335 $index++;
6a488035 336 }
9d72cede 337 if ($totalCount > $count) {
f0472f17 338 $statistics['counts']['count' . $index] = array(
339 'title' => ts('Total No Pledges'),
340 'value' => $totalCount,
341 'type' => CRM_Utils_Type::T_INT,
342 );
343 }
6a488035 344 }
bcb4b43e 345 // reset from clause
346 if ($totalPaid) {
347 $this->_totalPaid = TRUE;
348 $this->from();
349 }
6a488035
TO
350 return $statistics;
351 }
352
00be9182 353 public function orderBy() {
6a488035
TO
354 $this->_orderBy = "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact']}.id";
355 }
356
00be9182 357 public function where() {
6a488035
TO
358 $clauses = array();
359 foreach ($this->_columns as $tableName => $table) {
360 if (array_key_exists('filters', $table)) {
361 foreach ($table['filters'] as $fieldName => $field) {
362 $clause = NULL;
363 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
364 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
9d72cede
EM
365 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
366 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
6a488035
TO
367
368 if ($relative || $from || $to) {
369 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
370 }
371 }
372 else {
373 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
374 if ($op) {
375 $clause = $this->whereClause($field,
376 $op,
377 CRM_Utils_Array::value("{$fieldName}_value",
378 $this->_params
379 ),
380 CRM_Utils_Array::value("{$fieldName}_min",
381 $this->_params
382 ),
383 CRM_Utils_Array::value("{$fieldName}_max",
384 $this->_params
385 )
386 );
387 }
388 }
389
390 if (!empty($clause)) {
391 $clauses[] = $clause;
392 }
393 }
394 }
395 }
396 if (empty($clauses)) {
397 $this->_where = "WHERE ({$this->_aliases['civicrm_pledge']}.is_test=0 ) ";
398 }
399 else {
400 $this->_where = "WHERE ({$this->_aliases['civicrm_pledge']}.is_test=0 ) AND
edcb3801 401 " . implode(' AND ', $clauses);
6a488035
TO
402 }
403
404 if ($this->_aclWhere) {
405 $this->_where .= " AND {$this->_aclWhere} ";
406 }
407 }
408
00be9182 409 public function postProcess() {
6a488035
TO
410
411 $this->beginPostProcess();
412
413 // get the acl clauses built before we assemble the query
414 $this->buildACLClause($this->_aliases['civicrm_contact']);
9d72cede
EM
415 $sql = $this->buildQuery();
416 $rows = $payment = array();
6a488035
TO
417
418 $dao = CRM_Core_DAO::executeQuery($sql);
419
420 // Set pager for the Main Query only which displays basic information
421 $this->setPager();
422 $this->assign('columnHeaders', $this->_columnHeaders);
423
424 while ($dao->fetch()) {
425 $pledgeID = $dao->civicrm_pledge_id;
426 foreach ($this->_columnHeaders as $columnHeadersKey => $columnHeadersValue) {
427 $row = array();
428 if (property_exists($dao, $columnHeadersKey)) {
429 $display[$pledgeID][$columnHeadersKey] = $dao->$columnHeadersKey;
430 }
431 }
432 $pledgeIDArray[] = $pledgeID;
433 }
434
435 // Add Special headers
436 $this->_columnHeaders['scheduled_date'] = array(
437 'type' => CRM_Utils_Type::T_DATE,
438 'title' => 'Next Payment Due',
9d72cede
EM
439 );
440 $this->_columnHeaders['scheduled_amount'] = array(
441 'type' => CRM_Utils_Type::T_MONEY,
442 'title' => 'Next Payment Amount',
443 );
444 $this->_columnHeaders['status_id'] = NULL;
445
446 /*
447 * this is purely about ordering the total paid & balance due fields off to the end
448 * of the table in case custom or address fields cause them to fall in the middle
449 * (arguably the pledge amount should be moved to after these fields too)
450 *
451 */
452 $tableHeaders = array(
453 'civicrm_pledge_payment_total_paid',
21dfd5f5 454 'civicrm_pledge_payment_balance_due',
9d72cede 455 );
6a488035
TO
456
457 foreach ($tableHeaders as $header) {
458 //per above, unset & reset them so they move to the end
9d72cede 459 if (isset($this->_columnHeaders[$header])) {
6a488035
TO
460 $headervalue = $this->_columnHeaders[$header];
461 unset($this->_columnHeaders[$header]);
462 $this->_columnHeaders[$header] = $headervalue;
463 }
464 }
465
466 // To Display Payment Details of pledged amount
467 // for pledge payments In Progress
468 if (!empty($display)) {
a18fb275
SB
469 $statusId = array_keys(CRM_Core_PseudoConstant::accountOptionValues("contribution_status", NULL, " AND v.name IN ('Pending', 'Overdue')"));
470 $statusId = implode(',', $statusId);
d1641c51 471 $select = "payment.pledge_id, payment.scheduled_amount, pledge.contact_id";
6a488035
TO
472 $sqlPayment = "
473 SELECT min(payment.scheduled_date) as scheduled_date,
d1641c51 474 {$select}
6a488035
TO
475
476 FROM civicrm_pledge_payment payment
477 LEFT JOIN civicrm_pledge pledge
478 ON pledge.id = payment.pledge_id
479
a18fb275 480 WHERE payment.status_id IN ({$statusId})
6a488035 481
d1641c51 482 GROUP BY {$select}";
6a488035
TO
483
484 $daoPayment = CRM_Core_DAO::executeQuery($sqlPayment);
485
486 while ($daoPayment->fetch()) {
487 foreach ($pledgeIDArray as $key => $val) {
488 if ($val == $daoPayment->pledge_id) {
489
490 $display[$daoPayment->pledge_id]['scheduled_date'] = $daoPayment->scheduled_date;
491
492 $display[$daoPayment->pledge_id]['scheduled_amount'] = $daoPayment->scheduled_amount;
493 }
494 }
495 }
6a488035
TO
496 }
497
498 // Displaying entire data on the form
499 if (!empty($display)) {
500 foreach ($display as $key => $value) {
501 $row = array();
502 foreach ($this->_columnHeaders as $columnKey => $columnValue) {
503 if (array_key_exists($columnKey, $value)) {
0d8afee2 504 $row[$columnKey] = !empty($value[$columnKey]) ? $value[$columnKey] : '';
6a488035
TO
505 }
506 }
507 $rows[] = $row;
508 }
509 }
510
511 unset($this->_columnHeaders['status_id']);
512 unset($this->_columnHeaders['civicrm_pledge_id']);
513 unset($this->_columnHeaders['civicrm_pledge_contact_id']);
514
515 $this->formatDisplay($rows, FALSE);
516 $this->doTemplateAssignment($rows);
517 $this->endPostProcess($rows);
518 }
519
74cf4551 520 /**
ced9bfed
EM
521 * Alter display of rows.
522 *
523 * Iterate through the rows retrieved via SQL and make changes for display purposes,
524 * such as rendering contacts as links.
525 *
526 * @param array $rows
527 * Rows generated by SQL, with an array for each row.
74cf4551 528 */
00be9182 529 public function alterDisplay(&$rows) {
9d72cede
EM
530 $entryFound = FALSE;
531 $checkList = array();
6a488035
TO
532 $display_flag = $prev_cid = $cid = 0;
533
534 foreach ($rows as $rowNum => $row) {
535 if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
536 // don't repeat contact details if its same as the previous row
537 if (array_key_exists('civicrm_pledge_contact_id', $row)) {
538 if ($cid = $row['civicrm_pledge_contact_id']) {
539 if ($rowNum == 0) {
540 $prev_cid = $cid;
541 }
542 else {
543 if ($prev_cid == $cid) {
544 $display_flag = 1;
545 $prev_cid = $cid;
546 }
547 else {
548 $display_flag = 0;
549 $prev_cid = $cid;
550 }
551 }
552
553 if ($display_flag) {
554 foreach ($row as $colName => $colVal) {
555 if (in_array($colName, $this->_noRepeats)) {
556 unset($rows[$rowNum][$colName]);
557 }
558 }
559 }
560 $entryFound = TRUE;
561 }
562 }
563 }
564
565 // convert display name to links
566 if (array_key_exists('civicrm_contact_sort_name', $row) &&
567 array_key_exists('civicrm_pledge_contact_id', $row)
568 ) {
569 $url = CRM_Utils_System::url("civicrm/contact/view",
570 'reset=1&cid=' . $row['civicrm_pledge_contact_id'],
571 $this->_absoluteUrl
572 );
573 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
574 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
575 $entryFound = TRUE;
576 }
577
9e335308 578 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
579 if ($value = $row['civicrm_pledge_financial_type_id']) {
580 $rows[$rowNum]['civicrm_pledge_financial_type_id'] = CRM_Contribute_PseudoConstant::financialType($value, FALSE);
581 }
582 $entryFound = TRUE;
583 }
584
6a488035
TO
585 //handle status id
586 if (array_key_exists('civicrm_pledge_status_id', $row)) {
587 if ($value = $row['civicrm_pledge_status_id']) {
588 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($value);
589 }
590 $entryFound = TRUE;
591 }
592
2ebf49a4
CD
593 // If using campaigns, convert campaign_id to campaign title
594 if (array_key_exists('civicrm_pledge_campaign_id', $row)) {
595 if ($value = $row['civicrm_pledge_campaign_id']) {
596 $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns[$value];
597 }
598 $entryFound = TRUE;
599 }
600
6a488035
TO
601 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'pledge/detail', 'List all pledge(s) for this ') ? TRUE : $entryFound;
602
603 // skip looking further in rows, if first row itself doesn't
604 // have the column we need
605 if (!$entryFound) {
606 break;
607 }
608 }
609 }
96025800 610
6a488035 611}