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
19 * This class is used to retrieve and display a range of
20 * contacts that match the given criteria (specifically for
21 * results of advanced search options.
24 class CRM_Event_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
27 * This defines two actions- View and Edit.
31 public static $_links = NULL;
34 * We use desc to remind us what that column is, name is used in the tpl
38 public static $_columnHeaders;
41 * Properties of contact we're interested in displaying
44 public static $_properties = [
49 'participant_status_id',
51 'participant_fee_level',
57 'participant_is_test',
58 'participant_role_id',
59 'participant_register_date',
60 'participant_fee_amount',
61 'participant_fee_currency',
64 'participant_campaign_id',
68 * Are we restricting ourselves to a single contact
72 protected $_single = FALSE;
75 * Are we restricting ourselves to a single contact
79 protected $_limit = NULL;
82 * What context are we being invoked from
86 protected $_context = NULL;
89 * What component context are we being invoked from
93 protected $_compContext = NULL;
96 * QueryParams is the array returned by exportValues called on
97 * the HTML_QuickForm_Controller for that page.
101 public $_queryParams;
104 * Represent the type of selector.
111 * The additional clause that we restrict the search with.
115 protected $_eventClause = NULL;
127 * @param array $queryParams
128 * Array of parameters for query.
129 * @param \const|int $action - action of search basic or advanced.
130 * @param string $eventClause
131 * If the caller wants to further restrict the search (used in participations).
132 * @param bool $single
133 * Are we dealing only with one contact?.
135 * How many participations do we want returned.
137 * @param string $context
138 * @param null $compContext
140 * @return \CRM_Event_Selector_Search
142 public function __construct(
144 $action = CRM_Core_Action
::NONE
,
151 // submitted form values
152 $this->_queryParams
= &$queryParams;
154 $this->_single
= $single;
155 $this->_limit
= $limit;
156 $this->_context
= $context;
157 $this->_compContext
= $compContext;
159 $this->_eventClause
= $eventClause;
162 $this->_action
= $action;
164 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
165 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
169 CRM_Contact_BAO_Query
::MODE_EVENT
171 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
172 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
176 * Can be used to alter the number of participation returned from a buildForm hook.
179 * How many participations do we want returned.
181 public function setLimit($limit) {
182 $this->_limit
= $limit;
186 * This method returns the links that are given for each search row.
187 * currently the links added for each row are
193 * @param null $context
194 * @param null $compContext
198 public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
201 $extraParams .= "&compContext={$compContext}";
203 elseif ($context == 'search') {
204 $extraParams .= '&compContext=participant';
208 $extraParams .= "&key={$qfKey}";
211 if (!(self
::$_links)) {
213 CRM_Core_Action
::VIEW
=> [
214 'name' => ts('View'),
215 'url' => 'civicrm/contact/view/participant',
216 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
217 'title' => ts('View Participation'),
219 CRM_Core_Action
::UPDATE
=> [
220 'name' => ts('Edit'),
221 'url' => 'civicrm/contact/view/participant',
222 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
223 'title' => ts('Edit Participation'),
225 CRM_Core_Action
::DELETE
=> [
226 'name' => ts('Delete'),
227 'url' => 'civicrm/contact/view/participant',
228 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
229 'title' => ts('Delete Participation'),
233 return self
::$_links;
237 * Getter for array of the parameters required for creating pager.
240 * @param array $params
242 public function getPagerParams($action, &$params) {
243 $params['status'] = ts('Event') . ' %%StatusMessage%%';
244 $params['csvString'] = NULL;
246 $params['rowCount'] = $this->_limit
;
249 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
252 $params['buttonTop'] = 'PagerTopButton';
253 $params['buttonBottom'] = 'PagerBottomButton';
257 * Returns total number of rows for the query.
262 * Total number of rows
264 public function getTotalCount($action) {
265 return $this->_query
->searchQuery(0, 0, NULL,
274 * Returns all the rows in the given offset and rowCount.
276 * @param string $action
277 * The action being performed.
279 * The row number to start from.
280 * @param int $rowCount
281 * The number of rows to return.
282 * @param string $sort
283 * The sql string that describes the sort order.
284 * @param string $output
285 * What should the result set include (web/email/csv).
288 * rows in the given offset and rowCount
290 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
291 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
297 // process the result of the query
300 //lets handle view, edit and delete separately. CRM-4418
301 $permissions = [CRM_Core_Permission
::VIEW
];
302 if (CRM_Core_Permission
::check('edit event participants')) {
303 $permissions[] = CRM_Core_Permission
::EDIT
;
305 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
306 $permissions[] = CRM_Core_Permission
::DELETE
;
308 $mask = CRM_Core_Action
::mask($permissions);
310 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
311 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
312 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
313 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
316 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
318 while ($result->fetch()) {
320 // the columns we are interested in
321 foreach (self
::$_properties as $property) {
322 if (isset($result->$property)) {
323 $row[$property] = $result->$property;
327 // Skip registration if event_id is NULL
328 if (empty($row['event_id'])) {
329 Civi
::log()->warning('Participant record without event ID. You have invalid data in your database!');
333 //carry campaign on selectors.
334 $row['campaign'] = $allCampaigns[$result->participant_campaign_id
] ??
NULL;
335 $row['campaign_id'] = $result->participant_campaign_id
;
337 // gross hack to show extra information for pending status
339 if ((isset($row['participant_status_id'])) &&
340 ($statusId = array_search($row['participant_status_id'], $statusTypes))
342 $statusClass = $statusClasses[$statusId];
345 $row['showConfirmUrl'] = $statusClass == 'Pending';
347 if (!empty($row['participant_is_test'])) {
348 $row['participant_status'] = CRM_Core_TestEntity
::appendTestText($row['participant_status']);
351 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
352 $links = self
::links($this->_key
, $this->_context
, $this->_compContext
);
354 if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
355 $links[CRM_Core_Action
::ADD
] = [
356 'name' => ts('Record Payment'),
357 'url' => 'civicrm/payment',
358 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
359 'title' => ts('Record Payment'),
361 if (CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments()) {
362 $links[CRM_Core_Action
::BASIC
] = [
363 'name' => ts('Submit Credit Card payment'),
364 'url' => 'civicrm/payment/add',
365 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event&mode=live',
366 'title' => ts('Submit Credit Card payment'),
371 if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
372 $links[CRM_Core_Action
::ADD
] = [
373 'name' => ts('Record Refund'),
374 'url' => 'civicrm/payment',
375 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
376 'title' => ts('Record Refund'),
380 // CRM-20879: Show 'Transfer or Cancel' action only if logged in user
381 // have 'edit event participants' permission and participant status
382 // is not Cancelled or Transferred
383 if (in_array(CRM_Core_Permission
::EDIT
, $permissions) &&
384 !in_array($statusTypes[$row['participant_status_id']], ['Cancelled', 'Transferred'])
387 'name' => ts('Transfer or Cancel'),
388 'url' => 'civicrm/event/selfsvcupdate',
389 'qs' => 'reset=1&pid=%%id%%&is_backoffice=1&cs=' . CRM_Contact_BAO_Contact_Utils
::generateChecksum($result->contact_id
, NULL, 'inf'),
390 'title' => ts('Transfer or Cancel'),
394 $row['action'] = CRM_Core_Action
::formLink($links,
397 'id' => $result->participant_id
,
398 'cid' => $result->contact_id
,
399 'cxt' => $this->_context
,
403 'participant.selector.row',
405 $result->participant_id
408 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
411 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
413 if (!empty($row['participant_fee_level'])) {
414 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
417 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
418 // add line item details if applicable
419 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
422 if (!empty($row['participant_role_id'])) {
424 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
425 $viewRoles[] = $participantRoles[$v];
427 $row['participant_role_id'] = implode(', ', $viewRoles);
431 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
439 public function getQILL() {
440 return $this->_query
->qill();
444 * Returns the column headers as an array of tuples:
445 * (name, sortName (key to the sort array))
447 * @param string $action
448 * The action being performed.
449 * @param string $output
450 * What should the result set include (web/email/csv).
453 * the column headers that need to be displayed
455 public function &getColumnHeaders($action = NULL, $output = NULL) {
456 if (!isset(self
::$_columnHeaders)) {
457 self
::$_columnHeaders = [
459 'name' => ts('Event'),
460 'sort' => 'event_title',
461 'direction' => CRM_Utils_Sort
::DONTCARE
,
464 'name' => ts('Fee Level'),
465 'sort' => 'participant_fee_level',
466 'direction' => CRM_Utils_Sort
::DONTCARE
,
469 'name' => ts('Amount'),
470 'sort' => 'participant_fee_amount',
471 'direction' => CRM_Utils_Sort
::DONTCARE
,
474 'name' => ts('Registered'),
475 'sort' => 'participant_register_date',
476 'direction' => CRM_Utils_Sort
::DESCENDING
,
479 'name' => ts('Event Date(s)'),
480 'sort' => 'event_start_date',
481 'direction' => CRM_Utils_Sort
::DESCENDING
,
484 'name' => ts('Status'),
485 'sort' => 'participant_status',
486 'direction' => CRM_Utils_Sort
::DONTCARE
,
489 'name' => ts('Role'),
490 'sort' => 'participant_role_id',
491 'direction' => CRM_Utils_Sort
::DONTCARE
,
493 ['desc' => ts('Actions')],
496 if (!$this->_single
) {
498 ['desc' => ts('Contact Type')],
500 'name' => ts('Participant'),
501 'sort' => 'sort_name',
502 'direction' => CRM_Utils_Sort
::DONTCARE
,
505 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
508 return self
::$_columnHeaders;
514 public function alphabetQuery() {
515 return $this->_query
->alphabetQuery();
521 public function &getQuery() {
522 return $this->_query
;
526 * Name of export file.
528 * @param string $output
534 public function getExportFileName($output = 'csv') {
535 return ts('CiviCRM Event Search');