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