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