3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class is used to retrieve and display a range of
20 * contacts that match the given criteria (specifically for
21 * results of advanced search options.
23 class CRM_Pledge_Selector_Search
extends CRM_Core_Selector_Base
{
26 * This defines two actions- View and Edit.
30 public static $_links = NULL;
33 * We use desc to remind us what that column is, name is used in the tpl
37 public static $_columnHeaders;
40 * Properties of contact we're interested in displaying
44 public static $_properties = [
52 'pledge_next_pay_date',
53 'pledge_next_pay_amount',
54 'pledge_outstanding_amount',
58 'pledge_contribution_page_id',
59 'pledge_financial_type',
65 * Are we restricting ourselves to a single contact
69 protected $_single = FALSE;
72 * Are we restricting ourselves to a single contact
76 protected $_limit = NULL;
79 * What context are we being invoked from
83 protected $_context = NULL;
86 * QueryParams is the array returned by exportValues called on
87 * the HTML_QuickForm_Controller for that page.
94 * Represent the type of selector
101 * The additional clause that we restrict the search with
105 protected $_additionalClause = NULL;
117 * @param array $queryParams
118 * Array of parameters for query.
119 * @param \const|int $action - action of search basic or advanced.
120 * @param string $additionalClause
121 * If the caller wants to further restrict the search (used in participations).
122 * @param bool $single
123 * Are we dealing only with one contact?.
125 * How many signers do we want returned.
127 * @param string $context
129 * @return \CRM_Pledge_Selector_Search
131 public function __construct(
133 $action = CRM_Core_Action
::NONE
,
134 $additionalClause = NULL,
139 // submitted form values
140 $this->_queryParams
= &$queryParams;
142 $this->_single
= $single;
143 $this->_limit
= $limit;
144 $this->_context
= $context;
146 $this->_additionalClause
= $additionalClause;
149 $this->_action
= $action;
151 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
152 CRM_Contact_BAO_Query
::MODE_PLEDGE
155 $this->_query
->_distinctComponentClause
= "civicrm_pledge.id";
156 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_pledge.id ";
160 * This method returns the links that are given for each search row.
162 * Currently the links added for each row are:
168 public static function &links() {
169 $args = func_get_args();
170 $hideOption = CRM_Utils_Array
::value(0, $args);
171 $key = CRM_Utils_Array
::value(1, $args);
173 $extraParams = ($key) ?
"&key={$key}" : NULL;
175 $cancelExtra = ts('Cancelling this pledge will also cancel any scheduled (and not completed) pledge payments.') . ' ' . ts('This action cannot be undone.') . ' ' . ts('Do you want to continue?');
177 CRM_Core_Action
::VIEW
=> [
178 'name' => ts('View'),
179 'url' => 'civicrm/contact/view/pledge',
180 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=pledge' . $extraParams,
181 'title' => ts('View Pledge'),
183 CRM_Core_Action
::UPDATE
=> [
184 'name' => ts('Edit'),
185 'url' => 'civicrm/contact/view/pledge',
186 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
187 'title' => ts('Edit Pledge'),
189 CRM_Core_Action
::DETACH
=> [
190 'name' => ts('Cancel'),
191 'url' => 'civicrm/contact/view/pledge',
192 'qs' => 'reset=1&action=detach&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
193 'extra' => 'onclick = "return confirm(\'' . $cancelExtra . '\');"',
194 'title' => ts('Cancel Pledge'),
196 CRM_Core_Action
::DELETE
=> [
197 'name' => ts('Delete'),
198 'url' => 'civicrm/contact/view/pledge',
199 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
200 'title' => ts('Delete Pledge'),
204 if (in_array('Cancel', $hideOption)) {
205 unset(self
::$_links[CRM_Core_Action
::DETACH
]);
208 return self
::$_links;
212 * Getter for array of the parameters required for creating pager.
215 * @param array $params
217 public function getPagerParams($action, &$params) {
218 $params['status'] = ts('Pledge') . ' %%StatusMessage%%';
219 $params['csvString'] = NULL;
221 $params['rowCount'] = $this->_limit
;
224 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
227 $params['buttonTop'] = 'PagerTopButton';
228 $params['buttonBottom'] = 'PagerBottomButton';
232 * Returns total number of rows for the query.
237 * Total number of rows
239 public function getTotalCount($action) {
240 return $this->_query
->searchQuery(0, 0, NULL,
244 $this->_additionalClause
249 * Returns all the rows in the given offset and rowCount.
251 * @param string $action
252 * The action being performed.
254 * The row number to start from.
255 * @param int $rowCount
256 * The number of rows to return.
257 * @param string $sort
258 * The sql string that describes the sort order.
259 * @param string $output
260 * What should the result set include (web/email/csv).
263 * the total number of rows for this action
265 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
266 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
270 $this->_additionalClause
273 // process the result of the query
276 // get all pledge status
277 $pledgeStatuses = CRM_Pledge_BAO_Pledge
::buildOptions('status_id');
279 // get all campaigns.
280 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
282 // CRM-4418 check for view, edit and delete
283 $permissions = [CRM_Core_Permission
::VIEW
];
284 if (CRM_Core_Permission
::check('edit pledges')) {
285 $permissions[] = CRM_Core_Permission
::EDIT
;
287 if (CRM_Core_Permission
::check('delete in CiviPledge')) {
288 $permissions[] = CRM_Core_Permission
::DELETE
;
290 $mask = CRM_Core_Action
::mask($permissions);
292 while ($result->fetch()) {
294 // the columns we are interested in
295 foreach (self
::$_properties as $property) {
296 if (isset($result->$property)) {
297 $row[$property] = $result->$property;
301 // carry campaign on selectors.
302 $row['campaign'] = CRM_Utils_Array
::value($result->pledge_campaign_id
, $allCampaigns);
303 $row['campaign_id'] = $result->pledge_campaign_id
;
305 // add pledge status name
306 if (!empty($row['pledge_status_id'])) {
307 $row['pledge_status_name'] = CRM_Utils_Array
::value($row['pledge_status_id'],
311 // append (test) to status label
312 if (!empty($row['pledge_is_test'])) {
313 $row['pledge_status'] = CRM_Core_TestEntity
::appendTestText($row['pledge_status']);
317 if (CRM_Utils_Array
::key('Cancelled', $row) ||
318 CRM_Utils_Array
::key('Completed', $row)
320 $hideOption[] = 'Cancel';
323 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->pledge_id
;
325 $row['action'] = CRM_Core_Action
::formLink(self
::links($hideOption, $this->_key
),
328 'id' => $result->pledge_id
,
329 'cid' => $result->contact_id
,
330 'cxt' => $this->_context
,
334 'pledge.selector.row',
339 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
347 * Get qill (display what was searched on).
351 public function getQILL() {
352 return $this->_query
->qill();
356 * Returns the column headers as an array of tuples.
358 * Keys are name, sortName, key to the sort array
360 * @param string $action
361 * The action being performed.
362 * @param string $output
363 * What should the result set include (web/email/csv).
366 * the column headers that need to be displayed
368 public function &getColumnHeaders($action = NULL, $output = NULL) {
369 if (!isset(self
::$_columnHeaders)) {
370 self
::$_columnHeaders = [
372 'name' => ts('Pledged'),
373 'sort' => 'pledge_amount',
374 'direction' => CRM_Utils_Sort
::DONTCARE
,
377 'name' => ts('Total Paid'),
378 'sort' => 'pledge_total_paid',
379 'direction' => CRM_Utils_Sort
::DONTCARE
,
382 'name' => ts('Balance'),
385 'name' => ts('Pledged For'),
386 'sort' => 'pledge_financial_type',
387 'direction' => CRM_Utils_Sort
::DONTCARE
,
390 'name' => ts('Pledge Made'),
391 'sort' => 'pledge_create_date',
392 'direction' => CRM_Utils_Sort
::DESCENDING
,
395 'name' => ts('Next Pay Date'),
396 'sort' => 'pledge_next_pay_date',
397 'direction' => CRM_Utils_Sort
::DONTCARE
,
400 'name' => ts('Next Amount'),
401 'sort' => 'pledge_next_pay_amount',
402 'direction' => CRM_Utils_Sort
::DONTCARE
,
405 'name' => ts('Status'),
406 'sort' => 'pledge_status',
407 'direction' => CRM_Utils_Sort
::DONTCARE
,
409 ['desc' => ts('Actions')],
412 if (!$this->_single
) {
414 ['desc' => ts('Contact ID')],
416 'name' => ts('Name'),
417 'sort' => 'sort_name',
418 'direction' => CRM_Utils_Sort
::DONTCARE
,
422 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
425 return self
::$_columnHeaders;
429 * Get sql query string.
433 public function &getQuery() {
434 return $this->_query
;
438 * Name of export file.
440 * @param string $output
446 public function getExportFileName($output = 'csv') {
447 return ts('Pledge Search');