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