3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Pledge_Selector_Search
extends CRM_Core_Selector_Base
{
45 * This defines two actions- View and Edit.
50 static $_links = NULL;
53 * we use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array(
73 'pledge_next_pay_date',
74 'pledge_next_pay_amount',
75 'pledge_outstanding_amount',
79 'pledge_contribution_page_id',
80 'pledge_financial_type',
86 * are we restricting ourselves to a single contact
91 protected $_single = FALSE;
94 * are we restricting ourselves to a single contact
99 protected $_limit = NULL;
102 * what context are we being invoked from
107 protected $_context = NULL;
110 * queryParams is the array returned by exportValues called on
111 * the HTML_QuickForm_Controller for that page.
116 public $_queryParams;
119 * represent the type of selector
127 * The additional clause that we restrict the search with
131 protected $_additionalClause = NULL;
143 * @param array $queryParams array of parameters for query
144 * @param \const|int $action - action of search basic or advanced.
145 * @param string $additionalClause if the caller wants to further restrict the search (used in participations)
146 * @param boolean $single are we dealing only with one contact?
147 * @param int $limit how many signers do we want returned
149 * @param string $context
151 * @return \CRM_Pledge_Selector_Search
154 function __construct(&$queryParams,
155 $action = CRM_Core_Action
::NONE
,
156 $additionalClause = NULL,
161 // submitted form values
162 $this->_queryParams
= &$queryParams;
164 $this->_single
= $single;
165 $this->_limit
= $limit;
166 $this->_context
= $context;
168 $this->_additionalClause
= $additionalClause;
171 $this->_action
= $action;
173 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
174 CRM_Contact_BAO_Query
::MODE_PLEDGE
177 $this->_query
->_distinctComponentClause
= "civicrm_pledge.id";
178 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_pledge.id ";
183 * This method returns the links that are given for each search row.
184 * currently the links added for each row are
193 static function &links() {
194 $args = func_get_args();
195 $hideOption = CRM_Utils_Array
::value(0, $args);
196 $key = CRM_Utils_Array
::value(1, $args);
198 $extraParams = ($key) ?
"&key={$key}" : NULL;
200 $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?');
201 self
::$_links = array(
202 CRM_Core_Action
::VIEW
=> array(
203 'name' => ts('View'),
204 'url' => 'civicrm/contact/view/pledge',
205 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=pledge' . $extraParams,
206 'title' => ts('View Pledge'),
208 CRM_Core_Action
::UPDATE
=> array(
209 'name' => ts('Edit'),
210 'url' => 'civicrm/contact/view/pledge',
211 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
212 'title' => ts('Edit Pledge'),
214 CRM_Core_Action
::DETACH
=> array(
215 'name' => ts('Cancel'),
216 'url' => 'civicrm/contact/view/pledge',
217 'qs' => 'reset=1&action=detach&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
218 'extra' => 'onclick = "return confirm(\'' . $cancelExtra . '\');"',
219 'title' => ts('Cancel Pledge'),
221 CRM_Core_Action
::DELETE
=> array(
222 'name' => ts('Delete'),
223 'url' => 'civicrm/contact/view/pledge',
224 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
225 'title' => ts('Delete Pledge'),
230 if (in_array('Cancel', $hideOption)) {
231 unset(self
::$_links[CRM_Core_Action
::DETACH
]);
234 return self
::$_links;
239 * getter for array of the parameters required for creating pager.
247 function getPagerParams($action, &$params) {
248 $params['status'] = ts('Pledge') . ' %%StatusMessage%%';
249 $params['csvString'] = NULL;
251 $params['rowCount'] = $this->_limit
;
254 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
257 $params['buttonTop'] = 'PagerTopButton';
258 $params['buttonBottom'] = 'PagerBottomButton';
263 * Returns total number of rows for the query.
267 * @return int Total number of rows
270 function getTotalCount($action) {
271 return $this->_query
->searchQuery(0, 0, NULL,
275 $this->_additionalClause
280 * returns all the rows in the given offset and rowCount
282 * @param enum $action the action being performed
283 * @param int $offset the row number to start from
284 * @param int $rowCount the number of rows to return
285 * @param string $sort the sql string that describes the sort order
286 * @param enum $output what should the result set include (web/email/csv)
288 * @return int the total number of rows for this action
290 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
291 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
295 $this->_additionalClause
298 // process the result of the query
301 // get all pledge status
302 $pledgeStatuses = CRM_Core_OptionGroup
::values('contribution_status',
303 FALSE, FALSE, FALSE, NULL, 'name', FALSE
307 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
309 //4418 check for view, edit and delete
310 $permissions = array(CRM_Core_Permission
::VIEW
);
311 if (CRM_Core_Permission
::check('edit pledges')) {
312 $permissions[] = CRM_Core_Permission
::EDIT
;
314 if (CRM_Core_Permission
::check('delete in CiviPledge')) {
315 $permissions[] = CRM_Core_Permission
::DELETE
;
317 $mask = CRM_Core_Action
::mask($permissions);
319 while ($result->fetch()) {
321 // the columns we are interested in
322 foreach (self
::$_properties as $property) {
323 if (isset($result->$property)) {
324 $row[$property] = $result->$property;
328 //carry campaign on selectors.
329 $row['campaign'] = CRM_Utils_Array
::value($result->pledge_campaign_id
, $allCampaigns);
330 $row['campaign_id'] = $result->pledge_campaign_id
;
332 // add pledge status name
333 $row['pledge_status_name'] = CRM_Utils_Array
::value($row['pledge_status_id'],
336 // append (test) to status label
337 if (!empty($row['pledge_is_test'])) {
338 $row['pledge_status'] .= ' (test)';
341 $hideOption = array();
342 if (CRM_Utils_Array
::key('Cancelled', $row) ||
343 CRM_Utils_Array
::key('Completed', $row)
345 $hideOption[] = 'Cancel';
348 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->pledge_id
;
350 $row['action'] = CRM_Core_Action
::formLink(self
::links($hideOption, $this->_key
),
353 'id' => $result->pledge_id
,
354 'cid' => $result->contact_id
,
355 'cxt' => $this->_context
,
359 'pledge.selector.row',
365 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
366 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
375 * @return array $qill which contains an array of strings
379 // the current internationalisation is bad, but should more or less work
380 // for most of "European" languages
381 public function getQILL() {
382 return $this->_query
->qill();
386 * returns the column headers as an array of tuples:
387 * (name, sortName (key to the sort array))
389 * @param string $action the action being performed
390 * @param enum $output what should the result set include (web/email/csv)
392 * @return array the column headers that need to be displayed
395 public function &getColumnHeaders($action = NULL, $output = NULL) {
396 if (!isset(self
::$_columnHeaders)) {
397 self
::$_columnHeaders = array(
399 'name' => ts('Pledged'),
400 'sort' => 'pledge_amount',
401 'direction' => CRM_Utils_Sort
::DONTCARE
,
404 'name' => ts('Total Paid'),
405 'sort' => 'pledge_total_paid',
406 'direction' => CRM_Utils_Sort
::DONTCARE
,
409 'name' => ts('Balance'),
412 'name' => ts('Pledged For'),
413 'sort' => 'pledge_financial_type',
414 'direction' => CRM_Utils_Sort
::DONTCARE
,
417 'name' => ts('Pledge Made'),
418 'sort' => 'pledge_create_date',
419 'direction' => CRM_Utils_Sort
::DESCENDING
,
422 'name' => ts('Next Pay Date'),
423 'sort' => 'pledge_next_pay_date',
424 'direction' => CRM_Utils_Sort
::DONTCARE
,
427 'name' => ts('Next Amount'),
428 'sort' => 'pledge_next_pay_amount',
429 'direction' => CRM_Utils_Sort
::DONTCARE
,
432 'name' => ts('Status'),
433 'sort' => 'pledge_status',
434 'direction' => CRM_Utils_Sort
::DONTCARE
,
436 array('desc' => ts('Actions')),
439 if (!$this->_single
) {
441 array('desc' => ts('Contact ID')),
443 'name' => ts('Name'),
444 'sort' => 'sort_name',
445 'direction' => CRM_Utils_Sort
::DONTCARE
,
449 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
452 return self
::$_columnHeaders;
458 function &getQuery() {
459 return $this->_query
;
463 * name of export file.
465 * @param string $output type of output
467 * @return string name of the file
469 function getExportFileName($output = 'csv') {
470 return ts('Pledge Search');