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_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',
86 'contribution_soft_credit_name',
87 'contribution_soft_credit_contact_id',
88 'contribution_soft_credit_amount',
89 'contribution_soft_credit_type',
93 * Are we restricting ourselves to a single contact
97 protected $_single = FALSE;
100 * Are we restricting ourselves to a single contact
104 protected $_limit = NULL;
107 * What context are we being invoked from
111 protected $_context = NULL;
114 * 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.
126 public $_queryParams;
129 * Represent the type of selector
136 * The additional clause that we restrict the search with
140 protected $_contributionClause = NULL;
149 protected $_includeSoftCredits = FALSE;
154 * @param array $queryParams
155 * Array of parameters for query.
156 * @param \const|int $action - action of search basic or advanced.
157 * @param string $contributionClause
158 * If the caller wants to further restrict the search (used in contributions).
159 * @param bool $single
160 * Are we dealing only with one contact?.
162 * How many contributions do we want returned.
164 * @param string $context
165 * @param null $compContext
167 * @return \CRM_Contribute_Selector_Search
170 function __construct(&$queryParams,
171 $action = CRM_Core_Action
::NONE
,
172 $contributionClause = NULL,
179 // submitted form values
180 $this->_queryParams
= &$queryParams;
182 $this->_single
= $single;
183 $this->_limit
= $limit;
184 $this->_context
= $context;
185 $this->_compContext
= $compContext;
187 $this->_contributionClause
= $contributionClause;
190 $this->_action
= $action;
192 $this->_includeSoftCredits
= CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($this->_queryParams
);
193 $this->_query
= new CRM_Contact_BAO_Query(
195 CRM_Contribute_BAO_Query
::defaultReturnProperties(
196 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
,
200 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
202 if ($this->_includeSoftCredits
) {
203 $this->_query
->_rowCountClause
= " count(civicrm_contribution.id)";
204 $this->_query
->_groupByComponentClause
= " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
206 $this->_query
->_distinctComponentClause
= " civicrm_contribution.id";
207 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_contribution.id ";
212 * This method returns the links that are given for each search row.
213 * currently the links added for each row are
218 * @param int $componentId
219 * @param null $componentAction
221 * @param null $compContext
225 public static function &links($componentId = NULL, $componentAction = NULL, $key = NULL, $compContext = NULL) {
228 $extraParams = "&compId={$componentId}&compAction={$componentAction}";
231 $extraParams .= "&compContext={$compContext}";
234 $extraParams .= "&key={$key}";
237 if (!(self
::$_links)) {
238 self
::$_links = array(
239 CRM_Core_Action
::VIEW
=> array(
240 'name' => ts('View'),
241 'url' => 'civicrm/contact/view/contribution',
242 'qs' => "reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=contribute{$extraParams}",
243 'title' => ts('View Contribution'),
245 CRM_Core_Action
::UPDATE
=> array(
246 'name' => ts('Edit'),
247 'url' => 'civicrm/contact/view/contribution',
248 'qs' => "reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
249 'title' => ts('Edit Contribution'),
251 CRM_Core_Action
::DELETE
=> array(
252 'name' => ts('Delete'),
253 'url' => 'civicrm/contact/view/contribution',
254 'qs' => "reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
255 'title' => ts('Delete Contribution'),
259 return self
::$_links;
263 * Getter for array of the parameters required for creating pager.
266 * @param array $params
268 public function getPagerParams($action, &$params) {
269 $params['status'] = ts('Contribution') . ' %%StatusMessage%%';
270 $params['csvString'] = NULL;
272 $params['rowCount'] = $this->_limit
;
275 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
278 $params['buttonTop'] = 'PagerTopButton';
279 $params['buttonBottom'] = 'PagerBottomButton';
283 * Returns total number of rows for the query.
287 * @return int Total number of rows
289 public function getTotalCount($action) {
290 return $this->_query
->searchQuery(0, 0, NULL,
294 $this->_contributionClause
299 * Returns all the rows in the given offset and rowCount
301 * @param enum $action
302 * The action being performed.
304 * The row number to start from.
305 * @param int $rowCount
306 * The number of rows to return.
307 * @param string $sort
308 * The sql string that describes the sort order.
309 * @param enum $output
310 * What should the result set include (web/email/csv).
312 * @return int the total number of rows for this action
314 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
315 if ($this->_includeSoftCredits
) {
316 // especial sort order when rows include soft credits
317 $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id";
319 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
323 $this->_contributionClause
325 // process the result of the query
328 //CRM-4418 check for view/edit/delete
329 $permissions = array(CRM_Core_Permission
::VIEW
);
330 if (CRM_Core_Permission
::check('edit contributions')) {
331 $permissions[] = CRM_Core_Permission
::EDIT
;
333 if (CRM_Core_Permission
::check('delete in CiviContribute')) {
334 $permissions[] = CRM_Core_Permission
::DELETE
;
336 $mask = CRM_Core_Action
::mask($permissions);
338 $qfKey = $this->_key
;
339 $componentId = $componentContext = NULL;
340 if ($this->_context
!= 'contribute') {
341 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', CRM_Core_DAO
::$_nullObject);
342 $componentId = CRM_Utils_Request
::retrieve('id', 'Positive', CRM_Core_DAO
::$_nullObject);
343 $componentAction = CRM_Utils_Request
::retrieve('action', 'String', CRM_Core_DAO
::$_nullObject);
344 $componentContext = CRM_Utils_Request
::retrieve('compContext', 'String', CRM_Core_DAO
::$_nullObject);
346 if (!$componentContext &&
349 $componentContext = $this->_compContext
;
350 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', CRM_Core_DAO
::$_nullObject, NULL, FALSE, 'REQUEST');
354 // get all contribution status
355 $contributionStatuses = CRM_Core_OptionGroup
::values('contribution_status',
356 FALSE, FALSE, FALSE, NULL, 'name', FALSE
360 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
362 While ($result->fetch()) {
364 // the columns we are interested in
365 foreach (self
::$_properties as $property) {
366 if (property_exists($result, $property)) {
367 $row[$property] = $result->$property;
371 //carry campaign on selectors.
372 $row['campaign'] = CRM_Utils_Array
::value($result->contribution_campaign_id
, $allCampaigns);
373 $row['campaign_id'] = $result->contribution_campaign_id
;
375 // add contribution status name
376 $row['contribution_status_name'] = CRM_Utils_Array
::value($row['contribution_status_id'],
377 $contributionStatuses
380 if ($result->is_pay_later
&& CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
381 $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
383 elseif (CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
384 $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
387 if ($row['is_test']) {
388 $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
391 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->contribution_id
;
394 'id' => $result->contribution_id
,
395 'cid' => $result->contact_id
,
396 'cxt' => $this->_context
,
399 $row['action'] = CRM_Core_Action
::formLink(
400 self
::links($componentId,
408 'contribution.selector.row',
410 $result->contribution_id
413 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
414 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
417 if (!empty($row['amount_level'])) {
418 CRM_Event_BAO_Participant
::fixEventLevel($row['amount_level']);
428 * @return array $qill which contains an array of strings
431 // the current internationalisation is bad, but should more or less work
432 // for most of "European" languages
433 public function getQILL() {
434 return $this->_query
->qill();
438 * Returns the column headers as an array of tuples:
439 * (name, sortName (key to the sort array))
441 * @param string $action
442 * The action being performed.
443 * @param enum $output
444 * What should the result set include (web/email/csv).
446 * @return array the column headers that need to be displayed
448 public function &getColumnHeaders($action = NULL, $output = NULL) {
449 self
::$_columnHeaders = array(
451 'name' => $this->_includeSoftCredits ?
ts('Contribution Amount') : ts('Amount'),
452 'sort' => 'total_amount',
453 'direction' => CRM_Utils_Sort
::DONTCARE
,
456 if ($this->_includeSoftCredits
) {
457 self
::$_columnHeaders =
459 self
::$_columnHeaders,
462 'name' => ts('Soft Credit Amount'),
463 'sort' => 'contribution_soft_credit_amount',
464 'direction' => CRM_Utils_Sort
::DONTCARE
,
469 self
::$_columnHeaders =
471 self
::$_columnHeaders,
474 'name' => ts('Type'),
475 'sort' => 'financial_type',
476 'direction' => CRM_Utils_Sort
::DONTCARE
,
479 'name' => ts('Source'),
480 'sort' => 'contribution_source',
481 'direction' => CRM_Utils_Sort
::DONTCARE
,
484 'name' => ts('Received'),
485 'sort' => 'receive_date',
486 'direction' => CRM_Utils_Sort
::DESCENDING
,
489 'name' => ts('Thank-you Sent'),
490 'sort' => 'thankyou_date',
491 'direction' => CRM_Utils_Sort
::DONTCARE
,
494 'name' => ts('Status'),
495 'sort' => 'contribution_status',
496 'direction' => CRM_Utils_Sort
::DONTCARE
,
499 'name' => ts('Premium'),
500 'sort' => 'product_name',
501 'direction' => CRM_Utils_Sort
::DONTCARE
,
505 if (!$this->_single
) {
507 array('desc' => ts('Contact Type')),
509 'name' => ts('Name'),
510 'sort' => 'sort_name',
511 'direction' => CRM_Utils_Sort
::DONTCARE
,
514 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
516 if ($this->_includeSoftCredits
) {
517 self
::$_columnHeaders =
519 self
::$_columnHeaders,
522 'name' => ts('Soft Credit For'),
523 'sort' => 'contribution_soft_credit_name',
524 'direction' => CRM_Utils_Sort
::DONTCARE
,
527 'name' => ts('Soft Credit Type'),
528 'sort' => 'contribution_soft_credit_type',
529 'direction' => CRM_Utils_Sort
::ASCENDING
,
534 self
::$_columnHeaders =
536 self
::$_columnHeaders, array(
537 array('desc' => ts('Actions'))
540 return self
::$_columnHeaders;
546 public function alphabetQuery() {
547 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
553 public function &getQuery() {
554 return $this->_query
;
558 * Name of export file.
560 * @param string $output
563 * @return string name of the file
565 public function getExportFileName($output = 'csv') {
566 return ts('CiviCRM Contribution Search');
572 public function getSummary() {
573 return $this->_query
->summaryContribution($this->_context
);