3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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_Contribute_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
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 'contribution_source',
76 'contribution_status_id',
77 'contribution_status',
81 'contribution_recur_id',
85 'contribution_campaign_id',
89 * are we restricting ourselves to a single contact
94 protected $_single = FALSE;
97 * are we restricting ourselves to a single contact
102 protected $_limit = NULL;
105 * what context are we being invoked from
110 protected $_context = NULL;
113 * what component context are we being invoked from
118 protected $_compContext = NULL;
121 * queryParams is the array returned by exportValues called on
122 * the HTML_QuickForm_Controller for that page.
127 public $_queryParams;
130 * represent the type of selector
138 * The additional clause that we restrict the search with
142 protected $_contributionClause = NULL;
154 * @param array $queryParams array of parameters for query
155 * @param int $action - action of search basic or advanced.
156 * @param string $contributionClause if the caller wants to further restrict the search (used in contributions)
157 * @param boolean $single are we dealing only with one contact?
158 * @param int $limit how many contributions do we want returned
160 * @return CRM_Contact_Selector
163 function __construct(&$queryParams,
164 $action = CRM_Core_Action
::NONE
,
165 $contributionClause = NULL,
172 // submitted form values
173 $this->_queryParams
= &$queryParams;
175 $this->_single
= $single;
176 $this->_limit
= $limit;
177 $this->_context
= $context;
178 $this->_compContext
= $compContext;
180 $this->_contributionClause
= $contributionClause;
183 $this->_action
= $action;
185 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
186 CRM_Contribute_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
,
190 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
192 $this->_query
->_distinctComponentClause
= " civicrm_contribution.id";
193 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_contribution.id ";
198 * This method returns the links that are given for each search row.
199 * currently the links added for each row are
208 static function &links($componentId = NULL, $componentAction = NULL, $key = NULL, $compContext = NULL) {
211 $extraParams = "&compId={$componentId}&compAction={$componentAction}";
214 $extraParams .= "&compContext={$compContext}";
217 $extraParams .= "&key={$key}";
220 if (!(self
::$_links)) {
221 self
::$_links = array(
222 CRM_Core_Action
::VIEW
=> array(
223 'name' => ts('View'),
224 'url' => 'civicrm/contact/view/contribution',
225 'qs' => "reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=contribute{$extraParams}",
226 'title' => ts('View Contribution'),
228 CRM_Core_Action
::UPDATE
=> array(
229 'name' => ts('Edit'),
230 'url' => 'civicrm/contact/view/contribution',
231 'qs' => "reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
232 'title' => ts('Edit Contribution'),
234 CRM_Core_Action
::DELETE
=> array(
235 'name' => ts('Delete'),
236 'url' => 'civicrm/contact/view/contribution',
237 'qs' => "reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
238 'title' => ts('Delete Contribution'),
242 return self
::$_links;
247 * getter for array of the parameters required for creating pager.
252 function getPagerParams($action, &$params) {
253 $params['status'] = ts('Contribution') . ' %%StatusMessage%%';
254 $params['csvString'] = NULL;
256 $params['rowCount'] = $this->_limit
;
259 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
262 $params['buttonTop'] = 'PagerTopButton';
263 $params['buttonBottom'] = 'PagerBottomButton';
268 * Returns total number of rows for the query.
272 * @return int Total number of rows
275 function getTotalCount($action) {
276 return $this->_query
->searchQuery(0, 0, NULL,
280 $this->_contributionClause
285 * returns all the rows in the given offset and rowCount
287 * @param enum $action the action being performed
288 * @param int $offset the row number to start from
289 * @param int $rowCount the number of rows to return
290 * @param string $sort the sql string that describes the sort order
291 * @param enum $output what should the result set include (web/email/csv)
293 * @return int the total number of rows for this action
295 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
296 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
300 $this->_contributionClause
302 // process the result of the query
305 //CRM-4418 check for view/edit/delete
306 $permissions = array(CRM_Core_Permission
::VIEW
);
307 if (CRM_Core_Permission
::check('edit contributions')) {
308 $permissions[] = CRM_Core_Permission
::EDIT
;
310 if (CRM_Core_Permission
::check('delete in CiviContribute')) {
311 $permissions[] = CRM_Core_Permission
::DELETE
;
313 $mask = CRM_Core_Action
::mask($permissions);
315 $qfKey = $this->_key
;
316 $componentId = $componentContext = NULL;
317 if ($this->_context
!= 'contribute') {
318 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', CRM_Core_DAO
::$_nullObject);
319 $componentId = CRM_Utils_Request
::retrieve('id', 'Positive', CRM_Core_DAO
::$_nullObject);
320 $componentAction = CRM_Utils_Request
::retrieve('action', 'String', CRM_Core_DAO
::$_nullObject);
321 $componentContext = CRM_Utils_Request
::retrieve('compContext', 'String', CRM_Core_DAO
::$_nullObject);
323 if (!$componentContext &&
326 $componentContext = $this->_compContext
;
327 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', CRM_Core_DAO
::$_nullObject, NULL, FALSE, 'REQUEST');
331 // get all contribution status
332 $contributionStatuses = CRM_Core_OptionGroup
::values('contribution_status',
333 FALSE, FALSE, FALSE, NULL, 'name', FALSE
337 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
339 While ($result->fetch()) {
341 // the columns we are interested in
342 foreach (self
::$_properties as $property) {
343 if (property_exists($result, $property)) {
344 $row[$property] = $result->$property;
348 //carry campaign on selectors.
349 $row['campaign'] = CRM_Utils_Array
::value($result->contribution_campaign_id
, $allCampaigns);
350 $row['campaign_id'] = $result->contribution_campaign_id
;
352 // add contribution status name
353 $row['contribution_status_name'] = CRM_Utils_Array
::value($row['contribution_status_id'],
354 $contributionStatuses
357 if ($result->is_pay_later
&& CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
358 $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
360 elseif (CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
361 $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
364 if ($row['is_test']) {
365 $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
368 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->contribution_id
;
371 'id' => $result->contribution_id
,
372 'cid' => $result->contact_id
,
373 'cxt' => $this->_context
,
376 $row['action'] = CRM_Core_Action
::formLink(
377 self
::links($componentId,
385 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
386 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
389 if (CRM_Utils_Array
::value('amount_level', $row)) {
390 CRM_Event_BAO_Participant
::fixEventLevel($row['amount_level']);
401 * @return array $qill which contains an array of strings
405 // the current internationalisation is bad, but should more or less work
406 // for most of "European" languages
407 public function getQILL() {
408 return $this->_query
->qill();
412 * returns the column headers as an array of tuples:
413 * (name, sortName (key to the sort array))
415 * @param string $action the action being performed
416 * @param enum $output what should the result set include (web/email/csv)
418 * @return array the column headers that need to be displayed
421 public function &getColumnHeaders($action = NULL, $output = NULL) {
422 if (!isset(self
::$_columnHeaders)) {
423 self
::$_columnHeaders = array(
425 'name' => ts('Amount'),
426 'sort' => 'total_amount',
427 'direction' => CRM_Utils_Sort
::DONTCARE
,
429 array('name' => ts('Type'),
430 'sort' => 'financial_type_id',
431 'direction' => CRM_Utils_Sort
::DONTCARE
,
434 'name' => ts('Source'),
435 'sort' => 'contribution_source',
436 'direction' => CRM_Utils_Sort
::DONTCARE
,
439 'name' => ts('Received'),
440 'sort' => 'receive_date',
441 'direction' => CRM_Utils_Sort
::DESCENDING
,
444 'name' => ts('Thank-you Sent'),
445 'sort' => 'thankyou_date',
446 'direction' => CRM_Utils_Sort
::DONTCARE
,
449 'name' => ts('Status'),
450 'sort' => 'contribution_status_id',
451 'direction' => CRM_Utils_Sort
::DONTCARE
,
454 'name' => ts('Premium'),
455 'sort' => 'product_name',
456 'direction' => CRM_Utils_Sort
::DONTCARE
,
458 array('desc' => ts('Actions')),
461 if (!$this->_single
) {
463 array('desc' => ts('Contact Type')),
465 'name' => ts('Name'),
466 'sort' => 'sort_name',
467 'direction' => CRM_Utils_Sort
::DONTCARE
,
470 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
473 return self
::$_columnHeaders;
476 function alphabetQuery() {
477 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
480 function &getQuery() {
481 return $this->_query
;
485 * name of export file.
487 * @param string $output type of output
489 * @return string name of the file
491 function getExportFileName($output = 'csv') {
492 return ts('CiviCRM Contribution Search');
495 function getSummary() {
496 return $this->_query
->summaryContribution($this->_context
);