Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
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 | /** | |
6a488035 | 29 | * @package CRM |
6b83d5bd | 30 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
31 | */ |
32 | ||
33 | /** | |
2e80df5b | 34 | * Class to render contribution search results. |
6a488035 TO |
35 | */ |
36 | class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements CRM_Core_Selector_API { | |
37 | ||
38 | /** | |
2e80df5b | 39 | * Array of action links. |
6a488035 TO |
40 | * |
41 | * @var array | |
6a488035 | 42 | */ |
1330f57a | 43 | public static $_links = NULL; |
6a488035 TO |
44 | |
45 | /** | |
100fef9d | 46 | * We use desc to remind us what that column is, name is used in the tpl |
6a488035 TO |
47 | * |
48 | * @var array | |
6a488035 | 49 | */ |
1330f57a | 50 | public static $_columnHeaders; |
6a488035 TO |
51 | |
52 | /** | |
53 | * Properties of contact we're interested in displaying | |
54 | * @var array | |
6a488035 | 55 | */ |
1330f57a | 56 | public static $_properties = [ |
6a488035 TO |
57 | 'contact_id', |
58 | 'contribution_id', | |
59 | 'contact_type', | |
60 | 'sort_name', | |
61 | 'amount_level', | |
62 | 'total_amount', | |
e777c2b6 | 63 | 'financial_type', |
6a488035 TO |
64 | 'contribution_source', |
65 | 'receive_date', | |
66 | 'thankyou_date', | |
67 | 'contribution_status_id', | |
68 | 'contribution_status', | |
69 | 'cancel_date', | |
70 | 'product_name', | |
71 | 'is_test', | |
72 | 'contribution_recur_id', | |
73 | 'receipt_date', | |
74 | 'membership_id', | |
75 | 'currency', | |
76 | 'contribution_campaign_id', | |
36bf52ef | 77 | 'contribution_soft_credit_name', |
d4e2b978 | 78 | 'contribution_soft_credit_contact_id', |
36bf52ef DS |
79 | 'contribution_soft_credit_amount', |
80 | 'contribution_soft_credit_type', | |
be2fb01f | 81 | ]; |
6a488035 TO |
82 | |
83 | /** | |
100fef9d | 84 | * Are we restricting ourselves to a single contact |
6a488035 | 85 | * |
b67daa72 | 86 | * @var bool |
6a488035 TO |
87 | */ |
88 | protected $_single = FALSE; | |
89 | ||
90 | /** | |
100fef9d | 91 | * Are we restricting ourselves to a single contact |
6a488035 | 92 | * |
b67daa72 | 93 | * @var bool |
6a488035 TO |
94 | */ |
95 | protected $_limit = NULL; | |
96 | ||
97 | /** | |
100fef9d | 98 | * What context are we being invoked from |
6a488035 | 99 | * |
6a488035 TO |
100 | * @var string |
101 | */ | |
102 | protected $_context = NULL; | |
103 | ||
104 | /** | |
100fef9d | 105 | * What component context are we being invoked from |
6a488035 | 106 | * |
6a488035 TO |
107 | * @var string |
108 | */ | |
109 | protected $_compContext = NULL; | |
110 | ||
111 | /** | |
100fef9d | 112 | * QueryParams is the array returned by exportValues called on |
6a488035 TO |
113 | * the HTML_QuickForm_Controller for that page. |
114 | * | |
115 | * @var array | |
6a488035 TO |
116 | */ |
117 | public $_queryParams; | |
118 | ||
119 | /** | |
100fef9d | 120 | * Represent the type of selector |
6a488035 TO |
121 | * |
122 | * @var int | |
6a488035 TO |
123 | */ |
124 | protected $_action; | |
125 | ||
126 | /** | |
127 | * The additional clause that we restrict the search with | |
128 | * | |
129 | * @var string | |
130 | */ | |
131 | protected $_contributionClause = NULL; | |
132 | ||
133 | /** | |
134 | * The query object | |
135 | * | |
136 | * @var string | |
137 | */ | |
138 | protected $_query; | |
139 | ||
36bf52ef DS |
140 | protected $_includeSoftCredits = FALSE; |
141 | ||
6a488035 | 142 | /** |
fe482240 | 143 | * Class constructor. |
6a488035 | 144 | * |
014c4014 TO |
145 | * @param array $queryParams |
146 | * Array of parameters for query. | |
da6b46f4 | 147 | * @param \const|int $action - action of search basic or advanced. |
014c4014 TO |
148 | * @param string $contributionClause |
149 | * If the caller wants to further restrict the search (used in contributions). | |
150 | * @param bool $single | |
151 | * Are we dealing only with one contact?. | |
152 | * @param int $limit | |
153 | * How many contributions do we want returned. | |
6a488035 | 154 | * |
da6b46f4 EM |
155 | * @param string $context |
156 | * @param null $compContext | |
157 | * | |
158 | * @return \CRM_Contribute_Selector_Search | |
6a488035 | 159 | */ |
8d7a9d07 | 160 | public function __construct( |
a13f3d8c | 161 | &$queryParams, |
874c9be7 | 162 | $action = CRM_Core_Action::NONE, |
6a488035 | 163 | $contributionClause = NULL, |
874c9be7 TO |
164 | $single = FALSE, |
165 | $limit = NULL, | |
166 | $context = 'search', | |
167 | $compContext = NULL | |
6a488035 TO |
168 | ) { |
169 | ||
170 | // submitted form values | |
171 | $this->_queryParams = &$queryParams; | |
172 | ||
353ffa53 TO |
173 | $this->_single = $single; |
174 | $this->_limit = $limit; | |
175 | $this->_context = $context; | |
6a488035 TO |
176 | $this->_compContext = $compContext; |
177 | ||
178 | $this->_contributionClause = $contributionClause; | |
179 | ||
180 | // type of selector | |
181 | $this->_action = $action; | |
b4bb60fc | 182 | $returnProperties = CRM_Contribute_BAO_Query::selectorReturnProperties($this->_queryParams); |
d4e2b978 | 183 | $this->_includeSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->_queryParams); |
6822e118 | 184 | $this->_queryParams[] = ['contribution_id', '!=', 0, 0, 0]; |
36bf52ef DS |
185 | $this->_query = new CRM_Contact_BAO_Query( |
186 | $this->_queryParams, | |
c5c270ef | 187 | $returnProperties, |
6a488035 TO |
188 | NULL, FALSE, FALSE, |
189 | CRM_Contact_BAO_Query::MODE_CONTRIBUTE | |
190 | ); | |
17caeafe | 191 | // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this |
192 | // can we remove? if not why not? | |
3dbf477c DS |
193 | if ($this->_includeSoftCredits) { |
194 | $this->_query->_rowCountClause = " count(civicrm_contribution.id)"; | |
ed81a415 | 195 | $this->_query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id "; |
0db6c3e1 TO |
196 | } |
197 | else { | |
3dbf477c DS |
198 | $this->_query->_distinctComponentClause = " civicrm_contribution.id"; |
199 | $this->_query->_groupByComponentClause = " GROUP BY civicrm_contribution.id "; | |
200 | } | |
6a488035 | 201 | } |
6a488035 TO |
202 | |
203 | /** | |
204 | * This method returns the links that are given for each search row. | |
205 | * currently the links added for each row are | |
206 | * | |
207 | * - View | |
208 | * - Edit | |
209 | * | |
100fef9d | 210 | * @param int $componentId |
fd31fa4c EM |
211 | * @param null $componentAction |
212 | * @param null $key | |
213 | * @param null $compContext | |
214 | * | |
6a488035 | 215 | * @return array |
6a488035 | 216 | */ |
00be9182 | 217 | public static function &links($componentId = NULL, $componentAction = NULL, $key = NULL, $compContext = NULL) { |
6a488035 TO |
218 | $extraParams = NULL; |
219 | if ($componentId) { | |
220 | $extraParams = "&compId={$componentId}&compAction={$componentAction}"; | |
221 | } | |
222 | if ($compContext) { | |
223 | $extraParams .= "&compContext={$compContext}"; | |
224 | } | |
225 | if ($key) { | |
226 | $extraParams .= "&key={$key}"; | |
227 | } | |
228 | ||
229 | if (!(self::$_links)) { | |
be2fb01f CW |
230 | self::$_links = [ |
231 | CRM_Core_Action::VIEW => [ | |
6a488035 TO |
232 | 'name' => ts('View'), |
233 | 'url' => 'civicrm/contact/view/contribution', | |
234 | 'qs' => "reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=contribute{$extraParams}", | |
235 | 'title' => ts('View Contribution'), | |
be2fb01f CW |
236 | ], |
237 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
238 | 'name' => ts('Edit'), |
239 | 'url' => 'civicrm/contact/view/contribution', | |
240 | 'qs' => "reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}", | |
241 | 'title' => ts('Edit Contribution'), | |
be2fb01f CW |
242 | ], |
243 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
244 | 'name' => ts('Delete'), |
245 | 'url' => 'civicrm/contact/view/contribution', | |
246 | 'qs' => "reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}", | |
247 | 'title' => ts('Delete Contribution'), | |
be2fb01f CW |
248 | ], |
249 | ]; | |
6a488035 TO |
250 | } |
251 | return self::$_links; | |
252 | } | |
6a488035 TO |
253 | |
254 | /** | |
100fef9d | 255 | * Getter for array of the parameters required for creating pager. |
6a488035 | 256 | * |
da6b46f4 | 257 | * @param $action |
c490a46a | 258 | * @param array $params |
6a488035 | 259 | */ |
00be9182 | 260 | public function getPagerParams($action, &$params) { |
6a488035 TO |
261 | $params['status'] = ts('Contribution') . ' %%StatusMessage%%'; |
262 | $params['csvString'] = NULL; | |
263 | if ($this->_limit) { | |
264 | $params['rowCount'] = $this->_limit; | |
265 | } | |
266 | else { | |
267 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
268 | } | |
269 | ||
270 | $params['buttonTop'] = 'PagerTopButton'; | |
271 | $params['buttonBottom'] = 'PagerBottomButton'; | |
272 | } | |
6a488035 TO |
273 | |
274 | /** | |
275 | * Returns total number of rows for the query. | |
276 | * | |
7fe37828 | 277 | * @param string $action |
6a488035 | 278 | * |
a6c01b45 CW |
279 | * @return int |
280 | * Total number of rows | |
6a488035 | 281 | */ |
00be9182 | 282 | public function getTotalCount($action) { |
6a488035 TO |
283 | return $this->_query->searchQuery(0, 0, NULL, |
284 | TRUE, FALSE, | |
285 | FALSE, FALSE, | |
286 | FALSE, | |
287 | $this->_contributionClause | |
288 | ); | |
289 | } | |
290 | ||
291 | /** | |
fe482240 | 292 | * Returns all the rows in the given offset and rowCount. |
6a488035 | 293 | * |
3f8d2862 | 294 | * @param string $action |
014c4014 TO |
295 | * The action being performed. |
296 | * @param int $offset | |
297 | * The row number to start from. | |
298 | * @param int $rowCount | |
299 | * The number of rows to return. | |
300 | * @param string $sort | |
301 | * The sql string that describes the sort order. | |
3f8d2862 | 302 | * @param string $output |
014c4014 | 303 | * What should the result set include (web/email/csv). |
6a488035 | 304 | * |
a6c01b45 CW |
305 | * @return int |
306 | * the total number of rows for this action | |
6a488035 | 307 | */ |
00be9182 | 308 | public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { |
4f3846df DS |
309 | if ($this->_includeSoftCredits) { |
310 | // especial sort order when rows include soft credits | |
8f7c2652 | 311 | $sort = $sort->orderBy() . ", civicrm_contribution.id, civicrm_contribution_soft.id"; |
4f3846df | 312 | } |
6a488035 TO |
313 | $result = $this->_query->searchQuery($offset, $rowCount, $sort, |
314 | FALSE, FALSE, | |
315 | FALSE, FALSE, | |
316 | FALSE, | |
317 | $this->_contributionClause | |
318 | ); | |
319 | // process the result of the query | |
be2fb01f | 320 | $rows = []; |
6a488035 TO |
321 | |
322 | //CRM-4418 check for view/edit/delete | |
be2fb01f | 323 | $permissions = [CRM_Core_Permission::VIEW]; |
6a488035 TO |
324 | if (CRM_Core_Permission::check('edit contributions')) { |
325 | $permissions[] = CRM_Core_Permission::EDIT; | |
326 | } | |
327 | if (CRM_Core_Permission::check('delete in CiviContribute')) { | |
328 | $permissions[] = CRM_Core_Permission::DELETE; | |
329 | } | |
330 | $mask = CRM_Core_Action::mask($permissions); | |
331 | ||
332 | $qfKey = $this->_key; | |
333 | $componentId = $componentContext = NULL; | |
334 | if ($this->_context != 'contribute') { | |
98df3f98 | 335 | // @todo explain the significance of context & why we do not get these i that context. |
a3d827a7 CW |
336 | $qfKey = CRM_Utils_Request::retrieve('key', 'String'); |
337 | $componentId = CRM_Utils_Request::retrieve('id', 'Positive'); | |
338 | $componentAction = CRM_Utils_Request::retrieve('action', 'String'); | |
339 | $componentContext = CRM_Utils_Request::retrieve('compContext', 'String'); | |
6a488035 TO |
340 | |
341 | if (!$componentContext && | |
342 | $this->_compContext | |
343 | ) { | |
98df3f98 | 344 | // @todo explain when this condition might occur. |
6a488035 TO |
345 | $componentContext = $this->_compContext; |
346 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST'); | |
347 | } | |
98df3f98 | 348 | // CRM-17628 for some reason qfKey is not always set when searching from contribution search. |
349 | // as a result if the edit link is opened using right-click + open in new tab | |
350 | // then the browser is not returned to the search results on save. | |
351 | // This is an effort to getting the qfKey without, sadly, understanding the intent of those who came before me. | |
352 | if (empty($qfKey)) { | |
353 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST'); | |
354 | } | |
6a488035 TO |
355 | } |
356 | ||
357 | // get all contribution status | |
358 | $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', | |
359 | FALSE, FALSE, FALSE, NULL, 'name', FALSE | |
360 | ); | |
361 | ||
362 | //get all campaigns. | |
363 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
364 | ||
874c9be7 | 365 | while ($result->fetch()) { |
9d5c7f14 | 366 | $this->_query->convertToPseudoNames($result); |
b501fa94 E |
367 | $links = self::links($componentId, |
368 | $componentAction, | |
369 | $qfKey, | |
370 | $componentContext | |
371 | ); | |
a964bc8e | 372 | $checkLineItem = FALSE; |
be2fb01f | 373 | $row = []; |
a964bc8e | 374 | // Now check for lineItems |
4323dc6c PN |
375 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { |
376 | $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id); | |
40c655aa | 377 | foreach ($lineItems as $items) { |
4323dc6c PN |
378 | if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { |
379 | $checkLineItem = TRUE; | |
380 | break; | |
381 | } | |
382 | if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { | |
383 | unset($links[CRM_Core_Action::UPDATE]); | |
384 | } | |
385 | if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { | |
386 | unset($links[CRM_Core_Action::DELETE]); | |
387 | } | |
a964bc8e | 388 | } |
4323dc6c PN |
389 | if ($checkLineItem) { |
390 | continue; | |
391 | } | |
392 | if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { | |
2d0b158e | 393 | unset($links[CRM_Core_Action::UPDATE]); |
48da6700 | 394 | } |
4323dc6c | 395 | if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { |
2d0b158e | 396 | unset($links[CRM_Core_Action::DELETE]); |
48da6700 | 397 | } |
a964bc8e | 398 | } |
6a488035 TO |
399 | // the columns we are interested in |
400 | foreach (self::$_properties as $property) { | |
401 | if (property_exists($result, $property)) { | |
402 | $row[$property] = $result->$property; | |
403 | } | |
404 | } | |
405 | ||
406 | //carry campaign on selectors. | |
5deb2f24 | 407 | // @todo - I can't find any evidence that 'carrying' the campaign on selectors actually |
408 | // results in it being displayed anywhere so why do we do this??? | |
6a488035 TO |
409 | $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns); |
410 | $row['campaign_id'] = $result->contribution_campaign_id; | |
411 | ||
412 | // add contribution status name | |
413 | $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], | |
414 | $contributionStatuses | |
415 | ); | |
416 | ||
685dc433 | 417 | $isPayLater = FALSE; |
6a488035 | 418 | if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { |
685dc433 | 419 | $isPayLater = TRUE; |
6a488035 | 420 | $row['contribution_status'] .= ' (' . ts('Pay Later') . ')'; |
be2fb01f | 421 | $links[CRM_Core_Action::ADD] = [ |
b9a90a9c | 422 | 'name' => ts('Pay with Credit Card'), |
423 | 'url' => 'civicrm/contact/view/contribution', | |
424 | 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&mode=live', | |
425 | 'title' => ts('Pay with Credit Card'), | |
be2fb01f | 426 | ]; |
6a488035 TO |
427 | } |
428 | elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { | |
429 | $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')'; | |
430 | } | |
431 | ||
432 | if ($row['is_test']) { | |
e777c2b6 | 433 | $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')'; |
6a488035 TO |
434 | } |
435 | ||
436 | $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id; | |
437 | ||
be2fb01f | 438 | $actions = [ |
6a488035 TO |
439 | 'id' => $result->contribution_id, |
440 | 'cid' => $result->contact_id, | |
441 | 'cxt' => $this->_context, | |
be2fb01f | 442 | ]; |
c5c270ef | 443 | |
be2fb01f | 444 | if (in_array($row['contribution_status_name'], ['Partially paid', 'Pending refund']) || $isPayLater) { |
8e50d640 PN |
445 | $buttonName = ts('Record Payment'); |
446 | if ($row['contribution_status_name'] == 'Pending refund') { | |
447 | $buttonName = ts('Record Refund'); | |
448 | } | |
059326f3 | 449 | elseif (CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) { |
be2fb01f | 450 | $links[CRM_Core_Action::BASIC] = [ |
14490e83 PN |
451 | 'name' => ts('Submit Credit Card payment'), |
452 | 'url' => 'civicrm/payment/add', | |
453 | 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=contribution&mode=live', | |
454 | 'title' => ts('Submit Credit Card payment'), | |
be2fb01f | 455 | ]; |
14490e83 | 456 | } |
be2fb01f | 457 | $links[CRM_Core_Action::ADD] = [ |
8e50d640 | 458 | 'name' => $buttonName, |
685dc433 | 459 | 'url' => 'civicrm/payment', |
8e50d640 PN |
460 | 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=contribution', |
461 | 'title' => $buttonName, | |
be2fb01f | 462 | ]; |
c5c270ef | 463 | } |
6a488035 | 464 | |
e777c2b6 | 465 | $row['action'] = CRM_Core_Action::formLink( |
b501fa94 | 466 | $links, |
87dab4a4 AH |
467 | $mask, $actions, |
468 | ts('more'), | |
469 | FALSE, | |
470 | 'contribution.selector.row', | |
471 | 'Contribution', | |
472 | $result->contribution_id | |
6a488035 TO |
473 | ); |
474 | ||
874c9be7 | 475 | $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id |
6a488035 TO |
476 | ); |
477 | ||
a7488080 | 478 | if (!empty($row['amount_level'])) { |
6a488035 TO |
479 | CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']); |
480 | } | |
481 | ||
482 | $rows[] = $row; | |
483 | } | |
484 | ||
485 | return $rows; | |
486 | } | |
487 | ||
488 | /** | |
1054415f | 489 | * @inheritDoc |
6a488035 | 490 | */ |
6a488035 TO |
491 | public function getQILL() { |
492 | return $this->_query->qill(); | |
493 | } | |
494 | ||
495 | /** | |
100fef9d | 496 | * Returns the column headers as an array of tuples: |
6a488035 TO |
497 | * (name, sortName (key to the sort array)) |
498 | * | |
014c4014 TO |
499 | * @param string $action |
500 | * The action being performed. | |
3f8d2862 | 501 | * @param string $output |
014c4014 | 502 | * What should the result set include (web/email/csv). |
6a488035 | 503 | * |
a6c01b45 CW |
504 | * @return array |
505 | * the column headers that need to be displayed | |
6a488035 TO |
506 | */ |
507 | public function &getColumnHeaders($action = NULL, $output = NULL) { | |
be2fb01f CW |
508 | $pre = []; |
509 | self::$_columnHeaders = [ | |
510 | [ | |
4f3846df | 511 | 'name' => $this->_includeSoftCredits ? ts('Contribution Amount') : ts('Amount'), |
36bf52ef DS |
512 | 'sort' => 'total_amount', |
513 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
4fb5fcf3 | 514 | 'field_name' => 'total_amount', |
be2fb01f CW |
515 | ], |
516 | ]; | |
4f3846df | 517 | if ($this->_includeSoftCredits) { |
8d7a9d07 CB |
518 | self::$_columnHeaders |
519 | = array_merge( | |
fd31fa4c | 520 | self::$_columnHeaders, |
be2fb01f CW |
521 | [ |
522 | [ | |
4f3846df DS |
523 | 'name' => ts('Soft Credit Amount'), |
524 | 'sort' => 'contribution_soft_credit_amount', | |
4fb5fcf3 | 525 | 'field_name' => 'contribution_soft_credit_amount', |
4f3846df | 526 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
527 | ], |
528 | ] | |
4f3846df DS |
529 | ); |
530 | } | |
8d7a9d07 CB |
531 | self::$_columnHeaders |
532 | = array_merge( | |
fd31fa4c | 533 | self::$_columnHeaders, |
be2fb01f CW |
534 | [ |
535 | [ | |
4f3846df | 536 | 'name' => ts('Type'), |
353ffa53 | 537 | 'sort' => 'financial_type', |
4fb5fcf3 | 538 | 'field_name' => 'financial_type', |
4f3846df | 539 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
540 | ], |
541 | [ | |
4f3846df DS |
542 | 'name' => ts('Source'), |
543 | 'sort' => 'contribution_source', | |
4fb5fcf3 | 544 | 'field_name' => 'contribution_source', |
4f3846df | 545 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
546 | ], |
547 | [ | |
4f3846df DS |
548 | 'name' => ts('Received'), |
549 | 'sort' => 'receive_date', | |
4fb5fcf3 | 550 | 'field_name' => 'receive_date', |
551 | 'type' => 'date', | |
4f3846df | 552 | 'direction' => CRM_Utils_Sort::DESCENDING, |
be2fb01f CW |
553 | ], |
554 | [ | |
4f3846df DS |
555 | 'name' => ts('Thank-you Sent'), |
556 | 'sort' => 'thankyou_date', | |
ca460381 | 557 | 'field_name' => 'thankyou_date', |
4fb5fcf3 | 558 | 'type' => 'date', |
4f3846df | 559 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
560 | ], |
561 | [ | |
4f3846df | 562 | 'name' => ts('Status'), |
33a5a53d | 563 | 'sort' => 'contribution_status', |
4fb5fcf3 | 564 | 'field_name' => 'contribution_status', |
4f3846df | 565 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
566 | ], |
567 | ] | |
4f3846df | 568 | ); |
c8dd6301 | 569 | if (CRM_Contribute_BAO_Query::isSiteHasProducts()) { |
570 | self::$_columnHeaders[] = [ | |
571 | 'name' => ts('Premium'), | |
572 | 'sort' => 'product_name', | |
573 | 'field_name' => 'product_name', | |
574 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
575 | ]; | |
576 | } | |
36bf52ef | 577 | if (!$this->_single) { |
be2fb01f CW |
578 | $pre = [ |
579 | [ | |
36bf52ef DS |
580 | 'name' => ts('Name'), |
581 | 'sort' => 'sort_name', | |
6a488035 | 582 | 'direction' => CRM_Utils_Sort::DONTCARE, |
be2fb01f CW |
583 | ], |
584 | ]; | |
36bf52ef | 585 | } |
d4c0653f | 586 | self::$_columnHeaders = array_merge($pre, self::$_columnHeaders); |
36bf52ef | 587 | if ($this->_includeSoftCredits) { |
006389de | 588 | self::$_columnHeaders = array_merge( |
8d7a9d07 | 589 | self::$_columnHeaders, |
be2fb01f CW |
590 | [ |
591 | [ | |
8d7a9d07 CB |
592 | 'name' => ts('Soft Credit For'), |
593 | 'sort' => 'contribution_soft_credit_name', | |
594 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
be2fb01f CW |
595 | ], |
596 | [ | |
8d7a9d07 CB |
597 | 'name' => ts('Soft Credit Type'), |
598 | 'sort' => 'contribution_soft_credit_type', | |
599 | 'direction' => CRM_Utils_Sort::ASCENDING, | |
be2fb01f CW |
600 | ], |
601 | ] | |
8d7a9d07 | 602 | ); |
6a488035 | 603 | } |
8d7a9d07 CB |
604 | self::$_columnHeaders |
605 | = array_merge( | |
be2fb01f CW |
606 | self::$_columnHeaders, [ |
607 | ['desc' => ts('Actions'), 'type' => 'actions'], | |
608 | ] | |
4f3846df | 609 | ); |
4fb5fcf3 | 610 | foreach (array_keys(self::$_columnHeaders) as $index) { |
611 | // Add weight & space it out a bit to allow headers to be inserted. | |
612 | self::$_columnHeaders[$index]['weight'] = $index * 10; | |
613 | } | |
614 | ||
c740f57b | 615 | CRM_Core_Smarty::singleton()->assign('softCreditColumns', $this->_includeSoftCredits); |
6a488035 TO |
616 | return self::$_columnHeaders; |
617 | } | |
618 | ||
186c9c17 EM |
619 | /** |
620 | * @return mixed | |
621 | */ | |
00be9182 | 622 | public function alphabetQuery() { |
52cda5dc | 623 | return $this->_query->alphabetQuery(); |
6a488035 TO |
624 | } |
625 | ||
186c9c17 EM |
626 | /** |
627 | * @return string | |
628 | */ | |
00be9182 | 629 | public function &getQuery() { |
6a488035 TO |
630 | return $this->_query; |
631 | } | |
632 | ||
633 | /** | |
100fef9d | 634 | * Name of export file. |
6a488035 | 635 | * |
014c4014 TO |
636 | * @param string $output |
637 | * Type of output. | |
6a488035 | 638 | * |
a6c01b45 CW |
639 | * @return string |
640 | * name of the file | |
6a488035 | 641 | */ |
00be9182 | 642 | public function getExportFileName($output = 'csv') { |
6a488035 TO |
643 | return ts('CiviCRM Contribution Search'); |
644 | } | |
645 | ||
186c9c17 EM |
646 | /** |
647 | * @return mixed | |
648 | */ | |
00be9182 | 649 | public function getSummary() { |
6a488035 TO |
650 | return $this->_query->summaryContribution($this->_context); |
651 | } | |
96025800 | 652 | |
6a488035 | 653 | } |