3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
90 protected $_single = FALSE;
93 * Are we restricting ourselves to a single contact
97 protected $_limit = NULL;
100 * What context are we being invoked from
104 protected $_context = NULL;
107 * QueryParams is the array returned by exportValues called on
108 * the HTML_QuickForm_Controller for that page.
112 public $_queryParams;
115 * Represent the type of selector
122 * The additional clause that we restrict the search with
126 protected $_additionalClause = NULL;
138 * @param array $queryParams array of parameters for query
139 * @param \const|int $action - action of search basic or advanced.
140 * @param string $additionalClause if the caller wants to further restrict the search (used in participations)
141 * @param boolean $single are we dealing only with one contact?
142 * @param int $limit how many signers do we want returned
144 * @param string $context
146 * @return \CRM_Pledge_Selector_Search
149 function __construct(&$queryParams,
150 $action = CRM_Core_Action
::NONE
,
151 $additionalClause = NULL,
156 // submitted form values
157 $this->_queryParams
= &$queryParams;
159 $this->_single
= $single;
160 $this->_limit
= $limit;
161 $this->_context
= $context;
163 $this->_additionalClause
= $additionalClause;
166 $this->_action
= $action;
168 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
169 CRM_Contact_BAO_Query
::MODE_PLEDGE
172 $this->_query
->_distinctComponentClause
= "civicrm_pledge.id";
173 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_pledge.id ";
177 * This method returns the links that are given for each search row.
178 * currently the links added for each row are
186 public static function &links() {
187 $args = func_get_args();
188 $hideOption = CRM_Utils_Array
::value(0, $args);
189 $key = CRM_Utils_Array
::value(1, $args);
191 $extraParams = ($key) ?
"&key={$key}" : NULL;
193 $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?');
194 self
::$_links = array(
195 CRM_Core_Action
::VIEW
=> array(
196 'name' => ts('View'),
197 'url' => 'civicrm/contact/view/pledge',
198 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=pledge' . $extraParams,
199 'title' => ts('View Pledge'),
201 CRM_Core_Action
::UPDATE
=> array(
202 'name' => ts('Edit'),
203 'url' => 'civicrm/contact/view/pledge',
204 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
205 'title' => ts('Edit Pledge'),
207 CRM_Core_Action
::DETACH
=> array(
208 'name' => ts('Cancel'),
209 'url' => 'civicrm/contact/view/pledge',
210 'qs' => 'reset=1&action=detach&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
211 'extra' => 'onclick = "return confirm(\'' . $cancelExtra . '\');"',
212 'title' => ts('Cancel Pledge'),
214 CRM_Core_Action
::DELETE
=> array(
215 'name' => ts('Delete'),
216 'url' => 'civicrm/contact/view/pledge',
217 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
218 'title' => ts('Delete Pledge'),
223 if (in_array('Cancel', $hideOption)) {
224 unset(self
::$_links[CRM_Core_Action
::DETACH
]);
227 return self
::$_links;
231 * Getter for array of the parameters required for creating pager.
234 * @param array $params
237 public function getPagerParams($action, &$params) {
238 $params['status'] = ts('Pledge') . ' %%StatusMessage%%';
239 $params['csvString'] = NULL;
241 $params['rowCount'] = $this->_limit
;
244 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
247 $params['buttonTop'] = 'PagerTopButton';
248 $params['buttonBottom'] = 'PagerBottomButton';
252 * Returns total number of rows for the query.
256 * @return int Total number of rows
258 public function getTotalCount($action) {
259 return $this->_query
->searchQuery(0, 0, NULL,
263 $this->_additionalClause
268 * Returns all the rows in the given offset and rowCount
270 * @param enum $action the action being performed
271 * @param int $offset the row number to start from
272 * @param int $rowCount the number of rows to return
273 * @param string $sort the sql string that describes the sort order
274 * @param enum $output what should the result set include (web/email/csv)
276 * @return int the total number of rows for this action
278 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
279 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
283 $this->_additionalClause
286 // process the result of the query
289 // get all pledge status
290 $pledgeStatuses = CRM_Core_OptionGroup
::values('contribution_status',
291 FALSE, FALSE, FALSE, NULL, 'name', FALSE
295 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
297 //4418 check for view, edit and delete
298 $permissions = array(CRM_Core_Permission
::VIEW
);
299 if (CRM_Core_Permission
::check('edit pledges')) {
300 $permissions[] = CRM_Core_Permission
::EDIT
;
302 if (CRM_Core_Permission
::check('delete in CiviPledge')) {
303 $permissions[] = CRM_Core_Permission
::DELETE
;
305 $mask = CRM_Core_Action
::mask($permissions);
307 while ($result->fetch()) {
309 // the columns we are interested in
310 foreach (self
::$_properties as $property) {
311 if (isset($result->$property)) {
312 $row[$property] = $result->$property;
316 //carry campaign on selectors.
317 $row['campaign'] = CRM_Utils_Array
::value($result->pledge_campaign_id
, $allCampaigns);
318 $row['campaign_id'] = $result->pledge_campaign_id
;
320 // add pledge status name
321 $row['pledge_status_name'] = CRM_Utils_Array
::value($row['pledge_status_id'],
324 // append (test) to status label
325 if (!empty($row['pledge_is_test'])) {
326 $row['pledge_status'] .= ' (test)';
329 $hideOption = array();
330 if (CRM_Utils_Array
::key('Cancelled', $row) ||
331 CRM_Utils_Array
::key('Completed', $row)
333 $hideOption[] = 'Cancel';
336 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->pledge_id
;
338 $row['action'] = CRM_Core_Action
::formLink(self
::links($hideOption, $this->_key
),
341 'id' => $result->pledge_id
,
342 'cid' => $result->contact_id
,
343 'cxt' => $this->_context
,
347 'pledge.selector.row',
353 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
354 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
362 * @return array $qill which contains an array of strings
365 // the current internationalisation is bad, but should more or less work
366 // for most of "European" languages
367 public function getQILL() {
368 return $this->_query
->qill();
372 * Returns the column headers as an array of tuples:
373 * (name, sortName (key to the sort array))
375 * @param string $action the action being performed
376 * @param enum $output what should the result set include (web/email/csv)
378 * @return array the column headers that need to be displayed
380 public function &getColumnHeaders($action = NULL, $output = NULL) {
381 if (!isset(self
::$_columnHeaders)) {
382 self
::$_columnHeaders = array(
384 'name' => ts('Pledged'),
385 'sort' => 'pledge_amount',
386 'direction' => CRM_Utils_Sort
::DONTCARE
,
389 'name' => ts('Total Paid'),
390 'sort' => 'pledge_total_paid',
391 'direction' => CRM_Utils_Sort
::DONTCARE
,
394 'name' => ts('Balance'),
397 'name' => ts('Pledged For'),
398 'sort' => 'pledge_financial_type',
399 'direction' => CRM_Utils_Sort
::DONTCARE
,
402 'name' => ts('Pledge Made'),
403 'sort' => 'pledge_create_date',
404 'direction' => CRM_Utils_Sort
::DESCENDING
,
407 'name' => ts('Next Pay Date'),
408 'sort' => 'pledge_next_pay_date',
409 'direction' => CRM_Utils_Sort
::DONTCARE
,
412 'name' => ts('Next Amount'),
413 'sort' => 'pledge_next_pay_amount',
414 'direction' => CRM_Utils_Sort
::DONTCARE
,
417 'name' => ts('Status'),
418 'sort' => 'pledge_status',
419 'direction' => CRM_Utils_Sort
::DONTCARE
,
421 array('desc' => ts('Actions')),
424 if (!$this->_single
) {
426 array('desc' => ts('Contact ID')),
428 'name' => ts('Name'),
429 'sort' => 'sort_name',
430 'direction' => CRM_Utils_Sort
::DONTCARE
,
434 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
437 return self
::$_columnHeaders;
443 public function &getQuery() {
444 return $this->_query
;
448 * Name of export file.
450 * @param string $output type of output
452 * @return string name of the file
454 public function getExportFileName($output = 'csv') {
455 return ts('Pledge Search');