| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | class CRM_Event_BAO_Query { |
| 36 | |
| 37 | /** |
| 38 | * @return array |
| 39 | */ |
| 40 | public static function &getFields() { |
| 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 | |
| 49 | /** |
| 50 | * @return array |
| 51 | */ |
| 52 | public static function &getParticipantFields() { |
| 53 | $fields = CRM_Event_BAO_Participant::importableFields('Individual', TRUE, TRUE); |
| 54 | return $fields; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Build select for CiviEvent. |
| 59 | * |
| 60 | * @param $query |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | public static function select(&$query) { |
| 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 |
| 73 | if (!empty($query->_returnProperties['participant_fee_level'])) { |
| 74 | $query->_select['participant_fee_level'] = "civicrm_participant.fee_level as participant_fee_level"; |
| 75 | $query->_element['participant_fee_level'] = 1; |
| 76 | } |
| 77 | |
| 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 | |
| 84 | //add fee amount |
| 85 | if (!empty($query->_returnProperties['participant_fee_amount'])) { |
| 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 |
| 91 | if (!empty($query->_returnProperties['participant_fee_currency'])) { |
| 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 |
| 97 | if (!empty($query->_returnProperties['event_id']) || !empty($query->_returnProperties['event_title'])) { |
| 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 |
| 107 | if (!empty($query->_returnProperties['event_start_date'])) { |
| 108 | $query->_select['event_start_date'] = "civicrm_event.start_date as event_start_date"; |
| 109 | $query->_element['event_start_date'] = 1; |
| 110 | } |
| 111 | |
| 112 | if (!empty($query->_returnProperties['event_end_date'])) { |
| 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 |
| 118 | if (!empty($query->_returnProperties['event_type'])) { |
| 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 | |
| 125 | if (!empty($query->_returnProperties['event_type_id'])) { |
| 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_id |
| 133 | if (!empty($query->_returnProperties['participant_status_id'])) { |
| 134 | $query->_select['participant_status_id'] = "civicrm_participant.status_id as participant_status_id"; |
| 135 | $query->_element['participant_status_id'] = 1; |
| 136 | $query->_tables['civicrm_participant'] = 1; |
| 137 | $query->_whereTables['civicrm_participant'] = 1; |
| 138 | } |
| 139 | |
| 140 | // get particupant_status label |
| 141 | if (!empty($query->_returnProperties['participant_status'])) { |
| 142 | $query->_select['participant_status'] = "participant_status.label as participant_status"; |
| 143 | $query->_element['participant_status'] = 1; |
| 144 | $query->_tables['participant_status'] = 1; |
| 145 | $query->_whereTables['civicrm_participant'] = 1; |
| 146 | } |
| 147 | |
| 148 | //add participant_role_id |
| 149 | if (!empty($query->_returnProperties['participant_role_id'])) { |
| 150 | $query->_select['participant_role_id'] = "civicrm_participant.role_id as participant_role_id"; |
| 151 | $query->_element['participant_role_id'] = 1; |
| 152 | $query->_tables['civicrm_participant'] = 1; |
| 153 | $query->_whereTables['civicrm_participant'] = 1; |
| 154 | $query->_pseudoConstantsSelect['participant_role_id'] = array( |
| 155 | 'pseudoField' => 'participant_role_id', |
| 156 | 'idCol' => 'participant_role_id', |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | //add participant_role |
| 161 | if (!empty($query->_returnProperties['participant_role'])) { |
| 162 | $query->_select['participant_role'] = "civicrm_participant.role_id as participant_role"; |
| 163 | $query->_element['participant_role'] = 1; |
| 164 | $query->_tables['participant_role'] = 1; |
| 165 | $query->_whereTables['civicrm_participant'] = 1; |
| 166 | $query->_pseudoConstantsSelect['participant_role'] = array( |
| 167 | 'pseudoField' => 'participant_role', |
| 168 | 'idCol' => 'participant_role', |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | //add register date |
| 173 | if (!empty($query->_returnProperties['participant_register_date'])) { |
| 174 | $query->_select['participant_register_date'] = "civicrm_participant.register_date as participant_register_date"; |
| 175 | $query->_element['participant_register_date'] = 1; |
| 176 | } |
| 177 | |
| 178 | //add source |
| 179 | if (!empty($query->_returnProperties['participant_source'])) { |
| 180 | $query->_select['participant_source'] = "civicrm_participant.source as participant_source"; |
| 181 | $query->_element['participant_source'] = 1; |
| 182 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
| 183 | } |
| 184 | |
| 185 | //participant note |
| 186 | if (!empty($query->_returnProperties['participant_note'])) { |
| 187 | $query->_select['participant_note'] = "civicrm_note.note as participant_note"; |
| 188 | $query->_element['participant_note'] = 1; |
| 189 | $query->_tables['participant_note'] = 1; |
| 190 | $query->_whereTables['civicrm_note'] = 1; |
| 191 | } |
| 192 | |
| 193 | if (!empty($query->_returnProperties['participant_is_pay_later'])) { |
| 194 | $query->_select['participant_is_pay_later'] = "civicrm_participant.is_pay_later as participant_is_pay_later"; |
| 195 | $query->_element['participant_is_pay_later'] = 1; |
| 196 | } |
| 197 | |
| 198 | if (!empty($query->_returnProperties['participant_is_test'])) { |
| 199 | $query->_select['participant_is_test'] = "civicrm_participant.is_test as participant_is_test"; |
| 200 | $query->_element['participant_is_test'] = 1; |
| 201 | } |
| 202 | |
| 203 | if (!empty($query->_returnProperties['participant_registered_by_id'])) { |
| 204 | $query->_select['participant_registered_by_id'] = "civicrm_participant.registered_by_id as participant_registered_by_id"; |
| 205 | $query->_element['participant_registered_by_id'] = 1; |
| 206 | } |
| 207 | |
| 208 | // get discount name |
| 209 | if (!empty($query->_returnProperties['participant_discount_name'])) { |
| 210 | $query->_select['participant_discount_name'] = "discount_name.title as participant_discount_name"; |
| 211 | $query->_element['participant_discount_name'] = 1; |
| 212 | $query->_tables['civicrm_discount'] = 1; |
| 213 | $query->_tables['participant_discount_name'] = 1; |
| 214 | $query->_whereTables['civicrm_discount'] = 1; |
| 215 | $query->_whereTables['participant_discount_name'] = 1; |
| 216 | } |
| 217 | |
| 218 | //carry campaign id to selectors. |
| 219 | if (!empty($query->_returnProperties['participant_campaign_id'])) { |
| 220 | $query->_select['participant_campaign_id'] = 'civicrm_participant.campaign_id as participant_campaign_id'; |
| 221 | $query->_element['participant_campaign_id'] = 1; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | /** |
| 228 | * @param $query |
| 229 | */ |
| 230 | public static function where(&$query) { |
| 231 | $grouping = NULL; |
| 232 | foreach (array_keys($query->_params) as $id) { |
| 233 | if (empty($query->_params[$id][0])) { |
| 234 | continue; |
| 235 | } |
| 236 | if (substr($query->_params[$id][0], 0, 6) == 'event_' || |
| 237 | substr($query->_params[$id][0], 0, 12) == 'participant_' |
| 238 | ) { |
| 239 | if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { |
| 240 | $query->_useDistinct = TRUE; |
| 241 | } |
| 242 | $grouping = $query->_params[$id][3]; |
| 243 | self::whereClauseSingle($query->_params[$id], $query); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @param $values |
| 250 | * @param $query |
| 251 | */ |
| 252 | public static function whereClauseSingle(&$values, &$query) { |
| 253 | list($name, $op, $value, $grouping, $wildcard) = $values; |
| 254 | $fields = array_merge(CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields()); |
| 255 | |
| 256 | switch ($name) { |
| 257 | case 'event_start_date_low': |
| 258 | case 'event_start_date_high': |
| 259 | $query->dateQueryBuilder($values, |
| 260 | 'civicrm_event', 'event_start_date', 'start_date', 'Start Date' |
| 261 | ); |
| 262 | return; |
| 263 | |
| 264 | case 'event_end_date_low': |
| 265 | case 'event_end_date_high': |
| 266 | $query->dateQueryBuilder($values, |
| 267 | 'civicrm_event', 'event_end_date', 'end_date', 'End Date' |
| 268 | ); |
| 269 | return; |
| 270 | |
| 271 | case 'event_include_repeating_events': |
| 272 | /** |
| 273 | * Include Repeating Events |
| 274 | */ |
| 275 | //Get parent of this event |
| 276 | $exEventId = ''; |
| 277 | if ($query->_where[$grouping]) { |
| 278 | foreach ($query->_where[$grouping] as $key => $val) { |
| 279 | if (strstr($val, 'civicrm_event.id =')) { |
| 280 | $exEventId = $val; |
| 281 | $extractEventId = explode(" ", $val); |
| 282 | $value = $extractEventId[2]; |
| 283 | unset($query->_where[$grouping][$key]); |
| 284 | } |
| 285 | } |
| 286 | $extractEventId = explode(" ", $exEventId); |
| 287 | $value = $extractEventId[2]; |
| 288 | unset($query->_where[$grouping][$key]); |
| 289 | } |
| 290 | $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event'); |
| 291 | if ($thisEventHasParent) { |
| 292 | $getAllConnections = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($thisEventHasParent, 'civicrm_event'); |
| 293 | $allEventIds = array(); |
| 294 | foreach ($getAllConnections as $key => $val) { |
| 295 | $allEventIds[] = $val['id']; |
| 296 | } |
| 297 | if (!empty($allEventIds)) { |
| 298 | $op = "IN"; |
| 299 | $value = "(" . implode(",", $allEventIds) . ")"; |
| 300 | } |
| 301 | } |
| 302 | $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; |
| 303 | $query->_qill[$grouping][] = ts('Include Repeating Events'); |
| 304 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; |
| 305 | return; |
| 306 | |
| 307 | case 'participant_is_test': |
| 308 | $key = array_search('civicrm_participant.is_test = 0', $query->_where[$grouping]); |
| 309 | if (!empty($key)) { |
| 310 | unset($query->_where[$grouping][$key]); |
| 311 | } |
| 312 | case 'participant_test': |
| 313 | // We dont want to include all tests for sql OR CRM-7827 |
| 314 | if (!$value || $query->getOperator() != 'OR') { |
| 315 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_test", |
| 316 | $op, |
| 317 | $value, |
| 318 | "Boolean" |
| 319 | ); |
| 320 | |
| 321 | $isTest = $value ? 'a Test' : 'not a Test'; |
| 322 | $query->_qill[$grouping][] = ts("Participant is %1", array(1 => $isTest)); |
| 323 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
| 324 | } |
| 325 | return; |
| 326 | |
| 327 | case 'participant_fee_id': |
| 328 | $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $value, 'label'); |
| 329 | $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); |
| 330 | if ($value) { |
| 331 | $query->_where[$grouping][] = "civicrm_participant.fee_level LIKE '%$feeLabel%'"; |
| 332 | $query->_qill[$grouping][] = ts("Fee level") . " contains $feeLabel"; |
| 333 | } |
| 334 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
| 335 | return; |
| 336 | |
| 337 | case 'participant_fee_amount_high': |
| 338 | case 'participant_fee_amount_low': |
| 339 | $query->numberRangeBuilder($values, |
| 340 | 'civicrm_participant', 'participant_fee_amount', 'fee_amount', 'Fee Amount' |
| 341 | ); |
| 342 | return; |
| 343 | |
| 344 | case 'participant_status_id': |
| 345 | if ($value && is_array($value) && strpos($op, 'IN') === FALSE) { |
| 346 | $op = 'IN'; |
| 347 | } |
| 348 | case 'participant_status': |
| 349 | case 'participant_source': |
| 350 | case 'participant_id': |
| 351 | case 'participant_contact_id': |
| 352 | case 'participant_is_pay_later': |
| 353 | case 'participant_fee_amount': |
| 354 | case 'participant_fee_level': |
| 355 | case 'participant_campaign_id': |
| 356 | |
| 357 | $qillName = $name; |
| 358 | if (in_array($name, array( |
| 359 | 'participant_status_id', |
| 360 | 'participant_source', |
| 361 | 'participant_id', |
| 362 | 'participant_contact_id', |
| 363 | 'participant_fee_amount', |
| 364 | 'participant_fee_level', |
| 365 | 'participant_is_pay_later', |
| 366 | 'participant_campaign_id', |
| 367 | ))) { |
| 368 | $name = str_replace('participant_', '', $name); |
| 369 | if ($name == 'is_pay_later') { |
| 370 | $qillName = $name; |
| 371 | } |
| 372 | } |
| 373 | elseif ($name == 'participant_status') { |
| 374 | $name = 'status_id'; |
| 375 | } |
| 376 | |
| 377 | $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; |
| 378 | $tableName = empty($tableName) ? 'civicrm_participant' : $tableName; |
| 379 | |
| 380 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType); |
| 381 | |
| 382 | list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op); |
| 383 | $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); |
| 384 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
| 385 | return; |
| 386 | |
| 387 | case 'participant_role': |
| 388 | case 'participant_role_id': |
| 389 | $qillName = $name; |
| 390 | $name = 'role_id'; |
| 391 | |
| 392 | if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { |
| 393 | $op = key($value); |
| 394 | $value = $value[$op]; |
| 395 | } |
| 396 | if (!strstr($op, 'NULL') && !strstr($op, 'EMPTY') && !strstr($op, 'LIKE')) { |
| 397 | $regexOp = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP'; |
| 398 | $regexp = "[[:cntrl:]]*" . implode('[[:>:]]*|[[:<:]]*', (array) $value) . "[[:cntrl:]]*"; |
| 399 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.$name", $regexOp, $regexp, 'String'); |
| 400 | } |
| 401 | else { |
| 402 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType); |
| 403 | } |
| 404 | |
| 405 | list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op); |
| 406 | $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); |
| 407 | $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; |
| 408 | return; |
| 409 | |
| 410 | case 'participant_register_date': |
| 411 | $query->dateQueryBuilder($values, |
| 412 | 'civicrm_participant', 'participant_register_date', 'register_date', 'Register Date' |
| 413 | ); |
| 414 | return; |
| 415 | |
| 416 | case 'event_id': |
| 417 | case 'participant_event_id': |
| 418 | $name = str_replace('participant_', '', $name); |
| 419 | case 'event_is_public': |
| 420 | case 'event_type_id': |
| 421 | case 'event_title': |
| 422 | $qillName = $name; |
| 423 | if (in_array($name, array( |
| 424 | 'event_id', |
| 425 | 'event_title', |
| 426 | 'event_is_public', |
| 427 | ) |
| 428 | )) { |
| 429 | $name = str_replace('event_', '', $name); |
| 430 | } |
| 431 | $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; |
| 432 | |
| 433 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.$name", $op, $value, $dataType); |
| 434 | $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; |
| 435 | if (!array_key_exists($qillName, $fields)) { |
| 436 | break; |
| 437 | } |
| 438 | list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op); |
| 439 | $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); |
| 440 | return; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * @param string $name |
| 446 | * @param $mode |
| 447 | * @param $side |
| 448 | * |
| 449 | * @return null|string |
| 450 | */ |
| 451 | public static function from($name, $mode, $side) { |
| 452 | $from = NULL; |
| 453 | switch ($name) { |
| 454 | case 'civicrm_participant': |
| 455 | $from = " LEFT JOIN civicrm_participant ON civicrm_participant.contact_id = contact_a.id "; |
| 456 | break; |
| 457 | |
| 458 | case 'civicrm_event': |
| 459 | $from = " INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id "; |
| 460 | break; |
| 461 | |
| 462 | case 'event_type': |
| 463 | $from = " $side JOIN civicrm_option_group option_group_event_type ON (option_group_event_type.name = 'event_type')"; |
| 464 | $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 ) "; |
| 465 | break; |
| 466 | |
| 467 | case 'participant_note': |
| 468 | $from .= " $side JOIN civicrm_note ON ( civicrm_note.entity_table = 'civicrm_participant' AND |
| 469 | civicrm_participant.id = civicrm_note.entity_id )"; |
| 470 | break; |
| 471 | |
| 472 | case 'participant_status': |
| 473 | $from .= " $side JOIN civicrm_participant_status_type participant_status ON (civicrm_participant.status_id = participant_status.id) "; |
| 474 | break; |
| 475 | |
| 476 | case 'participant_role': |
| 477 | $from = " $side JOIN civicrm_option_group option_group_participant_role ON (option_group_participant_role.name = 'participant_role')"; |
| 478 | $from .= " $side JOIN civicrm_option_value participant_role ON ((civicrm_participant.role_id = participant_role.value OR SUBSTRING_INDEX(role_id,'\ 1', 1) = participant_role.value) |
| 479 | AND option_group_participant_role.id = participant_role.option_group_id ) "; |
| 480 | break; |
| 481 | |
| 482 | case 'participant_discount_name': |
| 483 | $from = " $side JOIN civicrm_discount discount ON ( civicrm_participant.discount_id = discount.id )"; |
| 484 | $from .= " $side JOIN civicrm_option_group discount_name ON ( discount_name.id = discount.price_set_id ) "; |
| 485 | break; |
| 486 | } |
| 487 | return $from; |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Getter for the qill object. |
| 492 | * |
| 493 | * @return string |
| 494 | */ |
| 495 | public function qill() { |
| 496 | return (isset($this->_qill)) ? $this->_qill : ""; |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * @param $mode |
| 501 | * @param bool $includeCustomFields |
| 502 | * |
| 503 | * @return array|null |
| 504 | */ |
| 505 | public static function defaultReturnProperties( |
| 506 | $mode, |
| 507 | $includeCustomFields = TRUE |
| 508 | ) { |
| 509 | $properties = NULL; |
| 510 | if ($mode & CRM_Contact_BAO_Query::MODE_EVENT) { |
| 511 | $properties = array( |
| 512 | 'contact_type' => 1, |
| 513 | 'contact_sub_type' => 1, |
| 514 | 'sort_name' => 1, |
| 515 | 'display_name' => 1, |
| 516 | 'event_id' => 1, |
| 517 | 'event_title' => 1, |
| 518 | 'event_start_date' => 1, |
| 519 | 'event_end_date' => 1, |
| 520 | 'event_type' => 1, |
| 521 | 'participant_id' => 1, |
| 522 | 'participant_status' => 1, |
| 523 | 'participant_status_id' => 1, |
| 524 | 'participant_role' => 1, |
| 525 | 'participant_role_id' => 1, |
| 526 | 'participant_note' => 1, |
| 527 | 'participant_register_date' => 1, |
| 528 | 'participant_source' => 1, |
| 529 | 'participant_fee_level' => 1, |
| 530 | 'participant_is_test' => 1, |
| 531 | 'participant_is_pay_later' => 1, |
| 532 | 'participant_fee_amount' => 1, |
| 533 | 'participant_discount_name' => 1, |
| 534 | 'participant_fee_currency' => 1, |
| 535 | 'participant_registered_by_id' => 1, |
| 536 | 'participant_campaign_id' => 1, |
| 537 | ); |
| 538 | |
| 539 | if ($includeCustomFields) { |
| 540 | // also get all the custom participant properties |
| 541 | $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Participant'); |
| 542 | if (!empty($fields)) { |
| 543 | foreach ($fields as $name => $dontCare) { |
| 544 | $properties[$name] = 1; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return $properties; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * @param CRM_Core_Form $form |
| 555 | */ |
| 556 | public static function buildSearchForm(&$form) { |
| 557 | $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', |
| 558 | "reset=1", |
| 559 | FALSE, NULL, FALSE |
| 560 | ); |
| 561 | |
| 562 | $form->assign('dataURLEventFee', $dataURLEventFee); |
| 563 | |
| 564 | $form->addEntityRef('event_id', ts('Event Name'), array( |
| 565 | 'entity' => 'event', |
| 566 | 'placeholder' => ts('- any -'), |
| 567 | 'select' => array('minimumInputLength' => 0), |
| 568 | ) |
| 569 | ); |
| 570 | $form->addEntityRef('event_type_id', ts('Event Type'), array( |
| 571 | 'entity' => 'option_value', |
| 572 | 'placeholder' => ts('- any -'), |
| 573 | 'select' => array('minimumInputLength' => 0), |
| 574 | 'api' => array( |
| 575 | 'params' => array('option_group_id' => 'event_type'), |
| 576 | ), |
| 577 | ) |
| 578 | ); |
| 579 | $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select')); |
| 580 | |
| 581 | CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); |
| 582 | |
| 583 | $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>'))); |
| 584 | |
| 585 | $form->addSelect('participant_status_id', |
| 586 | array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) |
| 587 | ); |
| 588 | |
| 589 | $form->addSelect('participant_role_id', |
| 590 | array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) |
| 591 | ); |
| 592 | |
| 593 | $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); |
| 594 | $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE); |
| 595 | $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); |
| 596 | $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); |
| 597 | |
| 598 | $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); |
| 599 | $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); |
| 600 | // add all the custom searchable fields |
| 601 | $extends = array('Participant', 'Event'); |
| 602 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); |
| 603 | if ($groupDetails) { |
| 604 | $form->assign('participantGroupTree', $groupDetails); |
| 605 | foreach ($groupDetails as $group) { |
| 606 | foreach ($group['fields'] as $field) { |
| 607 | $fieldId = $field['id']; |
| 608 | $elementName = 'custom_' . $fieldId; |
| 609 | CRM_Core_BAO_CustomField::addQuickFormElement($form, |
| 610 | $elementName, |
| 611 | $fieldId, |
| 612 | FALSE, FALSE, TRUE |
| 613 | ); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); |
| 619 | |
| 620 | $form->assign('validCiviEvent', TRUE); |
| 621 | $form->setDefaults(array('participant_test' => 0)); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * @param $row |
| 626 | * @param int $id |
| 627 | */ |
| 628 | public static function searchAction(&$row, $id) { |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * @param $tables |
| 633 | */ |
| 634 | public static function tableNames(&$tables) { |
| 635 | //add participant table |
| 636 | if (!empty($tables['civicrm_event'])) { |
| 637 | $tables = array_merge(array('civicrm_participant' => 1), $tables); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | } |