3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class is used to retrieve and display a range of
22 * contacts that match the given criteria (specifically for
23 * results of advanced search options.
26 class CRM_Event_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
29 * This defines two actions- View and Edit.
33 public static $_links = NULL;
36 * We use desc to remind us what that column is, name is used in the tpl
40 public static $_columnHeaders;
43 * Properties of contact we're interested in displaying
46 public static $_properties = [
51 'participant_status_id',
53 'participant_fee_level',
59 'participant_is_test',
60 'participant_role_id',
61 'participant_register_date',
62 'participant_fee_amount',
63 'participant_fee_currency',
66 'participant_campaign_id',
70 * Are we restricting ourselves to a single contact
74 protected $_single = FALSE;
77 * Are we restricting ourselves to a single contact
81 protected $_limit = NULL;
84 * What context are we being invoked from
88 protected $_context = NULL;
91 * What component context are we being invoked from
95 protected $_compContext = NULL;
98 * QueryParams is the array returned by exportValues called on
99 * the HTML_QuickForm_Controller for that page.
103 public $_queryParams;
106 * Represent the type of selector.
113 * The additional clause that we restrict the search with.
117 protected $_eventClause = NULL;
129 * @param array $queryParams
130 * Array of parameters for query.
131 * @param \const|int $action - action of search basic or advanced.
132 * @param string $eventClause
133 * If the caller wants to further restrict the search (used in participations).
134 * @param bool $single
135 * Are we dealing only with one contact?.
137 * How many participations do we want returned.
139 * @param string $context
140 * @param null $compContext
142 * @return \CRM_Event_Selector_Search
144 public function __construct(
146 $action = CRM_Core_Action
::NONE
,
153 // submitted form values
154 $this->_queryParams
= &$queryParams;
156 $this->_single
= $single;
157 $this->_limit
= $limit;
158 $this->_context
= $context;
159 $this->_compContext
= $compContext;
161 $this->_eventClause
= $eventClause;
164 $this->_action
= $action;
166 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
167 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
171 CRM_Contact_BAO_Query
::MODE_EVENT
173 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
174 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
178 * Can be used to alter the number of participation returned from a buildForm hook.
181 * How many participations do we want returned.
183 public function setLimit($limit) {
184 $this->_limit
= $limit;
188 * This method returns the links that are given for each search row.
189 * currently the links added for each row are
195 * @param null $context
196 * @param null $compContext
200 public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
203 $extraParams .= "&compContext={$compContext}";
205 elseif ($context == 'search') {
206 $extraParams .= '&compContext=participant';
210 $extraParams .= "&key={$qfKey}";
213 if (!(self
::$_links)) {
215 CRM_Core_Action
::VIEW
=> [
216 'name' => ts('View'),
217 'url' => 'civicrm/contact/view/participant',
218 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
219 'title' => ts('View Participation'),
221 CRM_Core_Action
::UPDATE
=> [
222 'name' => ts('Edit'),
223 'url' => 'civicrm/contact/view/participant',
224 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
225 'title' => ts('Edit Participation'),
227 CRM_Core_Action
::DELETE
=> [
228 'name' => ts('Delete'),
229 'url' => 'civicrm/contact/view/participant',
230 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
231 'title' => ts('Delete Participation'),
235 return self
::$_links;
239 * Getter for array of the parameters required for creating pager.
242 * @param array $params
244 public function getPagerParams($action, &$params) {
245 $params['status'] = ts('Event') . ' %%StatusMessage%%';
246 $params['csvString'] = NULL;
248 $params['rowCount'] = $this->_limit
;
251 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
254 $params['buttonTop'] = 'PagerTopButton';
255 $params['buttonBottom'] = 'PagerBottomButton';
259 * Returns total number of rows for the query.
264 * Total number of rows
266 public function getTotalCount($action) {
267 return $this->_query
->searchQuery(0, 0, NULL,
276 * Returns all the rows in the given offset and rowCount.
278 * @param string $action
279 * The action being performed.
281 * The row number to start from.
282 * @param int $rowCount
283 * The number of rows to return.
284 * @param string $sort
285 * The sql string that describes the sort order.
286 * @param string $output
287 * What should the result set include (web/email/csv).
290 * rows in the given offset and rowCount
292 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
293 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
299 // process the result of the query
302 //lets handle view, edit and delete separately. CRM-4418
303 $permissions = [CRM_Core_Permission
::VIEW
];
304 if (CRM_Core_Permission
::check('edit event participants')) {
305 $permissions[] = CRM_Core_Permission
::EDIT
;
307 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
308 $permissions[] = CRM_Core_Permission
::DELETE
;
310 $mask = CRM_Core_Action
::mask($permissions);
312 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
313 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
314 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
315 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
318 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
320 while ($result->fetch()) {
322 // the columns we are interested in
323 foreach (self
::$_properties as $property) {
324 if (isset($result->$property)) {
325 $row[$property] = $result->$property;
329 // Skip registration if event_id is NULL
330 if (empty($row['event_id'])) {
331 Civi
::log()->warning('Participant record without event ID. You have invalid data in your database!');
335 //carry campaign on selectors.
336 $row['campaign'] = $allCampaigns[$result->participant_campaign_id
] ??
NULL;
337 $row['campaign_id'] = $result->participant_campaign_id
;
339 // gross hack to show extra information for pending status
341 if ((isset($row['participant_status_id'])) &&
342 ($statusId = array_search($row['participant_status_id'], $statusTypes))
344 $statusClass = $statusClasses[$statusId];
347 $row['showConfirmUrl'] = $statusClass == 'Pending';
349 if (!empty($row['participant_is_test'])) {
350 $row['participant_status'] = CRM_Core_TestEntity
::appendTestText($row['participant_status']);
353 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
354 $links = self
::links($this->_key
, $this->_context
, $this->_compContext
);
356 if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
357 $links[CRM_Core_Action
::ADD
] = [
358 'name' => ts('Record Payment'),
359 'url' => 'civicrm/payment',
360 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
361 'title' => ts('Record Payment'),
363 if (CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments()) {
364 $links[CRM_Core_Action
::BASIC
] = [
365 'name' => ts('Submit Credit Card payment'),
366 'url' => 'civicrm/payment/add',
367 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event&mode=live',
368 'title' => ts('Submit Credit Card payment'),
373 if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
374 $links[CRM_Core_Action
::ADD
] = [
375 'name' => ts('Record Refund'),
376 'url' => 'civicrm/payment',
377 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
378 'title' => ts('Record Refund'),
382 // CRM-20879: Show 'Transfer or Cancel' action only if logged in user
383 // have 'edit event participants' permission and participant status
384 // is not Cancelled or Transferred
385 if (in_array(CRM_Core_Permission
::EDIT
, $permissions) &&
386 !in_array($statusTypes[$row['participant_status_id']], ['Cancelled', 'Transferred'])
389 'name' => ts('Transfer or Cancel'),
390 'url' => 'civicrm/event/selfsvcupdate',
391 'qs' => 'reset=1&pid=%%id%%&is_backoffice=1&cs=' . CRM_Contact_BAO_Contact_Utils
::generateChecksum($result->contact_id
, NULL, 'inf'),
392 'title' => ts('Transfer or Cancel'),
396 $row['action'] = CRM_Core_Action
::formLink($links,
399 'id' => $result->participant_id
,
400 'cid' => $result->contact_id
,
401 'cxt' => $this->_context
,
405 'participant.selector.row',
407 $result->participant_id
410 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
413 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
415 if (!empty($row['participant_fee_level'])) {
416 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
419 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
420 // add line item details if applicable
421 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
424 if (!empty($row['participant_role_id'])) {
426 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
427 $viewRoles[] = $participantRoles[$v];
429 $row['participant_role_id'] = implode(', ', $viewRoles);
433 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
441 public function getQILL() {
442 return $this->_query
->qill();
446 * Returns the column headers as an array of tuples:
447 * (name, sortName (key to the sort array))
449 * @param string $action
450 * The action being performed.
451 * @param string $output
452 * What should the result set include (web/email/csv).
455 * the column headers that need to be displayed
457 public function &getColumnHeaders($action = NULL, $output = NULL) {
458 if (!isset(self
::$_columnHeaders)) {
459 self
::$_columnHeaders = [
461 'name' => ts('Event'),
462 'sort' => 'event_title',
463 'direction' => CRM_Utils_Sort
::DONTCARE
,
466 'name' => ts('Fee Level'),
467 'sort' => 'participant_fee_level',
468 'direction' => CRM_Utils_Sort
::DONTCARE
,
471 'name' => ts('Amount'),
472 'sort' => 'participant_fee_amount',
473 'direction' => CRM_Utils_Sort
::DONTCARE
,
476 'name' => ts('Registered'),
477 'sort' => 'participant_register_date',
478 'direction' => CRM_Utils_Sort
::DESCENDING
,
481 'name' => ts('Event Date(s)'),
482 'sort' => 'event_start_date',
483 'direction' => CRM_Utils_Sort
::DESCENDING
,
486 'name' => ts('Status'),
487 'sort' => 'participant_status',
488 'direction' => CRM_Utils_Sort
::DONTCARE
,
491 'name' => ts('Role'),
492 'sort' => 'participant_role_id',
493 'direction' => CRM_Utils_Sort
::DONTCARE
,
495 ['desc' => ts('Actions')],
498 if (!$this->_single
) {
500 ['desc' => ts('Contact Type')],
502 'name' => ts('Participant'),
503 'sort' => 'sort_name',
504 'direction' => CRM_Utils_Sort
::DONTCARE
,
507 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
510 return self
::$_columnHeaders;
516 public function alphabetQuery() {
517 return $this->_query
->alphabetQuery();
523 public function &getQuery() {
524 return $this->_query
;
528 * Name of export file.
530 * @param string $output
536 public function getExportFileName($output = 'csv') {
537 return ts('CiviCRM Event Search');