3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Event_BAO_Event
extends CRM_Event_DAO_Event
{
38 public function __construct() {
39 parent
::__construct();
43 * Fetch object based on array of properties.
45 * @param array $params
46 * (reference ) an assoc array of name/value pairs.
47 * @param array $defaults
48 * (reference ) an assoc array to hold the flattened values.
50 * @return CRM_Event_DAO_Event
52 public static function retrieve(&$params, &$defaults) {
53 $event = new CRM_Event_DAO_Event();
54 $event->copyValues($params);
55 if ($event->find(TRUE)) {
56 CRM_Core_DAO
::storeValues($event, $defaults);
63 * Update the is_active flag in the db.
66 * Id of the database record.
67 * @param bool $is_active
68 * Value we want to set the is_active field.
71 * true if we found and updated the object, else false
73 public static function setIsActive($id, $is_active) {
74 return CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Event', $id, 'is_active', $is_active);
80 * @param array $params
81 * Reference array contains the values submitted by the form.
83 * @return CRM_Event_DAO_Event
85 public static function add(&$params) {
86 CRM_Utils_System
::flushCache();
87 $financialTypeId = NULL;
88 if (!empty($params['id'])) {
89 CRM_Utils_Hook
::pre('edit', 'Event', $params['id'], $params);
90 if (empty($params['skipFinancialType'])) {
91 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['id'], 'financial_type_id');
95 CRM_Utils_Hook
::pre('create', 'Event', NULL, $params);
98 $event = new CRM_Event_DAO_Event();
100 $event->copyValues($params);
101 $result = $event->save();
103 if (!empty($params['id'])) {
104 CRM_Utils_Hook
::post('edit', 'Event', $event->id
, $event);
107 CRM_Utils_Hook
::post('create', 'Event', $event->id
, $event);
109 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
110 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_event', $params['financial_type_id']);
118 * @param array $params
119 * Reference array contains the values submitted by the form.
123 public static function create(&$params) {
124 $transaction = new CRM_Core_Transaction();
125 if (empty($params['is_template'])) {
126 $params['is_template'] = 0;
128 // check if new event, if so set the created_id (if not set)
129 // and always set created_date to now
130 if (empty($params['id'])) {
131 if (empty($params['created_id'])) {
132 $session = CRM_Core_Session
::singleton();
133 $params['created_id'] = $session->get('userID');
135 $params['created_date'] = date('YmdHis');
138 $event = self
::add($params);
139 CRM_Price_BAO_PriceSet
::setPriceSets($params, $event, 'event');
140 if (is_a($event, 'CRM_Core_Error')) {
141 CRM_Core_DAO
::transaction('ROLLBACK');
145 $contactId = CRM_Core_Session
::getLoggedInContactID();
147 $contactId = CRM_Utils_Array
::value('contact_id', $params);
150 // Log the information on successful add/edit of Event
152 'entity_table' => 'civicrm_event',
153 'entity_id' => $event->id
,
154 'modified_id' => $contactId,
155 'modified_date' => date('Ymd'),
158 CRM_Core_BAO_Log
::add($logParams);
160 if (!empty($params['custom']) &&
161 is_array($params['custom'])
163 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_event', $event->id
);
166 $transaction->commit();
179 public static function del($id) {
184 CRM_Utils_Hook
::pre('delete', 'Event', $id, CRM_Core_DAO
::$_nullArray);
186 $extends = ['event'];
187 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
188 foreach ($groupTree as $values) {
189 $query = "DELETE FROM %1 WHERE entity_id = %2";
190 CRM_Core_DAO
::executeQuery($query, [
191 1 => [$values['table_name'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
],
192 2 => [$id, 'Integer'],
196 // Clean up references to profiles used by the event (CRM-20935)
198 'module' => 'CiviEvent',
199 'entity_table' => 'civicrm_event',
202 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
204 'module' => 'CiviEvent_Additional',
205 'entity_table' => 'civicrm_event',
208 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
210 // price set cleanup, CRM-5527
211 CRM_Price_BAO_PriceSet
::removeFrom('civicrm_event', $id);
213 $event = new CRM_Event_DAO_Event();
216 if ($event->find(TRUE)) {
217 $locBlockId = $event->loc_block_id
;
218 $result = $event->delete();
220 if (!is_null($locBlockId)) {
221 self
::deleteEventLocBlock($locBlockId, $id);
224 CRM_Utils_Hook
::post('delete', 'Event', $id, $event);
232 * Delete the location block associated with an event.
234 * Function checks that it is not being used by any other event.
236 * @param int $locBlockId
237 * Location block id to be deleted.
238 * @param int $eventId
239 * Event with which loc block is associated.
241 public static function deleteEventLocBlock($locBlockId, $eventId = NULL) {
242 $query = "SELECT count(ce.id) FROM civicrm_event ce WHERE ce.loc_block_id = $locBlockId";
245 $query .= " AND ce.id != $eventId;";
248 $locCount = CRM_Core_DAO
::singleValueQuery($query);
250 if ($locCount == 0) {
251 CRM_Core_BAO_Location
::deleteLocBlock($locBlockId);
256 * Get current/future Events.
259 * 0 returns current and future events.
260 * 1 if events all are required
261 * 2 returns events since 3 months ago
262 * @param int|array $id single int event id or array of multiple event ids to return
263 * @param bool $isActive
264 * true if you need only active events.
265 * @param bool $checkPermission
266 * true if you need to check permission else false.
267 * @param bool $titleOnly
268 * true if you need only title not appended with start date
272 public static function getEvents(
276 $checkPermission = TRUE,
280 SELECT `id`, `title`, `start_date`
282 WHERE ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
285 $op = is_array($id) ?
'IN' : '=';
286 $where = CRM_Contact_BAO_Query
::buildClause('id', $op, $id);
287 $query .= " AND {$where}";
290 // find only events ending in the future
291 $endDate = date('YmdHis');
293 AND ( `end_date` >= {$endDate} OR
295 ( end_date IS NULL OR end_date = '' ) AND start_date >= {$endDate}
300 // find only events starting in the last 3 months
301 $startDate = date('YmdHis', strtotime('3 months ago'));
302 $query .= " AND ( `start_date` >= {$startDate} OR start_date IS NULL )";
305 $query .= " AND civicrm_event.is_active = 1";
308 $query .= " ORDER BY title asc";
311 $dao = CRM_Core_DAO
::executeQuery($query);
312 while ($dao->fetch()) {
313 if ((!$checkPermission ||
314 CRM_Event_BAO_Event
::checkPermission($dao->id
)
318 $events[$dao->id
] = $dao->title
;
320 $events[$dao->id
] .= ' - ' . CRM_Utils_Date
::customFormat($dao->start_date
);
329 * Get events Summary.
332 * Array of event summary values
334 * @throws \CiviCRM_API3_Exception
336 public static function getEventSummary() {
337 $eventSummary = $eventIds = [];
338 $config = CRM_Core_Config
::singleton();
340 // get permission and include them here
341 // does not scale, but rearranging code for now
342 // FIXME in a future release
343 $permissions = self
::getAllPermissions();
345 if (empty($permissions[CRM_Core_Permission
::VIEW
])) {
346 $eventSummary['total_events'] = 0;
347 return $eventSummary;
350 $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission
::VIEW
])) . " ) ";
353 // We're fetching recent and upcoming events (where start date is 7 days ago OR later)
355 SELECT count(id) as total_events
357 WHERE civicrm_event.is_active = 1 AND
358 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
359 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
362 $dao = CRM_Core_DAO
::executeQuery($query);
365 $eventSummary['total_events'] = $dao->total_events
;
368 if (empty($eventSummary) ||
369 $dao->total_events
== 0
371 return $eventSummary;
374 //get the participant status type values.
375 $cpstObject = new CRM_Event_DAO_ParticipantStatusType();
376 $cpst = $cpstObject->getTableName();
377 $query = "SELECT id, name, label, class FROM $cpst";
378 $status = CRM_Core_DAO
::executeQuery($query);
380 while ($status->fetch()) {
381 $statusValues[$status->id
]['id'] = $status->id
;
382 $statusValues[$status->id
]['name'] = $status->name
;
383 $statusValues[$status->id
]['label'] = $status->label
;
384 $statusValues[$status->id
]['class'] = $status->class;
387 // Get the Id of Option Group for Event Types
388 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
389 $optionGroupDAO->name
= 'event_type';
390 $optionGroupId = NULL;
391 if ($optionGroupDAO->find(TRUE)) {
392 $optionGroupId = $optionGroupDAO->id
;
394 // Get the event summary display preferences
395 $show_max_events = Civi
::settings()->get('show_events');
396 // show all events if show_events is set to a negative value
397 if (isset($show_max_events) && $show_max_events >= 0) {
398 $event_summary_limit = "LIMIT 0, $show_max_events";
401 $event_summary_limit = "";
405 SELECT civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public,
406 civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date,
407 civicrm_event.end_date as end_date, civicrm_event.is_online_registration, civicrm_event.is_monetary, civicrm_event.is_show_location,civicrm_event.is_map as is_map, civicrm_option_value.label as event_type, civicrm_tell_friend.is_active as is_friend_active,
408 civicrm_event.slot_label_id,
409 civicrm_event.summary as summary,
410 civicrm_pcp_block.id as is_pcp_enabled,
411 civicrm_recurring_entity.parent_id as is_repeating_event
413 LEFT JOIN civicrm_option_value ON (
414 civicrm_event.event_type_id = civicrm_option_value.value AND
415 civicrm_option_value.option_group_id = %1 )
416 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id AND civicrm_tell_friend.entity_table = 'civicrm_event' )
417 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event')
418 LEFT JOIN civicrm_recurring_entity ON ( civicrm_event.id = civicrm_recurring_entity.entity_id AND civicrm_recurring_entity.entity_table = 'civicrm_event' )
419 WHERE civicrm_event.is_active = 1 AND
420 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
421 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
423 ORDER BY civicrm_event.start_date ASC
426 $eventParticipant = [];
430 'eventTitle' => 'event_title',
431 'isPublic' => 'is_public',
432 'maxParticipants' => 'max_participants',
433 'startDate' => 'start_date',
434 'endDate' => 'end_date',
435 'eventType' => 'event_type',
437 'participants' => 'participants',
438 'notCountedDueToRole' => 'notCountedDueToRole',
439 'notCountedDueToStatus' => 'notCountedDueToStatus',
440 'notCountedParticipants' => 'notCountedParticipants',
443 $params = [1 => [$optionGroupId, 'Integer']];
444 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
445 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
447 $dao = CRM_Core_DAO
::executeQuery($query, $params);
448 while ($dao->fetch()) {
449 foreach ($properties as $property => $name) {
459 $eventSummary['events'][$dao->id
][$property] = $set;
463 if ($dao->$name && $config->mapAPIKey
) {
466 $params = ['entity_id' => $dao->id
, 'entity_table' => 'civicrm_event'];
467 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
468 if (is_numeric(CRM_Utils_Array
::value('geo_code_1', $values['location']['address'][1])) ||
470 !empty($values['location']['address'][1]['city']) &&
471 !empty($values['location']['address'][1]['state_province_id'])
474 $set = CRM_Utils_System
::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}");
478 $eventSummary['events'][$dao->id
][$property] = $set;
479 if (is_array($permissions[CRM_Core_Permission
::EDIT
])
480 && in_array($dao->id
, $permissions[CRM_Core_Permission
::EDIT
])) {
481 $eventSummary['events'][$dao->id
]['configure'] = CRM_Utils_System
::url('civicrm/admin/event', "action=update&id=$dao->id&reset=1");
487 $eventSummary['events'][$dao->id
][$property] = CRM_Utils_Date
::customFormat($dao->$name,
493 case 'notCountedDueToRole':
494 case 'notCountedDueToStatus':
495 case 'notCountedParticipants':
498 if ($name == 'participants') {
499 $propertyCnt = self
::getParticipantCount($dao->id
);
501 $set = CRM_Utils_System
::url('civicrm/event/search',
502 "reset=1&force=1&event=$dao->id&status=true&role=true"
506 elseif ($name == 'notCountedParticipants') {
507 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, TRUE, FALSE);
509 // FIXME : selector fail to search w/ OR operator.
510 // $set = CRM_Utils_System::url( 'civicrm/event/search',
511 // "reset=1&force=1&event=$dao->id&status=false&role=false" );
514 elseif ($name == 'notCountedDueToStatus') {
515 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, FALSE, FALSE);
517 $set = CRM_Utils_System
::url('civicrm/event/search',
518 "reset=1&force=1&event=$dao->id&status=false"
523 $propertyCnt = self
::getParticipantCount($dao->id
, FALSE, FALSE, TRUE, FALSE);
525 $set = CRM_Utils_System
::url('civicrm/event/search',
526 "reset=1&force=1&event=$dao->id&role=false"
531 $eventSummary['events'][$dao->id
][$property] = $propertyCnt;
532 $eventSummary['events'][$dao->id
][$name . '_url'] = $set;
536 $eventSummary['events'][$dao->id
][$property] = $dao->$name;
541 // prepare the area for per-status participant counts
542 $statusClasses = ['Positive', 'Pending', 'Waiting', 'Negative'];
543 $eventSummary['events'][$dao->id
]['statuses'] = array_fill_keys($statusClasses, []);
545 $eventSummary['events'][$dao->id
]['friend'] = $dao->is_friend_active
;
546 $eventSummary['events'][$dao->id
]['is_monetary'] = $dao->is_monetary
;
547 $eventSummary['events'][$dao->id
]['is_online_registration'] = $dao->is_online_registration
;
548 $eventSummary['events'][$dao->id
]['is_show_location'] = $dao->is_show_location
;
549 $eventSummary['events'][$dao->id
]['is_subevent'] = $dao->slot_label_id
;
550 $eventSummary['events'][$dao->id
]['is_pcp_enabled'] = $dao->is_pcp_enabled
;
551 $eventSummary['events'][$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mapping->getId());
552 $eventSummary['events'][$dao->id
]['is_repeating_event'] = $dao->is_repeating_event
;
554 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
555 foreach ($statusValues as $statusId => $statusValue) {
556 if (!array_key_exists($statusId, $statusTypes)) {
559 $class = $statusValue['class'];
560 $statusCount = self
::eventTotalSeats($dao->id
, "( participant.status_id = {$statusId} )");
562 $urlString = "reset=1&force=1&event={$dao->id}&status=$statusId";
564 'url' => CRM_Utils_System
::url('civicrm/event/search', $urlString),
565 'name' => $statusValue['name'],
566 'label' => $statusValue['label'],
567 'count' => $statusCount,
569 $eventSummary['events'][$dao->id
]['statuses'][$class][] = $statusInfo;
574 $countedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
575 $nonCountedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, '( filter = 0 OR filter IS NULL )');
576 $countedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
577 $nonCountedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )');
579 $countedStatusANDRoles = array_merge($countedStatus, $countedRoles);
580 $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles);
582 $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles));
583 $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus));
584 $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles));
585 $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles));
587 return $eventSummary;
591 * Get participant count.
593 * @param int $eventId
594 * @param bool $considerStatus consider status for participant count.
595 * Consider status for participant count.
596 * @param bool $status counted participant.
597 * Consider counted participant.
598 * @param bool $considerRole consider role for participant count.
599 * Consider role for participant count.
600 * @param bool $role consider counted( is filter role) participant.
601 * Consider counted( is filter role) participant.
604 * array with count of participants for each event based on status/role
606 public static function getParticipantCount(
608 $considerStatus = TRUE,
610 $considerRole = TRUE,
614 // consider both role and status for counted participants, CRM-4924.
616 // not counted participant.
617 if ($considerStatus && $considerRole && !$status && !$role) {
621 if ($considerStatus) {
622 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
623 $statusClause = 'NOT IN';
625 $statusClause = 'IN';
627 $status = implode(',', array_keys($statusTypes));
628 if (empty($status)) {
631 $clause[] = "participant.status_id {$statusClause} ( {$status} ) ";
635 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
636 $roleClause = 'NOT IN';
641 if (!empty($roleTypes)) {
643 foreach (array_keys($roleTypes) as $roleType) {
644 $escapedRoles[] = CRM_Utils_Type
::escape($roleType, 'String');
647 $clause[] = "participant.role_id {$roleClause} ( '" . implode("', '", $escapedRoles) . "' ) ";
652 if (!empty($clause)) {
653 $sqlClause = ' ( ' . implode($operator, $clause) . ' )';
656 return self
::eventTotalSeats($eventId, $sqlClause);
660 * Get the information to map a event.
663 * For which we want map info.
665 * @return null|string
668 public static function &getMapInfo(&$id) {
672 civicrm_event.id AS event_id,
673 civicrm_event.title AS display_name,
674 civicrm_address.street_address AS street_address,
675 civicrm_address.city AS city,
676 civicrm_address.postal_code AS postal_code,
677 civicrm_address.postal_code_suffix AS postal_code_suffix,
678 civicrm_address.geo_code_1 AS latitude,
679 civicrm_address.geo_code_2 AS longitude,
680 civicrm_state_province.abbreviation AS state,
681 civicrm_country.name AS country,
682 civicrm_location_type.name AS location_type
685 LEFT JOIN civicrm_loc_block ON ( civicrm_event.loc_block_id = civicrm_loc_block.id )
686 LEFT JOIN civicrm_address ON ( civicrm_loc_block.address_id = civicrm_address.id )
687 LEFT JOIN civicrm_state_province ON ( civicrm_address.state_province_id = civicrm_state_province.id )
688 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
689 LEFT JOIN civicrm_location_type ON ( civicrm_location_type.id = civicrm_address.location_type_id )
690 WHERE civicrm_address.geo_code_1 IS NOT NULL
691 AND civicrm_address.geo_code_2 IS NOT NULL
692 AND civicrm_event.id = " . CRM_Utils_Type
::escape($id, 'Integer');
694 $dao = new CRM_Core_DAO();
699 $config = CRM_Core_Config
::singleton();
701 while ($dao->fetch()) {
704 $location['displayName'] = addslashes($dao->display_name
);
705 $location['lat'] = $dao->latitude
;
706 $location['marker_class'] = 'Event';
707 $location['lng'] = $dao->longitude
;
709 $params = ['entity_id' => $id, 'entity_table' => 'civicrm_event'];
710 $addressValues = CRM_Core_BAO_Location
::getValues($params, TRUE);
711 $location['address'] = str_replace([
714 ], '', addslashes(nl2br($addressValues['address'][1]['display_text'])));
716 $location['url'] = CRM_Utils_System
::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id
);
717 $location['location_type'] = $dao->location_type
;
718 $eventImage = '<img src="' . $config->resourceBase
. 'i/contact_org.gif" alt="Organization " height="20" width="15" />';
719 $location['image'] = $eventImage;
720 $location['displayAddress'] = str_replace('<br />', ', ', $location['address']);
721 $locations[] = $location;
727 * Get the complete information for one or more events.
730 * Get events with start date >= this date.
731 * @param int $type Get events on the a specific event type (by event_type_id).
732 * Get events on the a specific event type (by event_type_id).
733 * @param int $eventId Return a single event - by event id.
734 * Return a single event - by event id.
736 * Also get events with end date >= this date.
737 * @param bool $onlyPublic Include public events only, default TRUE.
738 * Include public events only, default TRUE.
741 * array of all the events that are searched
743 public static function &getCompleteInfo(
750 $publicCondition = NULL;
752 $publicCondition = " AND civicrm_event.is_public = 1";
756 // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133
758 // get events with start_date >= requested start
759 $startDate = CRM_Utils_Type
::escape($start, 'Date');
760 $dateCondition .= " AND ( civicrm_event.start_date >= {$startDate} )";
764 // also get events with end_date <= requested end
765 $endDate = CRM_Utils_Type
::escape($end, 'Date');
766 $dateCondition .= " AND ( civicrm_event.end_date <= '{$endDate}' ) ";
769 // CRM-9421 and CRM-8620 Default mode for ical/rss feeds. No start or end filter passed.
770 // Need to exclude old events with only start date
771 // and not exclude events in progress (start <= today and end >= today). DGG
772 if (empty($start) && empty($end)) {
773 // get events with end date >= today, not sure of this logic
774 // but keeping this for backward compatibility as per issue CRM-5133
775 $today = date("Y-m-d G:i:s");
776 $dateCondition .= " AND ( civicrm_event.end_date >= '{$today}' OR civicrm_event.start_date >= '{$today}' ) ";
780 $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type
::escape($type, 'Integer');
783 // Get the Id of Option Group for Event Types
784 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
785 $optionGroupDAO->name
= 'event_type';
786 $optionGroupId = NULL;
787 if ($optionGroupDAO->find(TRUE)) {
788 $optionGroupId = $optionGroupDAO->id
;
793 civicrm_event.id as event_id,
794 civicrm_email.email as email,
795 civicrm_event.title as title,
796 civicrm_event.summary as summary,
797 civicrm_event.start_date as start,
798 civicrm_event.end_date as end,
799 civicrm_event.description as description,
800 civicrm_event.is_show_location as is_show_location,
801 civicrm_event.is_online_registration as is_online_registration,
802 civicrm_event.registration_link_text as registration_link_text,
803 civicrm_event.registration_start_date as registration_start_date,
804 civicrm_event.registration_end_date as registration_end_date,
805 civicrm_option_value.label as event_type,
806 civicrm_address.name as address_name,
807 civicrm_address.street_address as street_address,
808 civicrm_address.supplemental_address_1 as supplemental_address_1,
809 civicrm_address.supplemental_address_2 as supplemental_address_2,
810 civicrm_address.supplemental_address_3 as supplemental_address_3,
811 civicrm_address.city as city,
812 civicrm_address.postal_code as postal_code,
813 civicrm_address.postal_code_suffix as postal_code_suffix,
814 civicrm_state_province.abbreviation as state,
815 civicrm_country.name AS country
817 LEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id
818 LEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id
819 LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
820 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
821 LEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id
822 LEFT JOIN civicrm_option_value ON (
823 civicrm_event.event_type_id = civicrm_option_value.value AND
824 civicrm_option_value.option_group_id = %1 )
825 WHERE civicrm_event.is_active = 1
826 AND (is_template = 0 OR is_template IS NULL)
830 if (isset($typeCondition)) {
831 $query .= $typeCondition;
834 if (isset($eventId)) {
835 $query .= " AND civicrm_event.id =$eventId ";
837 $query .= " ORDER BY civicrm_event.start_date ASC";
839 $params = [1 => [$optionGroupId, 'Integer']];
840 $dao = CRM_Core_DAO
::executeQuery($query, $params);
842 $config = CRM_Core_Config
::singleton();
844 $baseURL = parse_url($config->userFrameworkBaseURL
);
845 $url = "@" . $baseURL['host'];
846 if (!empty($baseURL['path'])) {
847 $url .= substr($baseURL['path'], 0, -1);
850 // check 'view event info' permission
851 //@todo - per CRM-14626 we have resolved that 'view event info' means 'view ALL event info'
852 // and passing in the specific permission here will short-circuit the evaluation of permission to
853 // see specific events (doesn't seem relevant to this call
854 // however, since this function is accessed only by a convoluted call from a joomla block function
855 // it seems safer not to touch here. Suggestion is that CRM_Core_Permission::check(array or relevant permissions) would
856 // be clearer & safer here
857 $permissions = CRM_Core_Permission
::event(CRM_Core_Permission
::VIEW
);
859 // check if we're in shopping cart mode for events
860 $enable_cart = Civi
::settings()->get('enable_cart');
863 while ($dao->fetch()) {
864 if (!empty($permissions) && in_array($dao->event_id
, $permissions)) {
866 $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL
) . $url;
868 $info['title'] = $dao->title
;
869 $info['event_id'] = $dao->event_id
;
870 $info['summary'] = $dao->summary
;
871 $info['description'] = $dao->description
;
872 $info['start_date'] = $dao->start
;
873 $info['end_date'] = $dao->end
;
874 $info['contact_email'] = $dao->email
;
875 $info['event_type'] = $dao->event_type
;
876 $info['is_show_location'] = $dao->is_show_location
;
877 $info['is_online_registration'] = $dao->is_online_registration
;
878 $info['registration_link_text'] = $dao->registration_link_text
;
879 $info['registration_start_date'] = $dao->registration_start_date
;
880 $info['registration_end_date'] = $dao->registration_end_date
;
885 'address_name' => $dao->address_name
,
886 'street_address' => $dao->street_address
,
887 'supplemental_address_1' => $dao->supplemental_address_1
,
888 'supplemental_address_2' => $dao->supplemental_address_2
,
889 'supplemental_address_3' => $dao->supplemental_address_3
,
890 'city' => $dao->city
,
891 'state_province' => $dao->state
,
892 'postal_code' => $dao->postal_code
,
893 'postal_code_suffix' => $dao->postal_code_suffix
,
894 'country' => $dao->country
,
898 CRM_Utils_String
::append($address, ', ',
899 CRM_Utils_Address
::format($addrFields)
901 $info['location'] = $address;
902 $info['url'] = CRM_Utils_System
::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id
, TRUE, NULL, FALSE);
905 $reg = CRM_Event_Cart_BAO_EventInCart
::get_registration_link($dao->event_id
);
906 $info['registration_link'] = CRM_Utils_System
::url($reg['path'], $reg['query'], TRUE);
907 $info['registration_link_text'] = $reg['label'];
918 * Make a copy of a Event.
920 * Include all the fields in the event Wizard.
923 * The event id to copy.
924 * @param array $params
926 * @return CRM_Event_DAO_Event
927 * @throws \CRM_Core_Exception
929 public static function copy($id, $params = []) {
932 //get the required event values.
933 $eventParams = ['id' => $id];
934 $returnProperties = [
938 'default_discount_fee_id',
942 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
944 $fieldsFix = ['prefix' => ['title' => ts('Copy of') . ' ']];
945 if (empty($eventValues['is_show_location'])) {
946 $fieldsFix['prefix']['is_show_location'] = 0;
949 $blockCopyOfCustomValue = (!empty($params['custom']));
951 $copyEvent = CRM_Core_DAO
::copyGeneric('CRM_Event_DAO_Event',
953 // since the location is sharable, lets use the same loc_block_id.
954 ['loc_block_id' => CRM_Utils_Array
::value('loc_block_id', $eventValues)] +
$params,
957 $blockCopyOfCustomValue
959 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_event', $id, $copyEvent->id
);
960 CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin',
963 'entity_table' => 'civicrm_event',
965 ['entity_id' => $copyEvent->id
]
968 CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend',
971 'entity_table' => 'civicrm_event',
973 ['entity_id' => $copyEvent->id
]
976 CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock',
979 'entity_table' => 'civicrm_event',
981 ['entity_id' => $copyEvent->id
],
982 ['replace' => ['target_entity_id' => $copyEvent->id
]]
985 $oldMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
986 'id' => ($eventValues['is_template'] ? CRM_Event_ActionMapping
::EVENT_TPL_MAPPING_ID
: CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
),
988 $copyMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
989 'id' => ($copyEvent->is_template
== 1 ? CRM_Event_ActionMapping
::EVENT_TPL_MAPPING_ID
: CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
),
991 CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_ActionSchedule',
992 ['entity_value' => $id, 'mapping_id' => $oldMapping->getId()],
993 ['entity_value' => $copyEvent->id
, 'mapping_id' => $copyMapping->getId()]
998 if ($blockCopyOfCustomValue) {
999 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_event', $copyEvent->id
);
1002 CRM_Utils_System
::flushCache();
1003 CRM_Utils_Hook
::copy('Event', $copyEvent);
1009 * This is sometimes called in a loop (during event search).
1011 * We cache the values to prevent repeated calls to the db.
1017 public static function isMonetary($id) {
1018 static $isMonetary = [];
1019 if (!array_key_exists($id, $isMonetary)) {
1020 $isMonetary[$id] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1025 return $isMonetary[$id];
1029 * This is sometimes called in a loop (during event search).
1031 * We cache the values to prevent repeated calls to the db.
1037 public static function usesPriceSet($id) {
1038 static $usesPriceSet = [];
1039 if (!array_key_exists($id, $usesPriceSet)) {
1040 $usesPriceSet[$id] = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $id);
1042 return $usesPriceSet[$id];
1048 * @param int $contactID
1049 * @param array $values
1050 * @param int $participantId
1051 * @param bool $isTest
1052 * @param bool $returnMessageText
1054 * @return array|null
1055 * @throws \CiviCRM_API3_Exception
1057 public static function sendMail($contactID, $values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) {
1059 $template = CRM_Core_Smarty
::singleton();
1061 'custom_pre_id' => $values['custom_pre_id'],
1062 'custom_post_id' => $values['custom_post_id'],
1065 //get the params submitted by participant.
1066 $participantParams = CRM_Utils_Array
::value($participantId, $values['params'], []);
1068 if (!$returnMessageText) {
1069 //send notification email if field values are set (CRM-1941)
1070 foreach ($gIds as $key => $gIdValues) {
1072 if (!is_array($gIdValues)) {
1073 $gIdValues = [$gIdValues];
1076 foreach ($gIdValues as $gId) {
1077 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
1079 //get values of corresponding profile fields for notification
1080 list($profileValues) = self
::buildCustomDisplay($gId,
1089 list($profileValues) = $profileValues;
1092 'values' => $profileValues,
1095 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
1102 if ($values['event']['is_email_confirm'] ||
$returnMessageText) {
1103 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
1105 //send email only when email is present
1106 if (isset($email) ||
$returnMessageText) {
1107 $preProfileID = CRM_Utils_Array
::value('custom_pre_id', $values);
1108 $postProfileID = CRM_Utils_Array
::value('custom_post_id', $values);
1110 if (!empty($values['params']['additionalParticipant'])) {
1111 $preProfileID = CRM_Utils_Array
::value('additional_custom_pre_id', $values, $preProfileID);
1112 $postProfileID = CRM_Utils_Array
::value('additional_custom_post_id', $values, $postProfileID);
1115 $profilePre = self
::buildCustomDisplay($preProfileID,
1125 $profilePost = self
::buildCustomDisplay($postProfileID,
1135 $sessions = CRM_Event_Cart_BAO_Conference
::get_participant_sessions($participantId);
1137 // @todo - the goal is that all params available to the message template are explicitly defined here rather than
1138 // 'in a smattering of places'. Note that leakage can happen between mailings when not explicitly defined.
1139 $tplParams = array_merge($values, $participantParams, [
1141 'confirm_email_text' => CRM_Utils_Array
::value('confirm_email_text', $values['event']),
1142 'isShowLocation' => CRM_Utils_Array
::value('is_show_location', $values['event']),
1143 // The concept of contributeMode is deprecated.
1144 'contributeMode' => CRM_Utils_Array
::value('contributeMode', $template->_tpl_vars
),
1145 'customPre' => $profilePre[0],
1146 'customPre_grouptitle' => empty($profilePre[1]) ?
NULL : [CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $preProfileID)],
1147 'customPost' => $profilePost[0],
1148 'customPost_grouptitle' => empty($profilePost[1]) ?
NULL : [CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $postProfileID)],
1149 'participantID' => $participantId,
1150 'conference_sessions' => $sessions,
1151 'credit_card_number' => CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $participantParams)),
1152 'credit_card_exp_date' => CRM_Utils_Date
::mysqlToIso(CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $participantParams))),
1155 // CRM-13890 : NOTE wait list condition need to be given so that
1156 // wait list message is shown properly in email i.e. WRT online event registration template
1157 if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) {
1158 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id', TRUE);
1159 $tplParams['participant_status'] = CRM_Event_PseudoConstant
::participantStatus($statusId, NULL, 'label');
1161 //CRM-15754 - if participant_status contains status ID
1162 elseif (!empty($tplParams['participant_status']) && CRM_Utils_Rule
::integer($tplParams['participant_status'])) {
1163 $tplParams['participant_status'] = CRM_Event_PseudoConstant
::participantStatus($tplParams['participant_status'], NULL, 'label');
1166 $sendTemplateParams = [
1167 'groupName' => 'msg_tpl_workflow_event',
1168 'valueName' => 'event_online_receipt',
1169 'contactId' => $contactID,
1170 'isTest' => $isTest,
1171 'tplParams' => $tplParams,
1172 'PDFFilename' => ts('confirmation') . '.pdf',
1175 // address required during receipt processing (pdf and email receipt)
1176 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
1177 $sendTemplateParams['tplParams']['address'] = $displayAddress;
1178 // The concept of contributeMode is deprecated.
1179 $sendTemplateParams['tplParams']['contributeMode'] = NULL;
1182 // set lineItem details
1183 if ($lineItem = CRM_Utils_Array
::value('lineItem', $values)) {
1184 // check if additional participant, if so filter only to relevant ones
1186 if (!empty($values['params']['additionalParticipant'])) {
1188 foreach ($lineItem as $liKey => $liValue) {
1189 $firstElement = array_pop($liValue);
1190 if ($firstElement['entity_id'] == $participantId) {
1191 $ownLineItems[0] = $lineItem[$liKey];
1195 if (!empty($ownLineItems)) {
1196 $sendTemplateParams['tplParams']['lineItem'] = $ownLineItems;
1200 $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
1204 if ($returnMessageText) {
1205 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1207 'subject' => $subject,
1209 'to' => $displayName,
1214 $sendTemplateParams['from'] = CRM_Utils_Array
::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array
::value('confirm_from_email', $values['event']) . ">";
1215 $sendTemplateParams['toName'] = $displayName;
1216 $sendTemplateParams['toEmail'] = $email;
1217 $sendTemplateParams['autoSubmitted'] = TRUE;
1218 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_confirm',
1221 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_confirm',
1224 // append invoice pdf to email
1225 $template = CRM_Core_Smarty
::singleton();
1226 $taxAmt = $template->get_template_vars('totalTaxAmount');
1227 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
1228 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
1229 if (isset($invoicing) && isset($prefixValue['is_email_pdf']) && !empty($values['contributionId'])) {
1230 $sendTemplateParams['isEmailPdf'] = TRUE;
1231 $sendTemplateParams['contributionId'] = $values['contributionId'];
1233 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1240 * Add the custom fields OR array of participant's profile info.
1243 * @param string $name
1245 * @param string $template
1246 * @param int $participantId
1247 * @param bool $isTest
1248 * @param bool $returnResults
1249 * @param array $participantParams
1251 * @return array|null
1252 * @throws \CRM_Core_Exception
1254 public static function buildCustomDisplay(
1261 $returnResults = FALSE,
1262 $participantParams = []
1265 return [NULL, NULL];
1268 if (!is_array($id)) {
1269 $id = CRM_Utils_Type
::escape($id, 'Positive');
1270 $profileIds = [$id];
1276 $val = $groupTitles = NULL;
1277 foreach ($profileIds as $gid) {
1278 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
1280 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
,
1281 NULL, NULL, FALSE, NULL,
1282 FALSE, NULL, CRM_Core_Permission
::CREATE
,
1286 //this condition is added, since same contact can have multiple event registrations..
1287 $params = [['participant_id', '=', $participantId, 0, 0]];
1289 //add participant id
1290 $fields['participant_id'] = [
1291 'name' => 'participant_id',
1292 'title' => ts('Participant ID'),
1294 //check whether its a text drive
1296 $params[] = ['participant_test', '=', 1, 0, 0];
1299 //display campaign on thankyou page.
1300 if (array_key_exists('participant_campaign_id', $fields)) {
1301 if ($participantId) {
1302 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
1306 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
1307 $values[$fields['participant_campaign_id']['title']] = CRM_Utils_Array
::value($campaignId,
1311 unset($fields['participant_campaign_id']);
1315 foreach ($fields as $k => $v) {
1317 $groupTitle = $v['groupTitle'];
1319 // suppress all file fields from display
1321 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
1322 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
1323 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
1330 $groupTitles[] = $groupTitle;
1332 //display profile groups those are subscribed by participant.
1333 if (($groups = CRM_Utils_Array
::value('group', $participantParams)) &&
1337 foreach ($groups as $grpId => $isSelected) {
1342 if (!empty($grpIds)) {
1343 //get the group titles.
1345 $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )';
1346 $grp = CRM_Core_DAO
::executeQuery($query);
1347 while ($grp->fetch()) {
1348 $grpTitles[] = $grp->title
;
1350 if (!empty($grpTitles) &&
1351 CRM_Utils_Array
::value('title', CRM_Utils_Array
::value('group', $fields))
1353 $values[$fields['group']['title']] = implode(', ', $grpTitles);
1355 unset($fields['group']);
1359 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
1361 if (isset($fields['participant_status_id']['title']) &&
1362 isset($values[$fields['participant_status_id']['title']]) &&
1363 is_numeric($values[$fields['participant_status_id']['title']])
1366 $status = CRM_Event_PseudoConstant
::participantStatus();
1367 $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]];
1370 if (isset($fields['participant_role_id']['title']) &&
1371 isset($values[$fields['participant_role_id']['title']]) &&
1372 is_numeric($values[$fields['participant_role_id']['title']])
1375 $roles = CRM_Event_PseudoConstant
::participantRole();
1376 $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]];
1379 if (isset($fields['participant_register_date']['title']) &&
1380 isset($values[$fields['participant_register_date']['title']])
1382 $values[$fields['participant_register_date']['title']] = CRM_Utils_Date
::customFormat($values[$fields['participant_register_date']['title']]);
1385 //handle fee_level for price set
1386 if (isset($fields['participant_fee_level']['title']) &&
1387 isset($values[$fields['participant_fee_level']['title']])
1389 $feeLevel = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1390 $values[$fields['participant_fee_level']['title']]
1392 foreach ($feeLevel as $key => $value) {
1394 unset($feeLevel[$key]);
1397 $values[$fields['participant_fee_level']['title']] = implode(',', $feeLevel);
1400 unset($values[$fields['participant_id']['title']]);
1407 $template->assign($name, $val);
1410 if (count($groupTitles)) {
1411 $template->assign($name . '_grouptitle', $groupTitles);
1414 //return if we only require array of participant's info.
1415 if ($returnResults) {
1417 return [$val, $groupTitles];
1426 * Build the array for display the profile fields.
1428 * @param array $params
1432 * @param array $groupTitle
1433 * Profile Group Title.
1434 * @param array $values
1435 * Formatted array of key value.
1437 * @param array $profileFields
1439 * @throws \CRM_Core_Exception
1440 * @throws \API_Exception
1441 * @throws \CiviCRM_API3_Exception
1443 public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) {
1445 $config = CRM_Core_Config
::singleton();
1446 $session = CRM_Core_Session
::singleton();
1447 $contactID = $session->get('userID');
1449 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $contactID)) {
1450 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
);
1454 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::ADD
);
1457 if (!empty($fields)) {
1458 $groupTitle['groupTitle'] = CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $gid);
1461 $imProviders = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_IM', 'provider_id');
1462 //start of code to set the default values
1463 foreach ($fields as $name => $field) {
1466 // skip fields that should not be displayed separately
1467 if ($field['skipDisplay']) {
1471 $index = $field['title'];
1472 if ($name === 'organization_name') {
1473 $values[$index] = $params[$name];
1476 if ('state_province' == substr($name, 0, 14)) {
1477 if ($params[$name]) {
1478 $values[$index] = CRM_Core_PseudoConstant
::stateProvince($params[$name]);
1481 $values[$index] = '';
1484 elseif ('date' == substr($name, -4)) {
1485 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::processDate($params[$name]),
1486 $config->dateformatFull
);
1488 elseif ('country' == substr($name, 0, 7)) {
1489 if ($params[$name]) {
1490 $values[$index] = CRM_Core_PseudoConstant
::country($params[$name]);
1493 $values[$index] = '';
1496 elseif ('county' == substr($name, 0, 6)) {
1497 if ($params[$name]) {
1498 $values[$index] = CRM_Core_PseudoConstant
::county($params[$name]);
1501 $values[$index] = '';
1504 elseif (in_array(substr($name, 0, -3), ['gender', 'prefix', 'suffix', 'communication_style'])) {
1505 $values[$index] = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
1507 elseif (in_array($name, [
1512 $filterCondition = ['greeting_type' => $name];
1513 $greeting = CRM_Core_PseudoConstant
::greeting($filterCondition);
1514 $values[$index] = $greeting[$params[$name]];
1516 elseif ($name === 'preferred_communication_method') {
1517 $communicationFields = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
1519 $pref = $params[$name];
1520 if (is_array($pref)) {
1521 foreach ($pref as $k => $v) {
1523 $compref[] = $communicationFields[$k];
1527 $values[$index] = implode(',', $compref);
1529 elseif ($name == 'contact_sub_type') {
1530 $values[$index] = implode(', ', $params[$name]);
1532 elseif ($name == 'group') {
1533 $groups = CRM_Contact_BAO_GroupContact
::getGroupList();
1535 foreach ($params[$name] as $gId => $dontCare) {
1537 $title[] = $groups[$gId];
1540 $values[$index] = implode(', ', $title);
1542 elseif ($name == 'tag') {
1543 $entityTags = $params[$name];
1544 $allTags = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]);
1546 if (is_array($entityTags)) {
1547 foreach ($entityTags as $tagId => $dontCare) {
1548 $title[] = $allTags[$tagId];
1551 $values[$index] = implode(', ', $title);
1553 elseif ('participant_role_id' == $name or
1554 'participant_role' == $name
1556 $roles = CRM_Event_PseudoConstant
::participantRole();
1557 $values[$index] = $roles[$params[$name]];
1559 elseif ('participant_status_id' == $name or
1560 'participant_status' == $name
1562 $status = CRM_Event_PseudoConstant
::participantStatus();
1563 $values[$index] = $status[$params[$name]];
1565 elseif (substr($name, -11) == 'campaign_id') {
1566 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($params[$name]);
1567 $values[$index] = CRM_Utils_Array
::value($params[$name], $campaigns);
1569 elseif (strpos($name, '-') !== FALSE) {
1570 list($fieldName, $id) = CRM_Utils_System
::explode('-', $name, 2);
1571 $detailName = str_replace(' ', '_', $name);
1572 if (in_array($fieldName, [
1577 $values[$index] = $params[$detailName];
1578 $idx = $detailName . '_id';
1579 $values[$index] = $params[$idx];
1581 elseif ($fieldName == 'im') {
1582 $providerName = NULL;
1583 if ($providerId = $detailName . '-provider_id') {
1584 $providerName = CRM_Utils_Array
::value($params[$providerId], $imProviders);
1586 if ($providerName) {
1587 $values[$index] = $params[$detailName] . " (" . $providerName . ")";
1590 $values[$index] = $params[$detailName];
1593 elseif ($fieldName == 'phone') {
1594 $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
1595 if (isset($params[$phoneExtField])) {
1596 $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
1599 $values[$index] = $params[$detailName];
1603 $values[$index] = $params[$detailName];
1607 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
1608 if ($params[$name]) {
1609 $values[$index] = '[ x ]';
1613 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
1615 SELECT html_type, data_type
1616 FROM civicrm_custom_field
1619 $dao = CRM_Core_DAO
::executeQuery($query);
1621 $htmlType = $dao->html_type
;
1623 if ($htmlType == 'File') {
1624 $path = CRM_Utils_Array
::value('name', $params[$name]);
1625 $fileType = CRM_Utils_Array
::value('type', $params[$name]);
1626 $values[$index] = CRM_Utils_File
::getFileURL($path, $fileType);
1629 if ($dao->data_type
== 'Int' ||
1630 $dao->data_type
== 'Boolean'
1632 $v = $params[$name];
1633 if (!CRM_Utils_System
::isNull($v)) {
1634 $customVal = (int) $v;
1637 elseif ($dao->data_type
== 'Float') {
1638 $customVal = (float ) ($params[$name]);
1640 elseif ($dao->data_type
== 'Date') {
1641 //@todo note the currently we are using default date time formatting. Since you can select/set
1642 // different date and time format specific to custom field we should consider fixing this
1643 // sometime in the future
1644 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1645 CRM_Utils_Date
::processDate($params[$name]), $config->dateformatFull
);
1647 if (!empty($params[$name . '_time'])) {
1648 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1649 CRM_Utils_Date
::processDate($params[$name], $params[$name . '_time']),
1650 $config->dateformatDatetime
);
1654 // for checkboxes, change array of [key => bool] to array of [idx => key]
1655 elseif ($dao->html_type
== 'CheckBox') {
1656 $customVal = array_keys(array_filter($params[$name]));
1659 $customVal = $params[$name];
1661 //take the custom field options
1662 $returnProperties = [$name => 1];
1663 $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
1665 $displayValue = CRM_Core_BAO_CustomField
::displayValue($customVal, $cfID);
1667 //Hack since we dont have function to check empty.
1668 //FIXME in 2.3 using crmIsEmptyArray()
1669 $customValue = TRUE;
1670 if (is_array($customVal) && is_array($displayValue)) {
1671 $customValue = array_diff($customVal, $displayValue);
1673 //use difference of arrays
1674 if (empty($customValue) ||
!$customValue) {
1675 $values[$index] = '';
1678 $values[$index] = $displayValue;
1682 elseif ($name == 'home_URL' &&
1683 !empty($params[$name])
1685 $url = CRM_Utils_System
::fixURL($params[$name]);
1686 $values[$index] = "<a href=\"$url\">{$params[$name]}</a>";
1688 elseif (in_array($name, [
1691 'participant_register_date',
1693 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::format($params[$name]));
1696 $values[$index] = CRM_Utils_Array
::value($name, $params);
1700 $profileFields[$name] = $field;
1706 * Build the array for Additional participant's information array of primary and additional Ids.
1708 * @param int $participantId
1709 * Id of Primary participant.
1710 * @param array $values
1711 * Key/value event info.
1712 * @param int $contactId
1713 * Contact id of Primary participant.
1714 * @param bool $isTest
1715 * Whether test or live transaction.
1716 * @param bool $isIdsArray
1717 * To return an array of Ids.
1719 * @param bool $skipCancel
1722 * array of Additional participant's info OR array of Ids.
1724 public static function buildCustomProfile(
1729 $isIdsArray = FALSE,
1733 $customProfile = $additionalIDs = [];
1734 if (!$participantId) {
1735 CRM_Core_Error
::fatal(ts('Cannot find participant ID'));
1738 //set Ids of Primary Participant also.
1739 if ($isIdsArray && $contactId) {
1740 $additionalIDs[$participantId] = $contactId;
1743 //hack to skip cancelled participants, CRM-4320
1744 $where = "participant.registered_by_id={$participantId}";
1746 $cancelStatusId = 0;
1747 $negativeStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
1748 $cancelStatusId = array_search('Cancelled', $negativeStatuses);
1749 $where .= " AND participant.status_id != {$cancelStatusId}";
1752 SELECT participant.id, participant.contact_id
1753 FROM civicrm_participant participant
1756 $dao = CRM_Core_DAO
::executeQuery($query);
1757 while ($dao->fetch()) {
1758 $additionalIDs[$dao->id
] = $dao->contact_id
;
1761 //return if only array is required.
1762 if ($isIdsArray && $contactId) {
1763 return $additionalIDs;
1766 $preProfileID = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
1767 $postProfileID = CRM_Utils_Array
::value('additional_custom_post_id', $values);
1768 //else build array of Additional participant's information.
1769 if (count($additionalIDs)) {
1770 if ($preProfileID ||
$postProfileID) {
1771 $template = CRM_Core_Smarty
::singleton();
1773 $isCustomProfile = TRUE;
1775 $title = $groupTitles = [];
1776 foreach ($additionalIDs as $pId => $cId) {
1777 //get the params submitted by participant.
1778 $participantParams = NULL;
1779 if (isset($values['params'])) {
1780 $participantParams = CRM_Utils_Array
::value($pId, $values['params'], []);
1783 list($profilePre, $groupTitles) = self
::buildCustomDisplay($preProfileID,
1784 'additionalCustomPre',
1794 $profile = $profilePre;
1795 // $customProfile[$i] = array_merge( $groupTitles, $customProfile[$i] );
1797 $title = $groupTitles;
1801 list($profilePost, $groupTitles) = self
::buildCustomDisplay($postProfileID,
1802 'additionalCustomPost',
1812 if (isset($profilePre)) {
1813 $profile = array_merge($profilePre, $profilePost);
1815 $title = array_merge($title, $groupTitles);
1819 $profile = $profilePost;
1821 $title = $groupTitles;
1825 $profiles[] = $profile;
1828 $customProfile['title'] = $title;
1829 $customProfile['profile'] = $profiles;
1833 return $customProfile;
1837 * Retrieve all event addresses.
1841 public static function getLocationEvents() {
1845 'loc_block_id.address_id.name',
1846 'loc_block_id.address_id.street_address',
1847 'loc_block_id.address_id.supplemental_address_1',
1848 'loc_block_id.address_id.supplemental_address_2',
1849 'loc_block_id.address_id.supplemental_address_3',
1850 'loc_block_id.address_id.city',
1851 'loc_block_id.address_id.state_province_id.name',
1854 $result = civicrm_api3('Event', 'get', [
1855 'check_permissions' => TRUE,
1857 'loc_block_id.address_id' => ['IS NOT NULL' => 1],
1863 foreach ($result['values'] as $event) {
1865 foreach ($ret as $field) {
1866 if ($field != 'loc_block_id' && !empty($event[$field])) {
1867 $address .= ($address ?
' :: ' : '') . $event[$field];
1871 $events[$event['loc_block_id']] = $address;
1875 return CRM_Utils_Array
::asort($events);
1879 * @param int $locBlockId
1881 * @return int|null|string
1883 public static function countEventsUsingLocBlockId($locBlockId) {
1888 $locBlockId = CRM_Utils_Type
::escape($locBlockId, 'Integer');
1891 SELECT count(*) FROM civicrm_event ce
1892 WHERE ce.loc_block_id = $locBlockId";
1894 return CRM_Core_DAO
::singleValueQuery($query);
1898 * Check if event registration is valid according to permissions AND Dates.
1900 * @param array $values
1901 * @param int $eventID
1904 public static function validRegistrationRequest($values, $eventID) {
1905 // check that the user has permission to register for this event
1906 $hasPermission = CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
,
1907 $eventID, 'register for events'
1910 return $hasPermission && self
::validRegistrationDate($values);
1918 public static function validRegistrationDate(&$values) {
1919 // make sure that we are between registration start date and end dates
1920 // and that if the event has ended, registration is still specifically open
1921 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $values));
1922 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $values));
1923 $eventEnd = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $values));
1926 if ($startDate && $startDate >= $now) {
1929 elseif ($endDate && $endDate < $now) {
1932 elseif ($eventEnd && $eventEnd < $now && !$endDate) {
1939 /* Function to Show - Hide the Registration Link.
1941 * @param array $values
1942 * Key/value event info.
1944 * true if allow registration otherwise false
1952 public static function showHideRegistrationLink($values) {
1954 $session = CRM_Core_Session
::singleton();
1955 $contactID = $session->get('userID');
1956 $alreadyRegistered = FALSE;
1959 $params = ['contact_id' => $contactID];
1961 if ($eventId = CRM_Utils_Array
::value('id', $values['event'])) {
1962 $params['event_id'] = $eventId;
1964 if ($roleId = CRM_Utils_Array
::value('default_role_id', $values['event'])) {
1965 $params['role_id'] = $roleId;
1967 $alreadyRegistered = self
::checkRegistration($params);
1970 if (!empty($values['event']['allow_same_participant_emails']) ||
1978 /* Function to check if given contact is already registered.
1980 * @param array $params
1981 * Key/value participant info.
1986 * @param array $params
1990 public static function checkRegistration($params) {
1991 $alreadyRegistered = FALSE;
1992 if (empty($params['contact_id'])) {
1993 return $alreadyRegistered;
1996 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
1998 $participant = new CRM_Event_DAO_Participant();
1999 $participant->copyValues($params);
2001 $participant->is_test
= CRM_Utils_Array
::value('is_test', $params, 0);
2002 $participant->selectAdd();
2003 $participant->selectAdd('status_id');
2004 if ($participant->find(TRUE) && array_key_exists($participant->status_id
, $statusTypes)) {
2005 $alreadyRegistered = TRUE;
2008 return $alreadyRegistered;
2012 * Make sure that the user has permission to access this event.
2013 * FIXME: We have separate caches for checkPermission('permission') and getAllPermissions['permissions'] so they don't interfere.
2014 * But it would be nice to clean this up some more.
2016 * @param int $eventId
2017 * @param int $permissionType
2019 * @return bool|array
2020 * Whether the user has permission for this event (or if eventId=NULL an array of permissions)
2021 * @throws \CiviCRM_API3_Exception
2023 public static function checkPermission($eventId = NULL, $permissionType = CRM_Core_Permission
::VIEW
) {
2024 if (empty($eventId)) {
2025 CRM_Core_Error
::deprecatedFunctionWarning('CRM_Event_BAO_Event::getAllPermissions');
2026 return self
::getAllPermissions();
2029 switch ($permissionType) {
2030 case CRM_Core_Permission
::EDIT
:
2031 // We also set the cached "view" permission to TRUE if "edit" is TRUE
2032 if (isset(Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId])) {
2033 return Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId];
2035 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = FALSE;
2037 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo($eventId);
2038 // Note: for a multisite setup, a user with edit all events, can edit all events
2039 // including those from other sites
2040 if (($permissionType == CRM_Core_Permission
::EDIT
) && CRM_Core_Permission
::check('edit all events')) {
2041 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = TRUE;
2042 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2044 elseif (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_event', $allEvents, $createdEvents))) {
2045 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = TRUE;
2046 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2048 return Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId];
2050 case CRM_Core_Permission
::VIEW
:
2051 if (isset(Civi
::$statics[__CLASS__
]['permission']['view'][$eventId])) {
2052 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId];
2054 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = FALSE;
2056 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo($eventId);
2057 if (CRM_Core_Permission
::check('access CiviEvent')) {
2058 if (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, array_keys($createdEvents)))) {
2059 // User created this event so has permission to view it
2060 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2062 if (CRM_Core_Permission
::check('view event participants')) {
2063 // User has permission to view all events
2064 // use case: allow "view all events" but NOT "edit all events"
2065 // so for a normal site allow users with these two permissions to view all events AND
2066 // at the same time also allow any hook to override if needed.
2067 if (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, array_keys($allEvents)))) {
2068 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2072 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId];
2074 case CRM_Core_Permission
::DELETE
:
2075 if (isset(Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId])) {
2076 return Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId];
2078 Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId] = FALSE;
2079 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
2080 Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId] = TRUE;
2082 return Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId];
2090 * This is a helper for refactoring checkPermission
2091 * FIXME: We should be able to get rid of these arrays, but that would require understanding how CRM_ACL_API::group actually works!
2093 * @param int $eventId
2095 * @return array $allEvents, $createdEvents
2096 * @throws \CiviCRM_API3_Exception
2098 private static function checkPermissionGetInfo($eventId = NULL) {
2100 'check_permissions' => 1,
2101 'return' => 'id, created_id',
2102 'options' => ['limit' => 0],
2105 $params['id'] = $eventId;
2109 $createdEvents = [];
2110 $eventResult = civicrm_api3('Event', 'get', $params);
2111 if ($eventResult['count'] > 0) {
2112 $contactId = CRM_Core_Session
::getLoggedInContactID();
2113 foreach ($eventResult['values'] as $eventId => $eventDetail) {
2114 $allEvents[$eventId] = $eventId;
2115 if (isset($eventDetail['created_id']) && $contactId == $eventDetail['created_id']) {
2116 $createdEvents[$eventId] = $eventId;
2120 return [$allEvents, $createdEvents];
2124 * Make sure that the user has permission to access this event.
2125 * TODO: This function needs refactoring / cleaning up after being split from checkPermissions()
2128 * Array of events with permissions (array_keys=permissions)
2129 * @throws \CiviCRM_API3_Exception
2131 public static function getAllPermissions() {
2132 if (!isset(Civi
::$statics[__CLASS__
]['permissions'])) {
2133 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo();
2135 // Note: for a multisite setup, a user with edit all events, can edit all events
2136 // including those from other sites
2137 if (CRM_Core_Permission
::check('edit all events')) {
2138 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
] = array_keys($allEvents);
2141 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
] = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_event', $allEvents, $createdEvents);
2144 if (CRM_Core_Permission
::check('edit all events')) {
2145 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
] = array_keys($allEvents);
2148 if (CRM_Core_Permission
::check('access CiviEvent') &&
2149 CRM_Core_Permission
::check('view event participants')
2151 // use case: allow "view all events" but NOT "edit all events"
2152 // so for a normal site allow users with these two permissions to view all events AND
2153 // at the same time also allow any hook to override if needed.
2154 $createdEvents = array_keys($allEvents);
2156 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
] = CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, $createdEvents);
2159 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::DELETE
] = [];
2160 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
2161 // Note: we want to restrict the scope of delete permission to
2162 // events that are editable/viewable (usecase multisite).
2163 // We can remove array_intersect once we have ACL support for delete functionality.
2164 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::DELETE
] = array_intersect(Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
],
2165 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
]
2170 return Civi
::$statics[__CLASS__
]['permissions'];
2174 * Build From Email as the combination of all the email ids of the logged in user,
2175 * the domain email id and the email id configured for the event
2177 * @param int $eventId
2178 * The id of the event.
2181 * an array of email ids
2183 public static function getFromEmailIds($eventId = NULL) {
2184 $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email
::getFromEmail();
2187 // add the email id configured for the event
2188 $params = ['id' => $eventId];
2189 $returnProperties = ['confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm'];
2192 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $params, $eventEmail, $returnProperties);
2193 if (!empty($eventEmail['confirm_from_name']) && !empty($eventEmail['confirm_from_email'])) {
2194 $eventEmailId = "{$eventEmail['confirm_from_name']} <{$eventEmail['confirm_from_email']}>";
2196 $fromEmailValues['from_email_id'][$eventEmailId] = htmlspecialchars($eventEmailId);
2198 'cc' => CRM_Utils_Array
::value('cc_confirm', $eventEmail),
2199 'bcc' => CRM_Utils_Array
::value('bcc_confirm', $eventEmail),
2201 $fromEmailValues = array_merge($fromEmailValues, $fromEmailId);
2205 return $fromEmailValues;
2209 * Calculate event total seats occupied.
2211 * @param int $eventId
2213 * @param sting $extraWhereClause
2214 * Extra filter on participants.
2217 * event total seats w/ given criteria.
2219 public static function eventTotalSeats($eventId, $extraWhereClause = NULL) {
2220 if (empty($eventId)) {
2224 $extraWhereClause = trim($extraWhereClause);
2225 if (!empty($extraWhereClause)) {
2226 $extraWhereClause = " AND ( {$extraWhereClause} )";
2229 //event seats calculation :
2230 //1. consider event seat as a single when participant does not have line item.
2231 //2. consider event seat as a single when participant has line items but does not
2232 // have count for corresponding price field value ( ie price field value does not carry any seat )
2233 //3. consider event seat as a sum of all seats from line items in case price field value carries count.
2236 SELECT IF ( SUM( value.count*lineItem.qty ),
2237 SUM( value.count*lineItem.qty ) +
2238 COUNT( DISTINCT participant.id ) -
2239 COUNT( DISTINCT IF ( value.count, participant.id, NULL ) ),
2240 COUNT( DISTINCT participant.id ) )
2241 FROM civicrm_participant participant
2242 INNER JOIN civicrm_contact contact ON ( contact.id = participant.contact_id AND contact.is_deleted = 0 )
2243 INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
2244 LEFT JOIN civicrm_line_item lineItem ON ( lineItem.entity_id = participant.id
2245 AND lineItem.entity_table = 'civicrm_participant' )
2246 LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id AND value.count )
2247 WHERE ( participant.event_id = %1 )
2248 AND participant.is_test = 0
2250 GROUP BY participant.event_id";
2252 return (int) CRM_Core_DAO
::singleValueQuery($query, [1 => [$eventId, 'Positive']]);
2256 * Retrieve event template default values to be set.
2257 * as default values for current new event.
2259 * @param int $templateId
2260 * Event template id.
2263 * Array of custom data defaults.
2265 public static function getTemplateDefaultValues($templateId) {
2271 $templateParams = ['id' => $templateId];
2272 CRM_Event_BAO_Event
::retrieve($templateParams, $defaults);
2273 $fieldsToExclude = [
2276 'default_discount_fee_id',
2282 $defaults = array_diff_key($defaults, array_flip($fieldsToExclude));
2287 * @param int $event_id
2291 public static function get_sub_events($event_id) {
2292 $params = ['parent_event_id' => $event_id];
2294 return CRM_Event_BAO_Event
::retrieve($params, $defaults);
2298 * Update the Campaign Id of all the participants of the given event.
2300 * @param int $eventID
2302 * @param int $eventCampaignID
2303 * Campaign id of that event.
2305 public static function updateParticipantCampaignID($eventID, $eventCampaignID) {
2307 $params[1] = [$eventID, 'Integer'];
2309 if (empty($eventCampaignID)) {
2310 $query = "UPDATE civicrm_participant SET campaign_id = NULL WHERE event_id = %1";
2313 $query = "UPDATE civicrm_participant SET campaign_id = %2 WHERE event_id = %1";
2314 $params[2] = [$eventCampaignID, 'Integer'];
2316 CRM_Core_DAO
::executeQuery($query, $params);
2320 * Get options for a given field.
2321 * @see CRM_Core_DAO::buildOptions
2323 * @param string $fieldName
2324 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
2325 * @param array $props : whatever is known about this dao object
2327 * @return array|bool
2329 public static function buildOptions($fieldName, $context = NULL, $props = []) {
2331 // Special logic for fields whose options depend on context or properties
2332 switch ($fieldName) {
2333 case 'financial_type_id':
2334 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
2335 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
2339 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
2345 public static function getEntityRefFilters() {
2347 ['key' => 'event_type_id', 'value' => ts('Event Type')],
2349 'key' => 'start_date',
2350 'value' => ts('Start Date'),
2352 ['key' => '{">":"now"}', 'value' => ts('Upcoming')],
2354 'key' => '{"BETWEEN":["now - 3 month","now"]}',
2355 'value' => ts('Past 3 Months'),
2358 'key' => '{"BETWEEN":["now - 6 month","now"]}',
2359 'value' => ts('Past 6 Months'),
2362 'key' => '{"BETWEEN":["now - 1 year","now"]}',
2363 'value' => ts('Past Year'),