Merge pull request #23922 from seamuslee001/str_func_null_1
[civicrm-core.git] / CRM / Event / BAO / Query.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Event_BAO_Query extends CRM_Core_BAO_Query {
18
19 /**
20 * Function get the import/export fields for contribution.
21 *
22 * @param bool $checkPermission
23 *
24 * @return array
25 * Associative array of contribution fields
26 */
27 public static function &getFields($checkPermission = TRUE) {
28 $fields = [];
29 $fields = array_merge($fields, CRM_Event_DAO_Event::import());
30 $fields = array_merge($fields, self::getParticipantFields());
31 $fields = array_merge($fields, CRM_Core_DAO_Discount::export());
32 $fields['event'] = self::getPseudoEventDateFieldMetadata();
33 return $fields;
34 }
35
36 /**
37 * @return array
38 */
39 public static function getParticipantFields() {
40 return CRM_Event_BAO_Participant::importableFields('Individual', TRUE, TRUE);
41 }
42
43 /**
44 * Build select for CiviEvent.
45 *
46 * @param $query
47 */
48 public static function select(&$query) {
49 if (($query->_mode & CRM_Contact_BAO_Query::MODE_EVENT) ||
50 CRM_Contact_BAO_Query::componentPresent($query->_returnProperties, 'participant_')
51 ) {
52 $query->_select['participant_id'] = 'civicrm_participant.id as participant_id';
53 $query->_element['participant_id'] = 1;
54 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
55
56 //add fee level
57 if (!empty($query->_returnProperties['participant_fee_level'])) {
58 $query->_select['participant_fee_level'] = 'civicrm_participant.fee_level as participant_fee_level';
59 $query->_element['participant_fee_level'] = 1;
60 }
61
62 //add participant contact ID
63 if (!empty($query->_returnProperties['participant_contact_id'])) {
64 $query->_select['participant_contact_id'] = 'civicrm_participant.contact_id as participant_contact_id';
65 $query->_element['participant_contact_id'] = 1;
66 }
67
68 //add fee amount
69 if (!empty($query->_returnProperties['participant_fee_amount'])) {
70 $query->_select['participant_fee_amount'] = 'civicrm_participant.fee_amount as participant_fee_amount';
71 $query->_element['participant_fee_amount'] = 1;
72 }
73
74 //add fee currency
75 if (!empty($query->_returnProperties['participant_fee_currency'])) {
76 $query->_select['participant_fee_currency'] = "civicrm_participant.fee_currency as participant_fee_currency";
77 $query->_element['participant_fee_currency'] = 1;
78 }
79
80 //add event title also if event id is select
81 if (!empty($query->_returnProperties['event_id']) || !empty($query->_returnProperties['event_title'])) {
82 $query->_select['event_id'] = "civicrm_event.id as event_id";
83 $query->_select['event_title'] = "civicrm_event.title as event_title";
84 $query->_element['event_id'] = 1;
85 $query->_element['event_title'] = 1;
86 $query->_tables['civicrm_event'] = 1;
87 $query->_whereTables['civicrm_event'] = 1;
88 }
89
90 //add start date / end date
91 if (!empty($query->_returnProperties['event_start_date'])) {
92 $query->_select['event_start_date'] = "civicrm_event.start_date as event_start_date";
93 $query->_element['event_start_date'] = 1;
94 }
95
96 if (!empty($query->_returnProperties['event_end_date'])) {
97 $query->_select['event_end_date'] = "civicrm_event.end_date as event_end_date";
98 $query->_element['event_end_date'] = 1;
99 }
100
101 //event type
102 if (!empty($query->_returnProperties['event_type'])) {
103 $query->_select['event_type'] = "event_type.label as event_type";
104 $query->_element['event_type'] = 1;
105 $query->_tables['event_type'] = 1;
106 $query->_whereTables['event_type'] = 1;
107 }
108
109 if (!empty($query->_returnProperties['event_type_id'])) {
110 $query->_select['event_type_id'] = "civicrm_event.event_type_id as event_type_id";
111 $query->_element['event_type_id'] = 1;
112 $query->_tables['civicrm_event'] = 1;
113 $query->_whereTables['civicrm_event'] = 1;
114 }
115
116 //add status_id
117 if (!empty($query->_returnProperties['participant_status_id'])) {
118 $query->_select['participant_status_id'] = "civicrm_participant.status_id as participant_status_id";
119 $query->_element['participant_status_id'] = 1;
120 $query->_tables['civicrm_participant'] = 1;
121 $query->_whereTables['civicrm_participant'] = 1;
122 }
123
124 // get particupant_status label
125 if (!empty($query->_returnProperties['participant_status'])) {
126 $query->_select['participant_status'] = "participant_status.label as participant_status";
127 $query->_element['participant_status'] = 1;
128 $query->_tables['participant_status'] = 1;
129 $query->_whereTables['civicrm_participant'] = 1;
130 }
131
132 //add participant_role_id
133 if (!empty($query->_returnProperties['participant_role_id'])) {
134 $query->_select['participant_role_id'] = "civicrm_participant.role_id as participant_role_id";
135 $query->_element['participant_role_id'] = 1;
136 $query->_tables['civicrm_participant'] = 1;
137 $query->_whereTables['civicrm_participant'] = 1;
138 $query->_pseudoConstantsSelect['participant_role_id'] = [
139 'pseudoField' => 'participant_role_id',
140 'idCol' => 'participant_role_id',
141 ];
142 }
143
144 //add participant_role
145 if (!empty($query->_returnProperties['participant_role'])) {
146 $query->_select['participant_role'] = "civicrm_participant.role_id as participant_role";
147 $query->_element['participant_role'] = 1;
148 $query->_tables['participant_role'] = 1;
149 $query->_whereTables['civicrm_participant'] = 1;
150 $query->_pseudoConstantsSelect['participant_role'] = [
151 'pseudoField' => 'participant_role',
152 'idCol' => 'participant_role',
153 ];
154 }
155
156 //add register date
157 if (!empty($query->_returnProperties['participant_register_date'])) {
158 $query->_select['participant_register_date'] = "civicrm_participant.register_date as participant_register_date";
159 $query->_element['participant_register_date'] = 1;
160 }
161
162 //add source
163 if (!empty($query->_returnProperties['participant_source'])) {
164 $query->_select['participant_source'] = "civicrm_participant.source as participant_source";
165 $query->_element['participant_source'] = 1;
166 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
167 }
168
169 //participant note
170 if (!empty($query->_returnProperties['participant_note'])) {
171 $query->_select['participant_note'] = "participant_note.note as participant_note";
172 $query->_element['participant_note'] = 1;
173 $query->_tables['participant_note'] = 1;
174 $query->_whereTables['participant_note'] = 1;
175 }
176
177 if (!empty($query->_returnProperties['participant_is_pay_later'])) {
178 $query->_select['participant_is_pay_later'] = "civicrm_participant.is_pay_later as participant_is_pay_later";
179 $query->_element['participant_is_pay_later'] = 1;
180 }
181
182 if (!empty($query->_returnProperties['participant_is_test'])) {
183 $query->_select['participant_is_test'] = "civicrm_participant.is_test as participant_is_test";
184 $query->_element['participant_is_test'] = 1;
185 }
186
187 if (!empty($query->_returnProperties['participant_registered_by_id'])) {
188 $query->_select['participant_registered_by_id'] = "civicrm_participant.registered_by_id as participant_registered_by_id";
189 $query->_element['participant_registered_by_id'] = 1;
190 }
191
192 // get discount name
193 if (!empty($query->_returnProperties['participant_discount_name'])) {
194 $query->_select['participant_discount_name'] = "discount_name.title as participant_discount_name";
195 $query->_element['participant_discount_name'] = 1;
196 $query->_tables['civicrm_discount'] = 1;
197 $query->_tables['participant_discount_name'] = 1;
198 $query->_whereTables['civicrm_discount'] = 1;
199 $query->_whereTables['participant_discount_name'] = 1;
200 }
201
202 //carry campaign id to selectors.
203 if (!empty($query->_returnProperties['participant_campaign_id'])) {
204 $query->_select['participant_campaign_id'] = 'civicrm_participant.campaign_id as participant_campaign_id';
205 $query->_element['participant_campaign_id'] = 1;
206 }
207 }
208 }
209
210 /**
211 * Get event related where clauses.
212 *
213 * @param \CRM_Contact_BAO_Query $query
214 */
215 public static function where(&$query) {
216 foreach (array_keys($query->_params) as $id) {
217 if (empty($query->_params[$id][0])) {
218 continue;
219 }
220 if (substr($query->_params[$id][0], 0, 6) == 'event_' ||
221 substr($query->_params[$id][0], 0, 12) == 'participant_'
222 ) {
223 if ($query->_mode == CRM_Contact_BAO_Query::MODE_CONTACTS) {
224 $query->_useDistinct = TRUE;
225 }
226 self::whereClauseSingle($query->_params[$id], $query);
227 }
228 }
229 }
230
231 /**
232 * @param $values
233 * @param \CRM_Contact_BAO_Query $query
234 *
235 * @throws \CRM_Core_Exception
236 */
237 public static function whereClauseSingle(&$values, &$query) {
238 $checkPermission = empty($query->_skipPermission);
239 list($name, $op, $value, $grouping, $wildcard) = $values;
240 $fields = array_merge(CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields());
241 $fieldSpec = $fields[$values[0]] ?? [];
242
243 switch ($name) {
244 case 'event_low':
245 case 'event_high':
246 $query->dateQueryBuilder($values,
247 'civicrm_event', 'event', 'start_date', ts('Event Active On'), TRUE, 'YmdHis', 'end_date'
248 );
249 return;
250
251 case 'event_start_date_low':
252 case 'event_start_date_high':
253 $query->dateQueryBuilder($values,
254 'civicrm_event', 'event_start_date', 'start_date', 'Start Date'
255 );
256 return;
257
258 case 'event_end_date_low':
259 case 'event_end_date_high':
260 $query->dateQueryBuilder($values,
261 'civicrm_event', 'event_end_date', 'end_date', 'End Date'
262 );
263 return;
264
265 case 'event_include_repeating_events':
266 /**
267 * Include Repeating Events
268 */
269 //Get parent of this event
270 $exEventId = '';
271 if ($query->_where[$grouping]) {
272 foreach ($query->_where[$grouping] as $key => $val) {
273 if (strstr($val, 'civicrm_event.id =')) {
274 $exEventId = $val;
275 $extractEventId = explode(" ", $val);
276 $value = $extractEventId[2];
277 $where = $query->_where[$grouping][$key];
278 }
279 elseif (strstr($val, 'civicrm_event.id IN')) {
280 //extract the first event id if multiple events are selected
281 preg_match('/civicrm_event.id IN \(\"(\d+)/', $val, $matches);
282 $value = $matches[1];
283 $where = $query->_where[$grouping][$key];
284 }
285 }
286 if ($exEventId) {
287 $extractEventId = explode(" ", $exEventId);
288 $value = $extractEventId[2];
289 }
290 elseif (!empty($matches[1])) {
291 $value = $matches[1];
292 }
293 $where = $query->_where[$grouping][$key];
294 }
295 $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event');
296 if ($thisEventHasParent) {
297 $getAllConnections = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($thisEventHasParent, 'civicrm_event');
298 $allEventIds = [];
299 foreach ($getAllConnections as $key => $val) {
300 $allEventIds[] = $val['id'];
301 }
302 if (!empty($allEventIds)) {
303 $op = "IN";
304 $value = "(" . implode(",", $allEventIds) . ")";
305 }
306 }
307 $query->_where[$grouping][] = "{$where} OR civicrm_event.id $op {$value}";
308 $query->_qill[$grouping][] = ts('Include Repeating Events');
309 $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
310 return;
311
312 case 'participant_is_test':
313 $key = array_search('civicrm_participant.is_test = 0', $query->_where[$grouping]);
314 if (!empty($key)) {
315 unset($query->_where[$grouping][$key]);
316 }
317 case 'participant_test':
318 // We dont want to include all tests for sql OR CRM-7827
319 if (!$value || $query->getOperator() != 'OR') {
320 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_test",
321 $op,
322 $value,
323 "Boolean"
324 );
325
326 $isTest = $value ? ts('a Test') : ts('not a Test');
327 $query->_qill[$grouping][] = ts("Participant is %1", [1 => $isTest]);
328 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
329 }
330 return;
331
332 case 'participant_fee_id':
333 $labels = [];
334 foreach ($value as $val) {
335 $labels[] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
336 }
337 $query->_where[$grouping][] = "civicrm_line_item.price_field_value_id IN (" . implode(', ', $value) . ")";
338 $query->_qill[$grouping][] = ts("Fee level") . " IN " . implode(', ', $labels);
339 $query->_tables['civicrm_participant'] = $query->_tables['civicrm_line_item'] = $query->_whereTables['civicrm_line_item'] = 1;
340 return;
341
342 case 'participant_fee_amount_high':
343 case 'participant_fee_amount_low':
344 $query->numberRangeBuilder($values,
345 'civicrm_participant', 'participant_fee_amount', 'fee_amount', 'Fee Amount'
346 );
347 return;
348
349 case 'participant_status_id':
350 $query->handleWhereFromMetadata($fieldSpec, $name, $value, $op);
351 return;
352
353 case 'participant_status':
354 case 'participant_source':
355 case 'participant_id':
356 case 'participant_contact_id':
357 case 'participant_is_pay_later':
358 case 'participant_fee_amount':
359 case 'participant_fee_level':
360 case 'participant_campaign_id':
361 case 'participant_registered_by_id':
362
363 $qillName = $name;
364 if (in_array($name, [
365 'participant_source',
366 'participant_id',
367 'participant_contact_id',
368 'participant_fee_amount',
369 'participant_fee_level',
370 'participant_is_pay_later',
371 'participant_campaign_id',
372 'participant_registered_by_id',
373 ])) {
374 $name = str_replace('participant_', '', $name);
375 if ($name == 'is_pay_later') {
376 $qillName = $name;
377 }
378 }
379 elseif ($name == 'participant_status') {
380 $name = 'status_id';
381 }
382
383 $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
384 $tableName = empty($tableName) ? 'civicrm_participant' : $tableName;
385 if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
386 $op = key($value);
387 $value = $value[$op];
388 }
389 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType);
390
391 list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op);
392 $query->_qill[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
393 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
394 return;
395
396 case 'participant_role':
397 case 'participant_role_id':
398 $qillName = $name;
399 $name = 'role_id';
400
401 $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
402 $tableName = empty($tableName) ? 'civicrm_participant' : $tableName;
403 if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
404 $op = key($value);
405 $value = $value[$op];
406 }
407 if (!strstr($op, 'NULL') && !strstr($op, 'EMPTY') && !strstr($op, 'LIKE')) {
408 $regexOp = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP';
409 $regexp = "([[:cntrl:]]|^)" . implode('([[:cntrl:]]|$)|([[:cntrl:]]|^)', (array) $value) . "([[:cntrl:]]|$)";
410 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.$name", $regexOp, $regexp, 'String');
411 }
412 else {
413 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType);
414 }
415
416 list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op);
417 $query->_qill[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
418 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
419 return;
420
421 case 'participant_register_date':
422 case 'participant_register_date_high':
423 case 'participant_register_date_low':
424 $query->dateQueryBuilder($values,
425 'civicrm_participant', 'participant_register_date', 'register_date', 'Register Date'
426 );
427 return;
428
429 case 'event_id':
430 case 'participant_event_id':
431 $name = str_replace('participant_', '', $name);
432 case 'event_is_public':
433 case 'event_type_id':
434 case 'event_title':
435 $qillName = $name;
436 if (in_array($name, [
437 'event_id',
438 'event_title',
439 'event_is_public',
440 ])) {
441 $name = str_replace('event_', '', $name);
442 }
443 $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
444
445 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.$name", $op, $value, $dataType);
446 $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
447 if (!array_key_exists($qillName, $fields)) {
448 break;
449 }
450 list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op, ['check_permission' => $checkPermission]);
451 $query->_qill[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
452 return;
453
454 case 'participant_note':
455 $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
456 $query->_tables['participant_note'] = $query->_whereTables['participant_note'] = 1;
457 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('participant_note.note', $op, $value, 'String');
458 $query->_qill[$grouping][] = ts('%1 %2 %3', [1 => $fields[$name]['title'], 2 => $op, 3 => $value]);
459 break;
460 }
461 }
462
463 /**
464 * @param string $name
465 * @param $mode
466 * @param $side
467 *
468 * @return null|string
469 */
470 public static function from($name, $mode, $side) {
471 $from = NULL;
472 switch ($name) {
473 case 'civicrm_participant':
474 $from = ' LEFT JOIN civicrm_participant ON civicrm_participant.contact_id = contact_a.id ';
475 break;
476
477 case 'civicrm_event':
478 //CRM-17121
479 $from = ' LEFT JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id ';
480 break;
481
482 case 'event_type':
483 $from = " $side JOIN civicrm_option_group option_group_event_type ON (option_group_event_type.name = 'event_type')";
484 $from .= " $side JOIN civicrm_option_value event_type ON (civicrm_event.event_type_id = event_type.value AND option_group_event_type.id = event_type.option_group_id ) ";
485 break;
486
487 case 'participant_note':
488 $from .= " $side JOIN civicrm_note participant_note ON ( participant_note.entity_table = 'civicrm_participant' AND
489 civicrm_participant.id = participant_note.entity_id )";
490 break;
491
492 case 'participant_status':
493 $from .= " $side JOIN civicrm_participant_status_type participant_status ON (civicrm_participant.status_id = participant_status.id) ";
494 break;
495
496 case 'participant_role':
497 $from = " $side JOIN civicrm_option_group option_group_participant_role ON (option_group_participant_role.name = 'participant_role')";
498 $from .= " $side JOIN civicrm_option_value participant_role ON ((civicrm_participant.role_id = participant_role.value OR SUBSTRING_INDEX(role_id,'\ 1', 1) = participant_role.value)
499 AND option_group_participant_role.id = participant_role.option_group_id ) ";
500 break;
501
502 case 'participant_discount_name':
503 $from = " $side JOIN civicrm_discount discount ON ( civicrm_participant.discount_id = discount.id )";
504 $from .= " $side JOIN civicrm_option_group discount_name ON ( discount_name.id = discount.price_set_id ) ";
505 break;
506
507 case 'civicrm_line_item':
508 $from .= " $side JOIN civicrm_line_item ON civicrm_line_item.entity_id = civicrm_participant.id AND civicrm_line_item.entity_table = 'civicrm_participant'";
509 break;
510 }
511 return $from;
512 }
513
514 /**
515 * @param $mode
516 * @param bool $includeCustomFields
517 *
518 * @return array|null
519 */
520 public static function defaultReturnProperties(
521 $mode,
522 $includeCustomFields = TRUE
523 ) {
524 $properties = NULL;
525 if ($mode & CRM_Contact_BAO_Query::MODE_EVENT) {
526 $properties = [
527 'contact_type' => 1,
528 'contact_sub_type' => 1,
529 'sort_name' => 1,
530 'display_name' => 1,
531 'event_id' => 1,
532 'event_title' => 1,
533 'event_start_date' => 1,
534 'event_end_date' => 1,
535 'event_type' => 1,
536 'participant_id' => 1,
537 'participant_status' => 1,
538 'participant_status_id' => 1,
539 'participant_role' => 1,
540 'participant_role_id' => 1,
541 'participant_note' => 1,
542 'participant_register_date' => 1,
543 'participant_source' => 1,
544 'participant_fee_level' => 1,
545 'participant_is_test' => 1,
546 'participant_is_pay_later' => 1,
547 'participant_fee_amount' => 1,
548 'participant_discount_name' => 1,
549 'participant_fee_currency' => 1,
550 'participant_registered_by_id' => 1,
551 'participant_campaign_id' => 1,
552 ];
553
554 if ($includeCustomFields) {
555 // also get all the custom participant properties
556 $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Participant');
557 if (!empty($fields)) {
558 foreach ($fields as $name => $dontCare) {
559 $properties[$name] = 1;
560 }
561 }
562 }
563 }
564
565 return $properties;
566 }
567
568 /**
569 * Get the metadata for fields to be included on the grant search form.
570 *
571 * @throws \CiviCRM_API3_Exception
572 */
573 public static function getSearchFieldMetadata() {
574 $fields = [
575 'participant_status_id',
576 'participant_register_date',
577 // Super-weird but we have to make it work.....
578 'event',
579 ];
580 $metadata = civicrm_api3('Participant', 'getfields', [])['values'];
581 $metadata['event'] = self::getPseudoEventDateFieldMetadata();
582 return array_intersect_key($metadata, array_flip($fields));
583 }
584
585 /**
586 * Build the event search form.
587 *
588 * @param \CRM_Event_Form_Search $form
589 *
590 * @throws \CiviCRM_API3_Exception
591 * @throws \CRM_Core_Exception
592 */
593 public static function buildSearchForm(&$form) {
594 $form->addSearchFieldMetadata(['Participant' => self::getSearchFieldMetadata()]);
595 $form->addFormFieldsFromMetadata();
596 $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee',
597 "reset=1",
598 FALSE, NULL, FALSE
599 );
600
601 $form->assign('dataURLEventFee', $dataURLEventFee);
602
603 $form->addEntityRef('event_id', ts('Event Name'), [
604 'entity' => 'Event',
605 'placeholder' => ts('- any -'),
606 'multiple' => 1,
607 'select' => ['minimumInputLength' => 0],
608 ]);
609 $form->addEntityRef('event_type_id', ts('Event Type'), [
610 'entity' => 'OptionValue',
611 'placeholder' => ts('- any -'),
612 'select' => ['minimumInputLength' => 0],
613 'api' => [
614 'params' => ['option_group_id' => 'event_type'],
615 ],
616 ]);
617 $obj = new CRM_Report_Form_Event_ParticipantListing();
618 $form->add('select', 'participant_fee_id',
619 ts('Fee Level'),
620 $obj->getPriceLevels(),
621 FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')]
622 );
623
624 $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', [1 => '<em>%1</em>']));
625
626 $form->addSelect('participant_role_id',
627 [
628 'entity' => 'participant',
629 'label' => ts('Participant Role'),
630 'multiple' => 'multiple',
631 'option_url' => NULL,
632 'placeholder' => ts('- any -'),
633 ]
634 );
635
636 $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE);
637 $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE);
638 $form->addElement('text', 'participant_fee_amount_low', ts('From'), ['size' => 8, 'maxlength' => 8]);
639 $form->addElement('text', 'participant_fee_amount_high', ts('To'), ['size' => 8, 'maxlength' => 8]);
640
641 $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money');
642 $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money');
643
644 self::addCustomFormFields($form, ['Participant', 'Event']);
645
646 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id');
647
648 $form->assign('validCiviEvent', TRUE);
649 $form->setDefaults(['participant_test' => 0]);
650 }
651
652 /**
653 * @param $tables
654 */
655 public static function tableNames(&$tables) {
656 //add participant table
657 if (!empty($tables['civicrm_event'])) {
658 $tables = array_merge(['civicrm_participant' => 1], $tables);
659 }
660 }
661
662 /**
663 * Get metadata from pseudo search field 'event'.
664 *
665 * @return array
666 */
667 protected static function getPseudoEventDateFieldMetadata(): array {
668 return [
669 'name' => 'event',
670 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
671 'title' => ts('Event Active On'),
672 'table_name' => 'civicrm_event',
673 'where' => 'civicrm_event.start_date',
674 'where_end' => 'civicrm_event.end_date',
675 'html' => ['type' => 'SelectDate', 'formatType' => 'activityDateTime'],
676 ];
677 }
678
679 }