3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
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_Event_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * This defines two actions- View and Edit.
49 static $_links = NULL;
52 * We use desc to remind us what that column is, name is used in the tpl
56 static $_columnHeaders;
59 * Properties of contact we're interested in displaying
62 static $_properties = [
67 'participant_status_id',
69 'participant_fee_level',
75 'participant_is_test',
76 'participant_role_id',
77 'participant_register_date',
78 'participant_fee_amount',
79 'participant_fee_currency',
82 'participant_campaign_id',
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 * What component context are we being invoked from
111 protected $_compContext = NULL;
114 * QueryParams is the array returned by exportValues called on
115 * the HTML_QuickForm_Controller for that page.
119 public $_queryParams;
122 * Represent the type of selector.
129 * The additional clause that we restrict the search with.
133 protected $_eventClause = NULL;
145 * @param array $queryParams
146 * Array of parameters for query.
147 * @param \const|int $action - action of search basic or advanced.
148 * @param string $eventClause
149 * If the caller wants to further restrict the search (used in participations).
150 * @param bool $single
151 * Are we dealing only with one contact?.
153 * How many participations do we want returned.
155 * @param string $context
156 * @param null $compContext
158 * @return \CRM_Event_Selector_Search
160 public function __construct(
162 $action = CRM_Core_Action
::NONE
,
169 // submitted form values
170 $this->_queryParams
= &$queryParams;
172 $this->_single
= $single;
173 $this->_limit
= $limit;
174 $this->_context
= $context;
175 $this->_compContext
= $compContext;
177 $this->_eventClause
= $eventClause;
180 $this->_action
= $action;
182 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
183 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
187 CRM_Contact_BAO_Query
::MODE_EVENT
189 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
190 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
194 * Can be used to alter the number of participation returned from a buildForm hook.
197 * How many participations do we want returned.
199 public function setLimit($limit) {
200 $this->_limit
= $limit;
204 * This method returns the links that are given for each search row.
205 * currently the links added for each row are
211 * @param null $context
212 * @param null $compContext
216 public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
219 $extraParams .= "&compContext={$compContext}";
221 elseif ($context == 'search') {
222 $extraParams .= '&compContext=participant';
226 $extraParams .= "&key={$qfKey}";
229 if (!(self
::$_links)) {
231 CRM_Core_Action
::VIEW
=> [
232 'name' => ts('View'),
233 'url' => 'civicrm/contact/view/participant',
234 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
235 'title' => ts('View Participation'),
237 CRM_Core_Action
::UPDATE
=> [
238 'name' => ts('Edit'),
239 'url' => 'civicrm/contact/view/participant',
240 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
241 'title' => ts('Edit Participation'),
243 CRM_Core_Action
::DELETE
=> [
244 'name' => ts('Delete'),
245 'url' => 'civicrm/contact/view/participant',
246 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
247 'title' => ts('Delete Participation'),
251 return self
::$_links;
255 * Getter for array of the parameters required for creating pager.
258 * @param array $params
260 public function getPagerParams($action, &$params) {
261 $params['status'] = ts('Event') . ' %%StatusMessage%%';
262 $params['csvString'] = NULL;
264 $params['rowCount'] = $this->_limit
;
267 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
270 $params['buttonTop'] = 'PagerTopButton';
271 $params['buttonBottom'] = 'PagerBottomButton';
275 * Returns total number of rows for the query.
280 * Total number of rows
282 public function getTotalCount($action) {
283 return $this->_query
->searchQuery(0, 0, NULL,
292 * Returns all the rows in the given offset and rowCount.
294 * @param string $action
295 * The action being performed.
297 * The row number to start from.
298 * @param int $rowCount
299 * The number of rows to return.
300 * @param string $sort
301 * The sql string that describes the sort order.
302 * @param string $output
303 * What should the result set include (web/email/csv).
306 * rows in the given offset and rowCount
308 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
309 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
315 // process the result of the query
318 //lets handle view, edit and delete separately. CRM-4418
319 $permissions = [CRM_Core_Permission
::VIEW
];
320 if (CRM_Core_Permission
::check('edit event participants')) {
321 $permissions[] = CRM_Core_Permission
::EDIT
;
323 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
324 $permissions[] = CRM_Core_Permission
::DELETE
;
326 $mask = CRM_Core_Action
::mask($permissions);
328 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
329 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
330 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
331 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
334 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
336 while ($result->fetch()) {
338 // the columns we are interested in
339 foreach (self
::$_properties as $property) {
340 if (isset($result->$property)) {
341 $row[$property] = $result->$property;
345 // Skip registration if event_id is NULL
346 if (empty($row['event_id'])) {
347 Civi
::log()->warning('Participant record without event ID. You have invalid data in your database!');
351 //carry campaign on selectors.
352 $row['campaign'] = CRM_Utils_Array
::value($result->participant_campaign_id
, $allCampaigns);
353 $row['campaign_id'] = $result->participant_campaign_id
;
355 // gross hack to show extra information for pending status
357 if ((isset($row['participant_status_id'])) &&
358 ($statusId = array_search($row['participant_status_id'], $statusTypes))
360 $statusClass = $statusClasses[$statusId];
363 $row['showConfirmUrl'] = ($statusClass == 'Pending') ?
TRUE : FALSE;
365 if (!empty($row['participant_is_test'])) {
366 $row['participant_status'] = CRM_Core_TestEntity
::appendTestText($row['participant_status']);
369 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
370 $links = self
::links($this->_key
, $this->_context
, $this->_compContext
);
372 if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
373 $links[CRM_Core_Action
::ADD
] = [
374 'name' => ts('Record Payment'),
375 'url' => 'civicrm/payment',
376 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
377 'title' => ts('Record Payment'),
379 if (CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments()) {
380 $links[CRM_Core_Action
::BASIC
] = [
381 'name' => ts('Submit Credit Card payment'),
382 'url' => 'civicrm/payment/add',
383 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event&mode=live',
384 'title' => ts('Submit Credit Card payment'),
389 if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
390 $links[CRM_Core_Action
::ADD
] = [
391 'name' => ts('Record Refund'),
392 'url' => 'civicrm/payment',
393 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
394 'title' => ts('Record Refund'),
398 // CRM-20879: Show 'Transfer or Cancel' action only if logged in user
399 // have 'edit event participants' permission and participant status
400 // is not Cancelled or Transferred
401 if (in_array(CRM_Core_Permission
::EDIT
, $permissions) &&
402 !in_array($statusTypes[$row['participant_status_id']], ['Cancelled', 'Transferred'])
405 'name' => ts('Transfer or Cancel'),
406 'url' => 'civicrm/event/selfsvcupdate',
407 'qs' => 'reset=1&pid=%%id%%&is_backoffice=1&cs=' . CRM_Contact_BAO_Contact_Utils
::generateChecksum($result->contact_id
, NULL, 'inf'),
408 'title' => ts('Transfer or Cancel'),
412 $row['action'] = CRM_Core_Action
::formLink($links,
415 'id' => $result->participant_id
,
416 'cid' => $result->contact_id
,
417 'cxt' => $this->_context
,
421 'participant.selector.row',
423 $result->participant_id
426 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
429 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
431 if (!empty($row['participant_fee_level'])) {
432 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
435 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
436 // add line item details if applicable
437 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
440 if (!empty($row['participant_role_id'])) {
442 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
443 $viewRoles[] = $participantRoles[$v];
445 $row['participant_role_id'] = implode(', ', $viewRoles);
449 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
457 public function getQILL() {
458 return $this->_query
->qill();
462 * Returns the column headers as an array of tuples:
463 * (name, sortName (key to the sort array))
465 * @param string $action
466 * The action being performed.
467 * @param string $output
468 * What should the result set include (web/email/csv).
471 * the column headers that need to be displayed
473 public function &getColumnHeaders($action = NULL, $output = NULL) {
474 if (!isset(self
::$_columnHeaders)) {
475 self
::$_columnHeaders = [
477 'name' => ts('Event'),
478 'sort' => 'event_title',
479 'direction' => CRM_Utils_Sort
::DONTCARE
,
482 'name' => ts('Fee Level'),
483 'sort' => 'participant_fee_level',
484 'direction' => CRM_Utils_Sort
::DONTCARE
,
487 'name' => ts('Amount'),
488 'sort' => 'participant_fee_amount',
489 'direction' => CRM_Utils_Sort
::DONTCARE
,
492 'name' => ts('Registered'),
493 'sort' => 'participant_register_date',
494 'direction' => CRM_Utils_Sort
::DESCENDING
,
497 'name' => ts('Event Date(s)'),
498 'sort' => 'event_start_date',
499 'direction' => CRM_Utils_Sort
::DESCENDING
,
502 'name' => ts('Status'),
503 'sort' => 'participant_status',
504 'direction' => CRM_Utils_Sort
::DONTCARE
,
507 'name' => ts('Role'),
508 'sort' => 'participant_role_id',
509 'direction' => CRM_Utils_Sort
::DONTCARE
,
511 ['desc' => ts('Actions')],
514 if (!$this->_single
) {
516 ['desc' => ts('Contact Type')],
518 'name' => ts('Participant'),
519 'sort' => 'sort_name',
520 'direction' => CRM_Utils_Sort
::DONTCARE
,
523 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
526 return self
::$_columnHeaders;
532 public function alphabetQuery() {
533 return $this->_query
->alphabetQuery();
539 public function &getQuery() {
540 return $this->_query
;
544 * Name of export file.
546 * @param string $output
552 public function getExportFileName($output = 'csv') {
553 return ts('CiviCRM Event Search');