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