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 | } | |
62933949 | 209 | |
6a488035 | 210 | |
0cf587a7 EM |
211 | /** |
212 | * @param $query | |
213 | */ | |
6a488035 | 214 | static function where(&$query) { |
28c666be | 215 | $grouping = NULL; |
6a488035 | 216 | foreach (array_keys($query->_params) as $id) { |
a7488080 | 217 | if (empty($query->_params[$id][0])) { |
6a488035 TO |
218 | continue; |
219 | } | |
220 | if (substr($query->_params[$id][0], 0, 6) == 'event_' || | |
221 | substr($query->_params[$id][0], 0, 12) == 'participant_' | |
222 | ) { | |
223 | if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { | |
224 | $query->_useDistinct = TRUE; | |
225 | } | |
6a488035 TO |
226 | $grouping = $query->_params[$id][3]; |
227 | self::whereClauseSingle($query->_params[$id], $query); | |
228 | } | |
229 | } | |
6a488035 TO |
230 | } |
231 | ||
0cf587a7 EM |
232 | /** |
233 | * @param $values | |
234 | * @param $query | |
235 | */ | |
6a488035 TO |
236 | static function whereClauseSingle(&$values, &$query) { |
237 | list($name, $op, $value, $grouping, $wildcard) = $values; | |
238 | switch ($name) { | |
239 | case 'event_start_date_low': | |
240 | case 'event_start_date_high': | |
241 | $query->dateQueryBuilder($values, | |
242 | 'civicrm_event', 'event_start_date', 'start_date', 'Start Date' | |
243 | ); | |
244 | return; | |
245 | ||
246 | case 'event_end_date_low': | |
247 | case 'event_end_date_high': | |
248 | $query->dateQueryBuilder($values, | |
249 | 'civicrm_event', 'event_end_date', 'end_date', 'End Date' | |
250 | ); | |
251 | return; | |
62933949 | 252 | |
6a488035 TO |
253 | case 'event_id': |
254 | $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; | |
255 | $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, 'title'); | |
256 | $query->_qill[$grouping][] = ts('Event') . " $op {$eventTitle}"; | |
257 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
258 | return; | |
62933949 | 259 | |
260 | case 'event_include_repeating_events': | |
261 | /** | |
262 | * Include Repeating Events | |
263 | */ | |
264 | //Get parent of this event | |
265 | $exEventId = ''; | |
a50a97b8 | 266 | if ($query->_where[$grouping]) { |
267 | foreach($query->_where[$grouping] as $key => $val) { | |
62933949 | 268 | if (strstr($val, 'civicrm_event.id =')) { |
269 | $exEventId = $val; | |
270 | $extractEventId = explode(" ", $val); | |
271 | $value = $extractEventId[2]; | |
272 | unset($query->_where[$grouping][$key]); | |
273 | } | |
274 | } | |
275 | $extractEventId = explode(" ", $exEventId); | |
276 | $value = $extractEventId[2]; | |
277 | unset($query->_where[$grouping][$key]); | |
278 | } | |
279 | $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event'); | |
a50a97b8 | 280 | if ($thisEventHasParent) { |
a99e6f73 | 281 | $getAllConnections = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($thisEventHasParent, 'civicrm_event'); |
282 | $allEventIds = array(); | |
a50a97b8 | 283 | foreach($getAllConnections as $key => $val) { |
a99e6f73 | 284 | $allEventIds[] = $val['id']; |
285 | } | |
a50a97b8 | 286 | if (!empty($allEventIds)) { |
62933949 | 287 | $op = "IN"; |
a99e6f73 | 288 | $value = "(".implode(",", $allEventIds).")"; |
62933949 | 289 | } |
290 | } | |
291 | $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; | |
292 | $query->_qill[$grouping][] = ts('Include Repeating Events (If Any) ') . " = TRUE"; | |
293 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
294 | return; | |
295 | ||
6a488035 TO |
296 | case 'event_type_id': |
297 | ||
298 | $eventTypes = CRM_Core_OptionGroup::values("event_type"); | |
299 | $query->_where[$grouping][] = "civicrm_participant.event_id = civicrm_event.id and civicrm_event.event_type_id = '{$value}'"; | |
300 | $query->_qill[$grouping][] = ts('Event Type - %1', array(1 => $eventTypes[$value])); | |
301 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
302 | return; | |
62933949 | 303 | |
6a488035 | 304 | case 'participant_test': |
28c666be CW |
305 | // We dont want to include all tests for sql OR CRM-7827 |
306 | if (!$value || $query->getOperator() != 'OR') { | |
307 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_test", | |
308 | $op, | |
309 | $value, | |
310 | "Boolean" | |
311 | ); | |
312 | if ($value) { | |
313 | $query->_qill[$grouping][] = ts("Participant is a Test"); | |
314 | } | |
315 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
6a488035 | 316 | } |
6a488035 TO |
317 | return; |
318 | ||
319 | case 'participant_fee_id': | |
9da8dc8c | 320 | $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $value, 'label'); |
6a488035 TO |
321 | $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); |
322 | if ($value) { | |
81d86b63 | 323 | $query->_where[$grouping][] = "civicrm_participant.fee_level LIKE '%$feeLabel%'"; |
324 | $query->_qill[$grouping][] = ts("Fee level") . " contains $feeLabel"; | |
6a488035 TO |
325 | } |
326 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
327 | return; | |
328 | ||
329 | case 'participant_fee_amount': | |
330 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.fee_amount", | |
331 | $op, | |
332 | $value, | |
333 | "Money" | |
334 | ); | |
335 | if ($value) { | |
336 | $query->_qill[$grouping][] = ts("Fee Amount") . " $op $value"; | |
337 | } | |
338 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
339 | return; | |
340 | ||
341 | case 'participant_fee_amount_high': | |
342 | case 'participant_fee_amount_low': | |
343 | $query->numberRangeBuilder($values, | |
344 | 'civicrm_participant', 'participant_fee_amount', 'fee_amount', 'Fee Amount' | |
345 | ); | |
346 | return; | |
347 | ||
348 | case 'participant_pay_later': | |
349 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_pay_later", | |
350 | $op, | |
351 | $value, | |
352 | "Boolean" | |
353 | ); | |
354 | $query->_qill[$grouping][] = $value ? ts("Participant is Pay Later") : ts("Participant is not Pay Later"); | |
355 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
356 | return; | |
357 | ||
358 | case 'participant_status': | |
359 | case 'participant_status_id': | |
360 | $val = array(); | |
361 | if (is_array($value)) { | |
362 | foreach ($value as $k => $v) { | |
363 | if ($v) { | |
364 | $val[$k] = $k; | |
365 | } | |
366 | } | |
367 | $status = implode(',', $val); | |
368 | } | |
369 | else { | |
370 | $status = $value; | |
371 | } | |
372 | ||
dbc6f6d6 | 373 | if (count($val) > 0) { |
6a488035 TO |
374 | $op = 'IN'; |
375 | $status = "({$status})"; | |
376 | } | |
377 | ||
378 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(); | |
379 | $names = array(); | |
380 | ||
381 | if (!empty($val)) { | |
382 | foreach ($val as $id => $dontCare) { | |
383 | $names[] = $statusTypes[$id]; | |
384 | } | |
385 | } | |
386 | else { | |
dbc6f6d6 | 387 | if (!empty($value)) { |
388 | $names[] = $statusTypes[$value]; | |
389 | } | |
6a488035 TO |
390 | } |
391 | ||
392 | $query->_qill[$grouping][] = ts('Participant Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); | |
393 | ||
394 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.status_id", | |
395 | $op, | |
396 | $status, | |
397 | "Integer" | |
398 | ); | |
399 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
400 | return; | |
401 | ||
62fd7fe8 | 402 | case 'participant_role': |
6a488035 TO |
403 | case 'participant_role_id': |
404 | $val = array(); | |
405 | if (is_array($value)) { | |
406 | foreach ($value as $k => $v) { | |
407 | if ($v) { | |
408 | $val[$k] = $k; | |
409 | } | |
410 | } | |
411 | } | |
412 | else { | |
413 | $val = array($value => 1); | |
414 | } | |
415 | ||
416 | $roleTypes = CRM_Event_PseudoConstant::participantRole(); | |
417 | ||
418 | $names = array(); | |
419 | foreach ($val as $id => $dontCare) { | |
dbc6f6d6 | 420 | if (!empty($roleTypes[$id]) ) { |
421 | $names[] = $roleTypes[$id]; | |
422 | } | |
6a488035 TO |
423 | } |
424 | ||
425 | if (!empty($names)) { | |
426 | $query->_qill[$grouping][] = | |
427 | ts('Participant Role %1', array(1 => $op)) . | |
428 | ' ' . | |
429 | implode(' ' . ts('or') . ' ', $names); | |
430 | $query->_where[$grouping][] = | |
431 | " civicrm_participant.role_id REGEXP '[[:<:]]" . | |
432 | implode('[[:>:]]|[[:<:]]', array_keys($val)) . | |
433 | "[[:>:]]' "; | |
434 | ||
435 | $query->_tables['civicrm_participant'] = | |
436 | $query->_whereTables['civicrm_participant'] = 1; | |
437 | } | |
438 | return; | |
439 | ||
440 | case 'participant_source': | |
441 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.source", | |
442 | $op, | |
443 | $value, | |
444 | "String" | |
445 | ); | |
446 | $query->_qill[$grouping][] = ts("Participant Source") . " $op $value"; | |
447 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
448 | return; | |
449 | ||
450 | case 'participant_register_date': | |
451 | $query->dateQueryBuilder($values, | |
452 | 'civicrm_participant', 'participant_register_date', 'register_date', 'Register Date' | |
453 | ); | |
454 | return; | |
455 | ||
456 | case 'participant_id': | |
59de5a50 EM |
457 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.id", |
458 | $op, | |
459 | $value, | |
460 | "Integer" | |
461 | ); | |
6a488035 TO |
462 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
463 | return; | |
464 | ||
465 | case 'event_id': | |
466 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.id", | |
467 | $op, | |
468 | $value, | |
469 | "Integer" | |
470 | ); | |
471 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
472 | $title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, "title"); | |
473 | $query->_qill[$grouping][] = ts('Event') . " $op $value"; | |
474 | return; | |
475 | ||
476 | case 'participant_contact_id': | |
477 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.contact_id", | |
478 | $op, | |
479 | $value, | |
480 | "Integer" | |
481 | ); | |
482 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; | |
483 | return; | |
484 | ||
485 | case 'event_is_public': | |
486 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.is_public", | |
487 | $op, | |
488 | $value, | |
489 | "Integer" | |
490 | ); | |
491 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; | |
492 | return; | |
493 | ||
494 | case 'participant_campaign_id': | |
495 | $campParams = array( | |
496 | 'op' => $op, | |
497 | 'campaign' => $value, | |
498 | 'grouping' => $grouping, | |
499 | 'tableName' => 'civicrm_participant', | |
500 | ); | |
501 | CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); | |
502 | return; | |
503 | } | |
504 | } | |
505 | ||
0cf587a7 EM |
506 | /** |
507 | * @param $name | |
508 | * @param $mode | |
509 | * @param $side | |
510 | * | |
511 | * @return null|string | |
512 | */ | |
6a488035 TO |
513 | static function from($name, $mode, $side) { |
514 | $from = NULL; | |
515 | switch ($name) { | |
516 | case 'civicrm_participant': | |
517 | $from = " LEFT JOIN civicrm_participant ON civicrm_participant.contact_id = contact_a.id "; | |
518 | break; | |
519 | ||
520 | case 'civicrm_event': | |
521 | $from = " INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id "; | |
522 | break; | |
523 | ||
524 | case 'event_type': | |
525 | $from = " $side JOIN civicrm_option_group option_group_event_type ON (option_group_event_type.name = 'event_type')"; | |
526 | $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 ) "; | |
527 | break; | |
528 | ||
529 | case 'participant_note': | |
530 | $from .= " $side JOIN civicrm_note ON ( civicrm_note.entity_table = 'civicrm_participant' AND | |
531 | civicrm_participant.id = civicrm_note.entity_id )"; | |
532 | break; | |
533 | ||
534 | case 'participant_status': | |
535 | $from .= " $side JOIN civicrm_participant_status_type participant_status ON (civicrm_participant.status_id = participant_status.id) "; | |
536 | break; | |
537 | ||
538 | case 'participant_role': | |
539 | $from = " $side JOIN civicrm_option_group option_group_participant_role ON (option_group_participant_role.name = 'participant_role')"; | |
540 | $from .= " $side JOIN civicrm_option_value participant_role ON (civicrm_participant.role_id = participant_role.value | |
541 | AND option_group_participant_role.id = participant_role.option_group_id ) "; | |
542 | break; | |
543 | ||
544 | case 'participant_discount_name': | |
545 | $from = " $side JOIN civicrm_discount discount ON ( civicrm_participant.discount_id = discount.id )"; | |
546 | $from .= " $side JOIN civicrm_option_group discount_name ON ( discount_name.id = discount.price_set_id ) "; | |
547 | break; | |
548 | } | |
549 | return $from; | |
550 | } | |
551 | ||
552 | /** | |
553 | * getter for the qill object | |
554 | * | |
555 | * @return string | |
556 | * @access public | |
557 | */ | |
558 | function qill() { | |
559 | return (isset($this->_qill)) ? $this->_qill : ""; | |
560 | } | |
561 | ||
0cf587a7 EM |
562 | /** |
563 | * @param $mode | |
564 | * @param bool $includeCustomFields | |
565 | * | |
566 | * @return array|null | |
567 | */ | |
6a488035 TO |
568 | static function defaultReturnProperties($mode, |
569 | $includeCustomFields = TRUE | |
570 | ) { | |
571 | $properties = NULL; | |
572 | if ($mode & CRM_Contact_BAO_Query::MODE_EVENT) { | |
573 | $properties = array( | |
574 | 'contact_type' => 1, | |
575 | 'contact_sub_type' => 1, | |
576 | 'sort_name' => 1, | |
577 | 'display_name' => 1, | |
578 | 'event_id' => 1, | |
579 | 'event_title' => 1, | |
580 | 'event_start_date' => 1, | |
581 | 'event_end_date' => 1, | |
582 | 'event_type' => 1, | |
583 | 'participant_id' => 1, | |
584 | 'participant_status' => 1, | |
585 | 'participant_role_id' => 1, | |
586 | 'participant_note' => 1, | |
587 | 'participant_register_date' => 1, | |
588 | 'participant_source' => 1, | |
589 | 'participant_fee_level' => 1, | |
590 | 'participant_is_test' => 1, | |
591 | 'participant_is_pay_later' => 1, | |
592 | 'participant_fee_amount' => 1, | |
593 | 'participant_discount_name' => 1, | |
594 | 'participant_fee_currency' => 1, | |
595 | 'participant_registered_by_id' => 1, | |
596 | 'participant_campaign_id' => 1, | |
597 | ); | |
598 | ||
599 | if ($includeCustomFields) { | |
600 | // also get all the custom participant properties | |
601 | $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Participant'); | |
602 | if (!empty($fields)) { | |
603 | foreach ($fields as $name => $dontCare) { | |
604 | $properties[$name] = 1; | |
605 | } | |
606 | } | |
607 | } | |
608 | } | |
609 | ||
610 | return $properties; | |
611 | } | |
612 | ||
6aac2db8 CW |
613 | /** |
614 | * @param CRM_Core_Form $form | |
615 | */ | |
6a488035 | 616 | static function buildSearchForm(&$form) { |
6a488035 TO |
617 | $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', |
618 | "reset=1", | |
619 | FALSE, NULL, FALSE | |
620 | ); | |
621 | ||
6a488035 TO |
622 | $form->assign('dataURLEventFee', $dataURLEventFee); |
623 | ||
9c7c6a00 CW |
624 | $eventId = $form->addEntityRef('event_id', ts('Event Name'), array( |
625 | 'entity' => 'event', | |
626 | 'placeholder' => ts('- any -'), | |
627 | 'select' => array('minimumInputLength' => 0), | |
628 | ) | |
629 | ); | |
6aac2db8 CW |
630 | $eventType = $form->addEntityRef('event_type_id', ts('Event Type'), array( |
631 | 'entity' => 'option_value', | |
632 | 'placeholder' => ts('- any -'), | |
633 | 'select' => array('minimumInputLength' => 0), | |
634 | 'api' => array( | |
635 | 'params' => array('option_group_id' => 'event_type'), | |
636 | ), | |
637 | ) | |
638 | ); | |
93793e86 | 639 | $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select')); |
6a488035 | 640 | |
bc3f7f04 | 641 | CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); |
62933949 | 642 | $eventIncludeRepeatingEvents = &$form->addElement('checkbox', "event_include_repeating_events", NULL, ts(' Include Repeating Events (If Any) ? ')); |
6a488035 TO |
643 | |
644 | $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); | |
6a488035 TO |
645 | foreach ($status as $id => $Name) { |
646 | $form->_participantStatus = &$form->addElement('checkbox', "participant_status_id[$id]", NULL, $Name); | |
647 | } | |
648 | ||
649 | foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { | |
650 | $form->_participantRole = &$form->addElement('checkbox', "participant_role_id[$rId]", NULL, $rName); | |
651 | } | |
652 | ||
8a4f27dc CW |
653 | $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); |
654 | $form->addYesNo('participant_pay_later', ts('Participant is Pay Later?'), TRUE); | |
6a488035 TO |
655 | $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); |
656 | $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); | |
657 | ||
658 | $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); | |
659 | $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); | |
660 | // add all the custom searchable fields | |
dcf0d348 | 661 | $extends = array('Participant', 'Event'); |
6a488035 TO |
662 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); |
663 | if ($groupDetails) { | |
664 | $form->assign('participantGroupTree', $groupDetails); | |
665 | foreach ($groupDetails as $group) { | |
666 | foreach ($group['fields'] as $field) { | |
667 | $fieldId = $field['id']; | |
668 | $elementName = 'custom_' . $fieldId; | |
669 | CRM_Core_BAO_CustomField::addQuickFormElement($form, | |
670 | $elementName, | |
671 | $fieldId, | |
672 | FALSE, FALSE, TRUE | |
673 | ); | |
674 | } | |
675 | } | |
676 | } | |
677 | ||
678 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); | |
62933949 | 679 | |
6a488035 TO |
680 | $form->assign('validCiviEvent', TRUE); |
681 | $form->setDefaults(array('participant_test' => 0)); | |
682 | } | |
683 | ||
0cf587a7 EM |
684 | /** |
685 | * @param $row | |
686 | * @param $id | |
687 | */ | |
6a488035 TO |
688 | static function searchAction(&$row, $id) {} |
689 | ||
0cf587a7 EM |
690 | /** |
691 | * @param $tables | |
692 | */ | |
6a488035 TO |
693 | static function tableNames(&$tables) { |
694 | //add participant table | |
a7488080 | 695 | if (!empty($tables['civicrm_event'])) { |
6a488035 TO |
696 | $tables = array_merge(array('civicrm_participant' => 1), $tables); |
697 | } | |
698 | } | |
699 | } | |
700 |