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