Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | class CRM_Event_BAO_Query { | |
37 | ||
38 | static function &getFields() { | |
39 | $fields = array(); | |
40 | $fields = array_merge($fields, CRM_Event_DAO_Event::import()); | |
41 | $fields = array_merge($fields, self::getParticipantFields()); | |
42 | $fields = array_merge($fields, CRM_Core_DAO_Discount::export()); | |
43 | ||
44 | return $fields; | |
45 | } | |
46 | ||
47 | static function &getParticipantFields() { | |
48 | $fields = CRM_Event_BAO_Participant::importableFields('Individual', TRUE, TRUE); | |
49 | return $fields; | |
50 | } | |
51 | ||
52 | /** | |
53 | * build select for CiviEvent | |
54 | * | |
55 | * @return void | |
56 | * @access public | |
57 | */ | |
58 | static function select(&$query) { | |
59 | if (($query->_mode & CRM_Contact_BAO_Query::MODE_EVENT) || | |
60 | CRM_Contact_BAO_Query::componentPresent($query->_returnProperties, 'participant_') | |
61 | ) { | |
62 | $query->_select['participant_id'] = "civicrm_participant.id as participant_id"; | |
63 | $query->_element['participant_id'] = 1; | |
64 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
65 | ||
66 | //add fee level | |
67 | if (CRM_Utils_Array::value('participant_fee_level', $query->_returnProperties)) { | |
68 | $query->_select['participant_fee_level'] = "civicrm_participant.fee_level as participant_fee_level"; | |
69 | $query->_element['participant_fee_level'] = 1; | |
70 | } | |
71 | ||
72 | //add fee amount | |
73 | if (CRM_Utils_Array::value('participant_fee_amount', $query->_returnProperties)) { | |
74 | $query->_select['participant_fee_amount'] = "civicrm_participant.fee_amount as participant_fee_amount"; | |
75 | $query->_element['participant_fee_amount'] = 1; | |
76 | } | |
77 | ||
78 | //add fee currency | |
79 | if (CRM_Utils_Array::value('participant_fee_currency', $query->_returnProperties)) { | |
80 | $query->_select['participant_fee_currency'] = "civicrm_participant.fee_currency as participant_fee_currency"; | |
81 | $query->_element['participant_fee_currency'] = 1; | |
82 | } | |
83 | ||
84 | //add event title also if event id is select | |
85 | if (CRM_Utils_Array::value('event_id', $query->_returnProperties) || | |
86 | CRM_Utils_Array::value('event_title', $query->_returnProperties) | |
87 | ) { | |
88 | $query->_select['event_id'] = "civicrm_event.id as event_id"; | |
89 | $query->_select['event_title'] = "civicrm_event.title as event_title"; | |
90 | $query->_element['event_id'] = 1; | |
91 | $query->_element['event_title'] = 1; | |
92 | $query->_tables['civicrm_event'] = 1; | |
93 | $query->_whereTables['civicrm_event'] = 1; | |
94 | } | |
95 | ||
96 | //add start date / end date | |
97 | if (CRM_Utils_Array::value('event_start_date', $query->_returnProperties)) { | |
98 | $query->_select['event_start_date'] = "civicrm_event.start_date as event_start_date"; | |
99 | $query->_element['event_start_date'] = 1; | |
100 | } | |
101 | ||
102 | if (CRM_Utils_Array::value('event_end_date', $query->_returnProperties)) { | |
103 | $query->_select['event_end_date'] = "civicrm_event.end_date as event_end_date"; | |
104 | $query->_element['event_end_date'] = 1; | |
105 | } | |
106 | ||
107 | //event type | |
108 | if (CRM_Utils_Array::value('event_type', $query->_returnProperties)) { | |
109 | $query->_select['event_type'] = "event_type.label as event_type"; | |
110 | $query->_element['event_type'] = 1; | |
111 | $query->_tables['event_type'] = 1; | |
112 | $query->_whereTables['event_type'] = 1; | |
113 | } | |
114 | ||
115 | if (CRM_Utils_Array::value('event_type_id', $query->_returnProperties)) { | |
116 | $query->_select['event_type_id'] = "event_type.id as event_type_id"; | |
117 | $query->_element['event_type_id'] = 1; | |
118 | $query->_tables['event_type'] = 1; | |
119 | $query->_whereTables['event_type'] = 1; | |
120 | } | |
121 | ||
122 | //add status and status_id | |
123 | if (CRM_Utils_Array::value('participant_status', $query->_returnProperties) || | |
124 | CRM_Utils_Array::value('participant_status_id', $query->_returnProperties) | |
125 | ) { | |
126 | $query->_select['participant_status'] = "participant_status.label as participant_status"; | |
127 | $query->_select['participant_status_id'] = "participant_status.id as participant_status_id"; | |
128 | $query->_element['participant_status_id'] = 1; | |
129 | $query->_element['participant_status'] = 1; | |
130 | $query->_tables['civicrm_participant'] = 1; | |
131 | $query->_tables['participant_status'] = 1; | |
132 | $query->_whereTables['civicrm_participant'] = 1; | |
133 | $query->_whereTables['participant_status'] = 1; | |
134 | } | |
135 | ||
136 | //add role | |
137 | if (CRM_Utils_Array::value('participant_role', $query->_returnProperties)) { | |
138 | $query->_select['participant_role'] = "participant_role.label as participant_role"; | |
139 | $query->_element['participant_role'] = 1; | |
140 | $query->_tables['civicrm_participant'] = 1; | |
141 | $query->_tables['participant_role'] = 1; | |
142 | $query->_whereTables['civicrm_participant'] = 1; | |
143 | $query->_whereTables['participant_role'] = 1; | |
144 | } | |
145 | ||
146 | if (CRM_Utils_Array::value('participant_role_id', $query->_returnProperties)) { | |
147 | $query->_select['participant_role_id'] = "civicrm_participant.role_id as participant_role_id"; | |
148 | $query->_element['participant_role_id'] = 1; | |
149 | $query->_tables['civicrm_participant'] = 1; | |
150 | $query->_tables['participant_role'] = 1; | |
151 | $query->_whereTables['civicrm_participant'] = 1; | |
152 | $query->_whereTables['participant_role'] = 1; | |
153 | } | |
154 | ||
155 | //add register date | |
156 | if (CRM_Utils_Array::value('participant_register_date', $query->_returnProperties)) { | |
157 | $query->_select['participant_register_date'] = "civicrm_participant.register_date as participant_register_date"; | |
158 | $query->_element['participant_register_date'] = 1; | |
159 | } | |
160 | ||
161 | //add source | |
162 | if (CRM_Utils_Array::value('participant_source', $query->_returnProperties)) { | |
163 | $query->_select['participant_source'] = "civicrm_participant.source as participant_source"; | |
164 | $query->_element['participant_source'] = 1; | |
165 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
166 | } | |
167 | ||
168 | //participant note | |
169 | if (CRM_Utils_Array::value('participant_note', $query->_returnProperties)) { | |
170 | $query->_select['participant_note'] = "civicrm_note.note as participant_note"; | |
171 | $query->_element['participant_note'] = 1; | |
172 | $query->_tables['participant_note'] = 1; | |
173 | $query->_whereTables['civicrm_note'] = 1; | |
174 | } | |
175 | ||
176 | if (CRM_Utils_Array::value('participant_is_pay_later', $query->_returnProperties)) { | |
177 | $query->_select['participant_is_pay_later'] = "civicrm_participant.is_pay_later as participant_is_pay_later"; | |
178 | $query->_element['participant_is_pay_later'] = 1; | |
179 | } | |
180 | ||
181 | if (CRM_Utils_Array::value('participant_is_test', $query->_returnProperties)) { | |
182 | $query->_select['participant_is_test'] = "civicrm_participant.is_test as participant_is_test"; | |
183 | $query->_element['participant_is_test'] = 1; | |
184 | } | |
185 | ||
186 | if (CRM_Utils_Array::value('participant_registered_by_id', $query->_returnProperties)) { | |
187 | $query->_select['participant_registered_by_id'] = "civicrm_participant.registered_by_id as participant_registered_by_id"; | |
188 | $query->_element['participant_registered_by_id'] = 1; | |
189 | } | |
190 | ||
191 | // get discount name | |
192 | if (CRM_Utils_Array::value('participant_discount_name', $query->_returnProperties)) { | |
193 | $query->_select['participant_discount_name'] = "discount_name.title as participant_discount_name"; | |
194 | $query->_element['participant_discount_name'] = 1; | |
195 | $query->_tables['civicrm_discount'] = 1; | |
196 | $query->_tables['participant_discount_name'] = 1; | |
197 | $query->_whereTables['civicrm_discount'] = 1; | |
198 | $query->_whereTables['participant_discount_name'] = 1; | |
199 | } | |
200 | ||
201 | //carry campaign id to selectors. | |
202 | if (CRM_Utils_Array::value('participant_campaign_id', $query->_returnProperties)) { | |
203 | $query->_select['participant_campaign_id'] = 'civicrm_participant.campaign_id as participant_campaign_id'; | |
204 | $query->_element['participant_campaign_id'] = 1; | |
205 | } | |
206 | } | |
207 | } | |
208 | ||
209 | static function where(&$query) { | |
28c666be | 210 | $grouping = NULL; |
6a488035 TO |
211 | foreach (array_keys($query->_params) as $id) { |
212 | if (!CRM_Utils_Array::value(0, $query->_params[$id])) { | |
213 | continue; | |
214 | } | |
215 | if (substr($query->_params[$id][0], 0, 6) == 'event_' || | |
216 | substr($query->_params[$id][0], 0, 12) == 'participant_' | |
217 | ) { | |
218 | if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { | |
219 | $query->_useDistinct = TRUE; | |
220 | } | |
6a488035 TO |
221 | $grouping = $query->_params[$id][3]; |
222 | self::whereClauseSingle($query->_params[$id], $query); | |
223 | } | |
224 | } | |
6a488035 TO |
225 | } |
226 | ||
227 | static function whereClauseSingle(&$values, &$query) { | |
228 | list($name, $op, $value, $grouping, $wildcard) = $values; | |
229 | switch ($name) { | |
230 | case 'event_start_date_low': | |
231 | case 'event_start_date_high': | |
232 | $query->dateQueryBuilder($values, | |
233 | 'civicrm_event', 'event_start_date', 'start_date', 'Start Date' | |
234 | ); | |
235 | return; | |
236 | ||
237 | case 'event_end_date_low': | |
238 | case 'event_end_date_high': | |
239 | $query->dateQueryBuilder($values, | |
240 | 'civicrm_event', 'event_end_date', 'end_date', 'End Date' | |
241 | ); | |
242 | return; | |
243 | ||
244 | case 'event_id': | |
245 | $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; | |
246 | $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, 'title'); | |
247 | $query->_qill[$grouping][] = ts('Event') . " $op {$eventTitle}"; | |
248 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
249 | return; | |
250 | ||
251 | case 'event_type_id': | |
252 | ||
253 | $eventTypes = CRM_Core_OptionGroup::values("event_type"); | |
254 | $query->_where[$grouping][] = "civicrm_participant.event_id = civicrm_event.id and civicrm_event.event_type_id = '{$value}'"; | |
255 | $query->_qill[$grouping][] = ts('Event Type - %1', array(1 => $eventTypes[$value])); | |
256 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
257 | return; | |
258 | ||
259 | case 'participant_test': | |
28c666be CW |
260 | // We dont want to include all tests for sql OR CRM-7827 |
261 | if (!$value || $query->getOperator() != 'OR') { | |
262 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_test", | |
263 | $op, | |
264 | $value, | |
265 | "Boolean" | |
266 | ); | |
267 | if ($value) { | |
268 | $query->_qill[$grouping][] = ts("Participant is a Test"); | |
269 | } | |
270 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
6a488035 | 271 | } |
6a488035 TO |
272 | return; |
273 | ||
274 | case 'participant_fee_id': | |
9da8dc8c | 275 | $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $value, 'label'); |
6a488035 TO |
276 | $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); |
277 | if ($value) { | |
278 | $query->_where[$grouping][] = "civicrm_participant.fee_level $op '$feeLabel'"; | |
279 | $query->_qill[$grouping][] = ts("Fee level") . " $op $feeLabel"; | |
280 | } | |
281 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
282 | return; | |
283 | ||
284 | case 'participant_fee_amount': | |
285 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.fee_amount", | |
286 | $op, | |
287 | $value, | |
288 | "Money" | |
289 | ); | |
290 | if ($value) { | |
291 | $query->_qill[$grouping][] = ts("Fee Amount") . " $op $value"; | |
292 | } | |
293 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
294 | return; | |
295 | ||
296 | case 'participant_fee_amount_high': | |
297 | case 'participant_fee_amount_low': | |
298 | $query->numberRangeBuilder($values, | |
299 | 'civicrm_participant', 'participant_fee_amount', 'fee_amount', 'Fee Amount' | |
300 | ); | |
301 | return; | |
302 | ||
303 | case 'participant_pay_later': | |
304 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_pay_later", | |
305 | $op, | |
306 | $value, | |
307 | "Boolean" | |
308 | ); | |
309 | $query->_qill[$grouping][] = $value ? ts("Participant is Pay Later") : ts("Participant is not Pay Later"); | |
310 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
311 | return; | |
312 | ||
313 | case 'participant_status': | |
314 | case 'participant_status_id': | |
315 | $val = array(); | |
316 | if (is_array($value)) { | |
317 | foreach ($value as $k => $v) { | |
318 | if ($v) { | |
319 | $val[$k] = $k; | |
320 | } | |
321 | } | |
322 | $status = implode(',', $val); | |
323 | } | |
324 | else { | |
325 | $status = $value; | |
326 | } | |
327 | ||
328 | if (count($val) > 1) { | |
329 | $op = 'IN'; | |
330 | $status = "({$status})"; | |
331 | } | |
332 | ||
333 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(); | |
334 | $names = array(); | |
335 | ||
336 | if (!empty($val)) { | |
337 | foreach ($val as $id => $dontCare) { | |
338 | $names[] = $statusTypes[$id]; | |
339 | } | |
340 | } | |
341 | else { | |
342 | $names[] = $statusTypes[$value]; | |
343 | } | |
344 | ||
345 | $query->_qill[$grouping][] = ts('Participant Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); | |
346 | ||
347 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.status_id", | |
348 | $op, | |
349 | $status, | |
350 | "Integer" | |
351 | ); | |
352 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
353 | return; | |
354 | ||
355 | case 'participant_role_id': | |
356 | $val = array(); | |
357 | if (is_array($value)) { | |
358 | foreach ($value as $k => $v) { | |
359 | if ($v) { | |
360 | $val[$k] = $k; | |
361 | } | |
362 | } | |
363 | } | |
364 | else { | |
365 | $val = array($value => 1); | |
366 | } | |
367 | ||
368 | $roleTypes = CRM_Event_PseudoConstant::participantRole(); | |
369 | ||
370 | $names = array(); | |
371 | foreach ($val as $id => $dontCare) { | |
372 | $names[] = $roleTypes[$id]; | |
373 | } | |
374 | ||
375 | if (!empty($names)) { | |
376 | $query->_qill[$grouping][] = | |
377 | ts('Participant Role %1', array(1 => $op)) . | |
378 | ' ' . | |
379 | implode(' ' . ts('or') . ' ', $names); | |
380 | $query->_where[$grouping][] = | |
381 | " civicrm_participant.role_id REGEXP '[[:<:]]" . | |
382 | implode('[[:>:]]|[[:<:]]', array_keys($val)) . | |
383 | "[[:>:]]' "; | |
384 | ||
385 | $query->_tables['civicrm_participant'] = | |
386 | $query->_whereTables['civicrm_participant'] = 1; | |
387 | } | |
388 | return; | |
389 | ||
390 | case 'participant_source': | |
391 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.source", | |
392 | $op, | |
393 | $value, | |
394 | "String" | |
395 | ); | |
396 | $query->_qill[$grouping][] = ts("Participant Source") . " $op $value"; | |
397 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
398 | return; | |
399 | ||
400 | case 'participant_register_date': | |
401 | $query->dateQueryBuilder($values, | |
402 | 'civicrm_participant', 'participant_register_date', 'register_date', 'Register Date' | |
403 | ); | |
404 | return; | |
405 | ||
406 | case 'participant_id': | |
407 | $query->_where[$grouping][] = "civicrm_participant.id $op $value"; | |
408 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
409 | return; | |
410 | ||
411 | case 'event_id': | |
412 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.id", | |
413 | $op, | |
414 | $value, | |
415 | "Integer" | |
416 | ); | |
417 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
418 | $title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, "title"); | |
419 | $query->_qill[$grouping][] = ts('Event') . " $op $value"; | |
420 | return; | |
421 | ||
422 | case 'participant_contact_id': | |
423 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.contact_id", | |
424 | $op, | |
425 | $value, | |
426 | "Integer" | |
427 | ); | |
428 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
429 | return; | |
430 | ||
431 | case 'event_is_public': | |
432 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.is_public", | |
433 | $op, | |
434 | $value, | |
435 | "Integer" | |
436 | ); | |
437 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
438 | return; | |
439 | ||
440 | case 'participant_campaign_id': | |
441 | $campParams = array( | |
442 | 'op' => $op, | |
443 | 'campaign' => $value, | |
444 | 'grouping' => $grouping, | |
445 | 'tableName' => 'civicrm_participant', | |
446 | ); | |
447 | CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); | |
448 | return; | |
449 | } | |
450 | } | |
451 | ||
452 | static function from($name, $mode, $side) { | |
453 | $from = NULL; | |
454 | switch ($name) { | |
455 | case 'civicrm_participant': | |
456 | $from = " LEFT JOIN civicrm_participant ON civicrm_participant.contact_id = contact_a.id "; | |
457 | break; | |
458 | ||
459 | case 'civicrm_event': | |
460 | $from = " INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id "; | |
461 | break; | |
462 | ||
463 | case 'event_type': | |
464 | $from = " $side JOIN civicrm_option_group option_group_event_type ON (option_group_event_type.name = 'event_type')"; | |
465 | $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 ) "; | |
466 | break; | |
467 | ||
468 | case 'participant_note': | |
469 | $from .= " $side JOIN civicrm_note ON ( civicrm_note.entity_table = 'civicrm_participant' AND | |
470 | civicrm_participant.id = civicrm_note.entity_id )"; | |
471 | break; | |
472 | ||
473 | case 'participant_status': | |
474 | $from .= " $side JOIN civicrm_participant_status_type participant_status ON (civicrm_participant.status_id = participant_status.id) "; | |
475 | break; | |
476 | ||
477 | case 'participant_role': | |
478 | $from = " $side JOIN civicrm_option_group option_group_participant_role ON (option_group_participant_role.name = 'participant_role')"; | |
479 | $from .= " $side JOIN civicrm_option_value participant_role ON (civicrm_participant.role_id = participant_role.value | |
480 | AND option_group_participant_role.id = participant_role.option_group_id ) "; | |
481 | break; | |
482 | ||
483 | case 'participant_discount_name': | |
484 | $from = " $side JOIN civicrm_discount discount ON ( civicrm_participant.discount_id = discount.id )"; | |
485 | $from .= " $side JOIN civicrm_option_group discount_name ON ( discount_name.id = discount.price_set_id ) "; | |
486 | break; | |
487 | } | |
488 | return $from; | |
489 | } | |
490 | ||
491 | /** | |
492 | * getter for the qill object | |
493 | * | |
494 | * @return string | |
495 | * @access public | |
496 | */ | |
497 | function qill() { | |
498 | return (isset($this->_qill)) ? $this->_qill : ""; | |
499 | } | |
500 | ||
501 | static function defaultReturnProperties($mode, | |
502 | $includeCustomFields = TRUE | |
503 | ) { | |
504 | $properties = NULL; | |
505 | if ($mode & CRM_Contact_BAO_Query::MODE_EVENT) { | |
506 | $properties = array( | |
507 | 'contact_type' => 1, | |
508 | 'contact_sub_type' => 1, | |
509 | 'sort_name' => 1, | |
510 | 'display_name' => 1, | |
511 | 'event_id' => 1, | |
512 | 'event_title' => 1, | |
513 | 'event_start_date' => 1, | |
514 | 'event_end_date' => 1, | |
515 | 'event_type' => 1, | |
516 | 'participant_id' => 1, | |
517 | 'participant_status' => 1, | |
518 | 'participant_role_id' => 1, | |
519 | 'participant_note' => 1, | |
520 | 'participant_register_date' => 1, | |
521 | 'participant_source' => 1, | |
522 | 'participant_fee_level' => 1, | |
523 | 'participant_is_test' => 1, | |
524 | 'participant_is_pay_later' => 1, | |
525 | 'participant_fee_amount' => 1, | |
526 | 'participant_discount_name' => 1, | |
527 | 'participant_fee_currency' => 1, | |
528 | 'participant_registered_by_id' => 1, | |
529 | 'participant_campaign_id' => 1, | |
530 | ); | |
531 | ||
532 | if ($includeCustomFields) { | |
533 | // also get all the custom participant properties | |
534 | $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Participant'); | |
535 | if (!empty($fields)) { | |
536 | foreach ($fields as $name => $dontCare) { | |
537 | $properties[$name] = 1; | |
538 | } | |
539 | } | |
540 | } | |
541 | } | |
542 | ||
543 | return $properties; | |
544 | } | |
545 | ||
546 | static function buildSearchForm(&$form) { | |
547 | $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event', | |
548 | "reset=1", | |
549 | FALSE, NULL, FALSE | |
550 | ); | |
551 | $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType', | |
552 | "reset=1", | |
553 | FALSE, NULL, FALSE | |
554 | ); | |
555 | $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', | |
556 | "reset=1", | |
557 | FALSE, NULL, FALSE | |
558 | ); | |
559 | ||
560 | $form->assign('dataURLEvent', $dataURLEvent); | |
561 | $form->assign('dataURLEventType', $dataURLEventType); | |
562 | $form->assign('dataURLEventFee', $dataURLEventFee); | |
563 | ||
564 | $eventId = &$form->add('text', 'event_name', ts('Event Name')); | |
565 | $eventType = &$form->add('text', 'event_type', ts('Event Type')); | |
566 | $participantFee = &$form->add('text', 'participant_fee_level', ts('Fee Level')); | |
567 | ||
568 | //elements for assigning value operation | |
569 | $eventNameId = &$form->add('hidden', 'event_id', '', array('id' => 'event_id')); | |
570 | $eventTypeId = &$form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id')); | |
571 | $participantFeeId = &$form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id')); | |
572 | ||
bc3f7f04 | 573 | CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); |
6a488035 TO |
574 | |
575 | $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); | |
576 | asort($status); | |
577 | foreach ($status as $id => $Name) { | |
578 | $form->_participantStatus = &$form->addElement('checkbox', "participant_status_id[$id]", NULL, $Name); | |
579 | } | |
580 | ||
581 | foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { | |
582 | $form->_participantRole = &$form->addElement('checkbox', "participant_role_id[$rId]", NULL, $rName); | |
583 | } | |
584 | ||
585 | $form->addYesNo('participant_test', ts('Participant is a Test?')); | |
586 | $form->addYesNo('participant_pay_later', ts('Participant is Pay Later?')); | |
587 | $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); | |
588 | $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); | |
589 | ||
590 | $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); | |
591 | $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); | |
592 | // add all the custom searchable fields | |
593 | $extends = array('Participant'); | |
594 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); | |
595 | if ($groupDetails) { | |
596 | $form->assign('participantGroupTree', $groupDetails); | |
597 | foreach ($groupDetails as $group) { | |
598 | foreach ($group['fields'] as $field) { | |
599 | $fieldId = $field['id']; | |
600 | $elementName = 'custom_' . $fieldId; | |
601 | CRM_Core_BAO_CustomField::addQuickFormElement($form, | |
602 | $elementName, | |
603 | $fieldId, | |
604 | FALSE, FALSE, TRUE | |
605 | ); | |
606 | } | |
607 | } | |
608 | } | |
609 | ||
610 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); | |
611 | ||
612 | $form->assign('validCiviEvent', TRUE); | |
613 | $form->setDefaults(array('participant_test' => 0)); | |
614 | } | |
615 | ||
616 | static function searchAction(&$row, $id) {} | |
617 | ||
618 | static function tableNames(&$tables) { | |
619 | //add participant table | |
620 | if (CRM_Utils_Array::value('civicrm_event', $tables)) { | |
621 | $tables = array_merge(array('civicrm_participant' => 1), $tables); | |
622 | } | |
623 | } | |
624 | } | |
625 |