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(
172 $action = CRM_Core_Action
::NONE
,
173 $contributionClause = NULL,
180 // submitted form values
181 $this->_queryParams
= &$queryParams;
183 $this->_single
= $single;
184 $this->_limit
= $limit;
185 $this->_context
= $context;
186 $this->_compContext
= $compContext;
188 $this->_contributionClause
= $contributionClause;
191 $this->_action
= $action;
193 $this->_includeSoftCredits
= CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($this->_queryParams
);
194 $this->_query
= new CRM_Contact_BAO_Query(
196 CRM_Contribute_BAO_Query
::defaultReturnProperties(
197 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
,
201 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
203 if ($this->_includeSoftCredits
) {
204 $this->_query
->_rowCountClause
= " count(civicrm_contribution.id)";
205 $this->_query
->_groupByComponentClause
= " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
208 $this->_query
->_distinctComponentClause
= " civicrm_contribution.id";
209 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_contribution.id ";
214 * This method returns the links that are given for each search row.
215 * currently the links added for each row are
220 * @param int $componentId
221 * @param null $componentAction
223 * @param null $compContext
227 public static function &links($componentId = NULL, $componentAction = NULL, $key = NULL, $compContext = NULL) {
230 $extraParams = "&compId={$componentId}&compAction={$componentAction}";
233 $extraParams .= "&compContext={$compContext}";
236 $extraParams .= "&key={$key}";
239 if (!(self
::$_links)) {
240 self
::$_links = array(
241 CRM_Core_Action
::VIEW
=> array(
242 'name' => ts('View'),
243 'url' => 'civicrm/contact/view/contribution',
244 'qs' => "reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=contribute{$extraParams}",
245 'title' => ts('View Contribution'),
247 CRM_Core_Action
::UPDATE
=> array(
248 'name' => ts('Edit'),
249 'url' => 'civicrm/contact/view/contribution',
250 'qs' => "reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
251 'title' => ts('Edit Contribution'),
253 CRM_Core_Action
::DELETE
=> array(
254 'name' => ts('Delete'),
255 'url' => 'civicrm/contact/view/contribution',
256 'qs' => "reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
257 'title' => ts('Delete Contribution'),
261 return self
::$_links;
265 * Getter for array of the parameters required for creating pager.
268 * @param array $params
270 public function getPagerParams($action, &$params) {
271 $params['status'] = ts('Contribution') . ' %%StatusMessage%%';
272 $params['csvString'] = NULL;
274 $params['rowCount'] = $this->_limit
;
277 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
280 $params['buttonTop'] = 'PagerTopButton';
281 $params['buttonBottom'] = 'PagerBottomButton';
285 * Returns total number of rows for the query.
290 * Total number of rows
292 public function getTotalCount($action) {
293 return $this->_query
->searchQuery(0, 0, NULL,
297 $this->_contributionClause
302 * Returns all the rows in the given offset and rowCount
304 * @param enum $action
305 * The action being performed.
307 * The row number to start from.
308 * @param int $rowCount
309 * The number of rows to return.
310 * @param string $sort
311 * The sql string that describes the sort order.
312 * @param enum $output
313 * What should the result set include (web/email/csv).
316 * the total number of rows for this action
318 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
319 if ($this->_includeSoftCredits
) {
320 // especial sort order when rows include soft credits
321 $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id";
323 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
327 $this->_contributionClause
329 // process the result of the query
332 //CRM-4418 check for view/edit/delete
333 $permissions = array(CRM_Core_Permission
::VIEW
);
334 if (CRM_Core_Permission
::check('edit contributions')) {
335 $permissions[] = CRM_Core_Permission
::EDIT
;
337 if (CRM_Core_Permission
::check('delete in CiviContribute')) {
338 $permissions[] = CRM_Core_Permission
::DELETE
;
340 $mask = CRM_Core_Action
::mask($permissions);
342 $qfKey = $this->_key
;
343 $componentId = $componentContext = NULL;
344 if ($this->_context
!= 'contribute') {
345 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', CRM_Core_DAO
::$_nullObject);
346 $componentId = CRM_Utils_Request
::retrieve('id', 'Positive', CRM_Core_DAO
::$_nullObject);
347 $componentAction = CRM_Utils_Request
::retrieve('action', 'String', CRM_Core_DAO
::$_nullObject);
348 $componentContext = CRM_Utils_Request
::retrieve('compContext', 'String', CRM_Core_DAO
::$_nullObject);
350 if (!$componentContext &&
353 $componentContext = $this->_compContext
;
354 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', CRM_Core_DAO
::$_nullObject, NULL, FALSE, 'REQUEST');
358 // get all contribution status
359 $contributionStatuses = CRM_Core_OptionGroup
::values('contribution_status',
360 FALSE, FALSE, FALSE, NULL, 'name', FALSE
364 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
366 while ($result->fetch()) {
368 // the columns we are interested in
369 foreach (self
::$_properties as $property) {
370 if (property_exists($result, $property)) {
371 $row[$property] = $result->$property;
375 //carry campaign on selectors.
376 $row['campaign'] = CRM_Utils_Array
::value($result->contribution_campaign_id
, $allCampaigns);
377 $row['campaign_id'] = $result->contribution_campaign_id
;
379 // add contribution status name
380 $row['contribution_status_name'] = CRM_Utils_Array
::value($row['contribution_status_id'],
381 $contributionStatuses
384 if ($result->is_pay_later
&& CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
385 $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
387 elseif (CRM_Utils_Array
::value('contribution_status_name', $row) == 'Pending') {
388 $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
391 if ($row['is_test']) {
392 $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
395 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->contribution_id
;
398 'id' => $result->contribution_id
,
399 'cid' => $result->contact_id
,
400 'cxt' => $this->_context
,
403 $row['action'] = CRM_Core_Action
::formLink(
404 self
::links($componentId,
412 'contribution.selector.row',
414 $result->contribution_id
417 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
420 if (!empty($row['amount_level'])) {
421 CRM_Event_BAO_Participant
::fixEventLevel($row['amount_level']);
432 * which contains an array of strings
435 // the current internationalisation is bad, but should more or less work
436 // for most of "European" languages
437 public function getQILL() {
438 return $this->_query
->qill();
442 * Returns the column headers as an array of tuples:
443 * (name, sortName (key to the sort array))
445 * @param string $action
446 * The action being performed.
447 * @param enum $output
448 * What should the result set include (web/email/csv).
451 * the column headers that need to be displayed
453 public function &getColumnHeaders($action = NULL, $output = NULL) {
454 self
::$_columnHeaders = array(
456 'name' => $this->_includeSoftCredits ?
ts('Contribution Amount') : ts('Amount'),
457 'sort' => 'total_amount',
458 'direction' => CRM_Utils_Sort
::DONTCARE
,
461 if ($this->_includeSoftCredits
) {
462 self
::$_columnHeaders =
464 self
::$_columnHeaders,
467 'name' => ts('Soft Credit Amount'),
468 'sort' => 'contribution_soft_credit_amount',
469 'direction' => CRM_Utils_Sort
::DONTCARE
,
474 self
::$_columnHeaders =
476 self
::$_columnHeaders,
479 'name' => ts('Type'),
480 'sort' => 'financial_type',
481 'direction' => CRM_Utils_Sort
::DONTCARE
,
484 'name' => ts('Source'),
485 'sort' => 'contribution_source',
486 'direction' => CRM_Utils_Sort
::DONTCARE
,
489 'name' => ts('Received'),
490 'sort' => 'receive_date',
491 'direction' => CRM_Utils_Sort
::DESCENDING
,
494 'name' => ts('Thank-you Sent'),
495 'sort' => 'thankyou_date',
496 'direction' => CRM_Utils_Sort
::DONTCARE
,
499 'name' => ts('Status'),
500 'sort' => 'contribution_status',
501 'direction' => CRM_Utils_Sort
::DONTCARE
,
504 'name' => ts('Premium'),
505 'sort' => 'product_name',
506 'direction' => CRM_Utils_Sort
::DONTCARE
,
510 if (!$this->_single
) {
512 array('desc' => ts('Contact Type')),
514 'name' => ts('Name'),
515 'sort' => 'sort_name',
516 'direction' => CRM_Utils_Sort
::DONTCARE
,
519 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
521 if ($this->_includeSoftCredits
) {
522 self
::$_columnHeaders =
524 self
::$_columnHeaders,
527 'name' => ts('Soft Credit For'),
528 'sort' => 'contribution_soft_credit_name',
529 'direction' => CRM_Utils_Sort
::DONTCARE
,
532 'name' => ts('Soft Credit Type'),
533 'sort' => 'contribution_soft_credit_type',
534 'direction' => CRM_Utils_Sort
::ASCENDING
,
539 self
::$_columnHeaders =
541 self
::$_columnHeaders, array(
542 array('desc' => ts('Actions')),
545 return self
::$_columnHeaders;
551 public function alphabetQuery() {
552 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
558 public function &getQuery() {
559 return $this->_query
;
563 * Name of export file.
565 * @param string $output
571 public function getExportFileName($output = 'csv') {
572 return ts('CiviCRM Contribution Search');
578 public function getSummary() {
579 return $this->_query
->summaryContribution($this->_context
);