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