3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Event_BAO_Event
extends CRM_Event_DAO_Event
{
22 public function __construct() {
23 parent
::__construct();
27 * Fetch object based on array of properties.
29 * @param array $params
30 * (reference ) an assoc array of name/value pairs.
31 * @param array $defaults
32 * (reference ) an assoc array to hold the flattened values.
34 * @return CRM_Event_DAO_Event
36 public static function retrieve(&$params, &$defaults) {
37 $event = new CRM_Event_DAO_Event();
38 $event->copyValues($params);
39 if ($event->find(TRUE)) {
40 CRM_Core_DAO
::storeValues($event, $defaults);
47 * Update the is_active flag in the db.
50 * Id of the database record.
51 * @param bool $is_active
52 * Value we want to set the is_active field.
55 * true if we found and updated the object, else false
57 public static function setIsActive($id, $is_active) {
58 return CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Event', $id, 'is_active', $is_active);
64 * @param array $params
65 * Reference array contains the values submitted by the form.
67 * @return CRM_Event_DAO_Event
69 public static function add(&$params) {
70 $financialTypeId = NULL;
71 if (!empty($params['id'])) {
72 CRM_Utils_Hook
::pre('edit', 'Event', $params['id'], $params);
73 if (empty($params['skipFinancialType'])) {
74 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['id'], 'financial_type_id');
78 CRM_Utils_Hook
::pre('create', 'Event', NULL, $params);
81 $event = new CRM_Event_DAO_Event();
83 $event->copyValues($params);
84 $result = $event->save();
86 if (!empty($params['id'])) {
87 CRM_Utils_Hook
::post('edit', 'Event', $event->id
, $event);
90 CRM_Utils_Hook
::post('create', 'Event', $event->id
, $event);
92 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
93 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_event', $params['financial_type_id']);
101 * @param array $params
102 * Reference array contains the values submitted by the form.
106 public static function create(&$params) {
107 $transaction = new CRM_Core_Transaction();
108 if (empty($params['is_template'])) {
109 $params['is_template'] = 0;
111 // check if new event, if so set the created_id (if not set)
112 // and always set created_date to now
113 if (empty($params['id'])) {
114 if (empty($params['created_id'])) {
115 $session = CRM_Core_Session
::singleton();
116 $params['created_id'] = $session->get('userID');
118 $params['created_date'] = date('YmdHis');
120 // Clone from template
121 if (!empty($params['template_id'])) {
122 $copy = self
::copy($params['template_id']);
123 $params['id'] = $copy->id
;
124 unset($params['template_id']);
128 $event = self
::add($params);
129 CRM_Price_BAO_PriceSet
::setPriceSets($params, $event, 'event');
130 if (is_a($event, 'CRM_Core_Error')) {
131 CRM_Core_DAO
::transaction('ROLLBACK');
135 $contactId = CRM_Core_Session
::getLoggedInContactID();
137 $contactId = $params['contact_id'] ??
NULL;
140 // Log the information on successful add/edit of Event
142 'entity_table' => 'civicrm_event',
143 'entity_id' => $event->id
,
144 'modified_id' => $contactId,
145 'modified_date' => date('Ymd'),
148 CRM_Core_BAO_Log
::add($logParams);
150 if (!empty($params['custom']) &&
151 is_array($params['custom'])
153 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_event', $event->id
);
156 $transaction->commit();
157 if (!empty($params['id'])) {
158 // Note that this will specifically clear cached event tokens.
159 Civi
::cache('metadata')->clear();
172 public static function del($id) {
177 CRM_Utils_Hook
::pre('delete', 'Event', $id);
179 $extends = ['event'];
180 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
181 foreach ($groupTree as $values) {
182 $query = "DELETE FROM %1 WHERE entity_id = %2";
183 CRM_Core_DAO
::executeQuery($query, [
184 1 => [$values['table_name'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
],
185 2 => [$id, 'Integer'],
189 // Clean up references to profiles used by the event (CRM-20935)
191 'module' => 'CiviEvent',
192 'entity_table' => 'civicrm_event',
195 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
197 'module' => 'CiviEvent_Additional',
198 'entity_table' => 'civicrm_event',
201 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
203 // price set cleanup, CRM-5527
204 CRM_Price_BAO_PriceSet
::removeFrom('civicrm_event', $id);
206 $event = new CRM_Event_DAO_Event();
209 if ($event->find(TRUE)) {
210 $locBlockId = $event->loc_block_id
;
211 $result = $event->delete();
213 if (!is_null($locBlockId)) {
214 self
::deleteEventLocBlock($locBlockId, $id);
217 CRM_Utils_Hook
::post('delete', 'Event', $id, $event);
225 * Delete the location block associated with an event.
227 * Function checks that it is not being used by any other event.
229 * @param int $locBlockId
230 * Location block id to be deleted.
231 * @param int $eventId
232 * Event with which loc block is associated.
234 public static function deleteEventLocBlock($locBlockId, $eventId = NULL) {
235 $query = "SELECT count(ce.id) FROM civicrm_event ce WHERE ce.loc_block_id = $locBlockId";
238 $query .= " AND ce.id != $eventId;";
241 $locCount = CRM_Core_DAO
::singleValueQuery($query);
243 if ($locCount == 0) {
244 CRM_Core_BAO_Location
::deleteLocBlock($locBlockId);
249 * Get current/future Events.
252 * 0 returns current and future events.
253 * 1 if events all are required
254 * 2 returns events since 3 months ago
255 * @param int|array $id single int event id or array of multiple event ids to return
256 * @param bool $isActive
257 * true if you need only active events.
258 * @param bool $checkPermission
259 * true if you need to check permission else false.
260 * @param bool $titleOnly
261 * true if you need only title not appended with start date
265 public static function getEvents(
269 $checkPermission = TRUE,
273 SELECT `id`, `title`, `start_date`
275 WHERE ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
278 $op = is_array($id) ?
'IN' : '=';
279 $where = CRM_Contact_BAO_Query
::buildClause('id', $op, $id);
280 $query .= " AND {$where}";
283 // find only events ending in the future
284 $endDate = date('YmdHis');
286 AND ( `end_date` >= {$endDate} OR
288 ( end_date IS NULL OR end_date = '' ) AND start_date >= {$endDate}
293 // find only events starting in the last 3 months
294 $startDate = date('YmdHis', strtotime('3 months ago'));
295 $query .= " AND ( `start_date` >= {$startDate} OR start_date IS NULL )";
298 $query .= " AND civicrm_event.is_active = 1";
301 $query .= " ORDER BY title asc";
304 $dao = CRM_Core_DAO
::executeQuery($query);
305 while ($dao->fetch()) {
306 if ((!$checkPermission ||
307 CRM_Event_BAO_Event
::checkPermission($dao->id
)
311 $events[$dao->id
] = $dao->title
;
313 $events[$dao->id
] .= ' - ' . CRM_Utils_Date
::customFormat($dao->start_date
);
322 * Get events Summary.
325 * Array of event summary values
327 * @throws \CiviCRM_API3_Exception
329 public static function getEventSummary() {
330 $eventSummary = $eventIds = [];
331 $config = CRM_Core_Config
::singleton();
333 // get permission and include them here
334 // does not scale, but rearranging code for now
335 // FIXME in a future release
336 $permissions = self
::getAllPermissions();
338 if (empty($permissions[CRM_Core_Permission
::VIEW
])) {
339 $eventSummary['total_events'] = 0;
340 return $eventSummary;
343 $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission
::VIEW
])) . " ) ";
346 // We're fetching recent and upcoming events (where start date is 7 days ago OR later)
348 SELECT count(id) as total_events
350 WHERE civicrm_event.is_active = 1 AND
351 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
352 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
355 $dao = CRM_Core_DAO
::executeQuery($query);
358 $eventSummary['total_events'] = $dao->total_events
;
361 if (empty($eventSummary) ||
362 $dao->total_events
== 0
364 return $eventSummary;
367 //get the participant status type values.
368 $cpstObject = new CRM_Event_DAO_ParticipantStatusType();
369 $cpst = $cpstObject->getTableName();
370 $query = "SELECT id, name, label, class FROM $cpst";
371 $status = CRM_Core_DAO
::executeQuery($query);
373 while ($status->fetch()) {
374 $statusValues[$status->id
]['id'] = $status->id
;
375 $statusValues[$status->id
]['name'] = $status->name
;
376 $statusValues[$status->id
]['label'] = $status->label
;
377 $statusValues[$status->id
]['class'] = $status->class;
380 // Get the Id of Option Group for Event Types
381 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
382 $optionGroupDAO->name
= 'event_type';
383 $optionGroupId = NULL;
384 if ($optionGroupDAO->find(TRUE)) {
385 $optionGroupId = $optionGroupDAO->id
;
387 // Get the event summary display preferences
388 $show_max_events = Civi
::settings()->get('show_events');
389 // show all events if show_events is set to a negative value
390 if (isset($show_max_events) && $show_max_events >= 0) {
391 $event_summary_limit = "LIMIT 0, $show_max_events";
394 $event_summary_limit = "";
398 SELECT civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public,
399 civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date,
400 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,
401 civicrm_event.slot_label_id,
402 civicrm_event.summary as summary,
403 civicrm_pcp_block.id as is_pcp_enabled,
404 civicrm_recurring_entity.parent_id as is_repeating_event
406 LEFT JOIN civicrm_option_value ON (
407 civicrm_event.event_type_id = civicrm_option_value.value AND
408 civicrm_option_value.option_group_id = %1 )
409 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id AND civicrm_tell_friend.entity_table = 'civicrm_event' )
410 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event')
411 LEFT JOIN civicrm_recurring_entity ON ( civicrm_event.id = civicrm_recurring_entity.entity_id AND civicrm_recurring_entity.entity_table = 'civicrm_event' )
412 WHERE civicrm_event.is_active = 1 AND
413 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
414 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
416 ORDER BY civicrm_event.start_date ASC
419 $eventParticipant = [];
423 'eventTitle' => 'event_title',
424 'isPublic' => 'is_public',
425 'maxParticipants' => 'max_participants',
426 'startDate' => 'start_date',
427 'endDate' => 'end_date',
428 'eventType' => 'event_type',
430 'participants' => 'participants',
431 'notCountedDueToRole' => 'notCountedDueToRole',
432 'notCountedDueToStatus' => 'notCountedDueToStatus',
433 'notCountedParticipants' => 'notCountedParticipants',
436 $params = [1 => [$optionGroupId, 'Integer']];
437 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
438 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
440 $dao = CRM_Core_DAO
::executeQuery($query, $params);
441 while ($dao->fetch()) {
442 foreach ($properties as $property => $name) {
452 $eventSummary['events'][$dao->id
][$property] = $set;
456 if ($dao->$name && $config->mapAPIKey
) {
459 $params = ['entity_id' => $dao->id
, 'entity_table' => 'civicrm_event'];
460 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
461 if (is_numeric(CRM_Utils_Array
::value('geo_code_1', $values['location']['address'][1])) ||
463 !empty($values['location']['address'][1]['city']) &&
464 !empty($values['location']['address'][1]['state_province_id'])
467 $set = CRM_Utils_System
::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}");
471 $eventSummary['events'][$dao->id
][$property] = $set;
472 if (is_array($permissions[CRM_Core_Permission
::EDIT
])
473 && in_array($dao->id
, $permissions[CRM_Core_Permission
::EDIT
])) {
474 $eventSummary['events'][$dao->id
]['configure'] = CRM_Utils_System
::url('civicrm/admin/event', "action=update&id=$dao->id&reset=1");
480 $eventSummary['events'][$dao->id
][$property] = CRM_Utils_Date
::customFormat($dao->$name,
486 case 'notCountedDueToRole':
487 case 'notCountedDueToStatus':
488 case 'notCountedParticipants':
491 if ($name == 'participants') {
492 $propertyCnt = self
::getParticipantCount($dao->id
);
494 $set = CRM_Utils_System
::url('civicrm/event/search',
495 "reset=1&force=1&event=$dao->id&status=true&role=true"
499 elseif ($name == 'notCountedParticipants') {
500 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, TRUE, FALSE);
502 // FIXME : selector fail to search w/ OR operator.
503 // $set = CRM_Utils_System::url( 'civicrm/event/search',
504 // "reset=1&force=1&event=$dao->id&status=false&role=false" );
507 elseif ($name == 'notCountedDueToStatus') {
508 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, FALSE, FALSE);
510 $set = CRM_Utils_System
::url('civicrm/event/search',
511 "reset=1&force=1&event=$dao->id&status=false"
516 $propertyCnt = self
::getParticipantCount($dao->id
, FALSE, FALSE, TRUE, FALSE);
518 $set = CRM_Utils_System
::url('civicrm/event/search',
519 "reset=1&force=1&event=$dao->id&role=false"
524 $eventSummary['events'][$dao->id
][$property] = $propertyCnt;
525 $eventSummary['events'][$dao->id
][$name . '_url'] = $set;
529 $eventSummary['events'][$dao->id
][$property] = $dao->$name;
534 // prepare the area for per-status participant counts
535 $statusClasses = ['Positive', 'Pending', 'Waiting', 'Negative'];
536 $eventSummary['events'][$dao->id
]['statuses'] = array_fill_keys($statusClasses, []);
538 $eventSummary['events'][$dao->id
]['friend'] = $dao->is_friend_active
;
539 $eventSummary['events'][$dao->id
]['is_monetary'] = $dao->is_monetary
;
540 $eventSummary['events'][$dao->id
]['is_online_registration'] = $dao->is_online_registration
;
541 $eventSummary['events'][$dao->id
]['is_show_location'] = $dao->is_show_location
;
542 $eventSummary['events'][$dao->id
]['is_subevent'] = $dao->slot_label_id
;
543 $eventSummary['events'][$dao->id
]['is_pcp_enabled'] = $dao->is_pcp_enabled
;
544 $eventSummary['events'][$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mapping->getId());
545 $eventSummary['events'][$dao->id
]['is_repeating_event'] = $dao->is_repeating_event
;
547 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
548 foreach ($statusValues as $statusId => $statusValue) {
549 if (!array_key_exists($statusId, $statusTypes)) {
552 $class = $statusValue['class'];
553 $statusCount = self
::eventTotalSeats($dao->id
, "( participant.status_id = {$statusId} )");
555 $urlString = "reset=1&force=1&event={$dao->id}&status=$statusId";
557 'url' => CRM_Utils_System
::url('civicrm/event/search', $urlString),
558 'name' => $statusValue['name'],
559 'label' => $statusValue['label'],
560 'count' => $statusCount,
562 $eventSummary['events'][$dao->id
]['statuses'][$class][] = $statusInfo;
567 $countedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
568 $nonCountedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, '( filter = 0 OR filter IS NULL )');
569 $countedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
570 $nonCountedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )');
572 $countedStatusANDRoles = array_merge($countedStatus, $countedRoles);
573 $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles);
575 $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles));
576 $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus));
577 $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles));
578 $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles));
580 return $eventSummary;
584 * Get participant count.
586 * @param int $eventId
587 * @param bool $considerStatus consider status for participant count.
588 * Consider status for participant count.
589 * @param bool $status counted participant.
590 * Consider counted participant.
591 * @param bool $considerRole consider role for participant count.
592 * Consider role for participant count.
593 * @param bool $role consider counted( is filter role) participant.
594 * Consider counted( is filter role) participant.
597 * array with count of participants for each event based on status/role
599 public static function getParticipantCount(
601 $considerStatus = TRUE,
603 $considerRole = TRUE,
607 // consider both role and status for counted participants, CRM-4924.
609 // not counted participant.
610 if ($considerStatus && $considerRole && !$status && !$role) {
614 if ($considerStatus) {
615 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
616 $statusClause = 'NOT IN';
618 $statusClause = 'IN';
620 $status = implode(',', array_keys($statusTypes));
621 if (empty($status)) {
624 $clause[] = "participant.status_id {$statusClause} ( {$status} ) ";
628 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
629 $roleClause = 'NOT IN';
634 if (!empty($roleTypes)) {
636 foreach (array_keys($roleTypes) as $roleType) {
637 $escapedRoles[] = CRM_Utils_Type
::escape($roleType, 'String');
640 $clause[] = "participant.role_id {$roleClause} ( '" . implode("', '", $escapedRoles) . "' ) ";
645 if (!empty($clause)) {
646 $sqlClause = ' ( ' . implode($operator, $clause) . ' )';
649 return self
::eventTotalSeats($eventId, $sqlClause);
653 * Get the information to map a event.
656 * For which we want map info.
658 * @return null|string
661 public static function &getMapInfo(&$id) {
665 civicrm_event.id AS event_id,
666 civicrm_event.title AS display_name,
667 civicrm_address.street_address AS street_address,
668 civicrm_address.city AS city,
669 civicrm_address.postal_code AS postal_code,
670 civicrm_address.postal_code_suffix AS postal_code_suffix,
671 civicrm_address.geo_code_1 AS latitude,
672 civicrm_address.geo_code_2 AS longitude,
673 civicrm_state_province.abbreviation AS state,
674 civicrm_country.name AS country,
675 civicrm_location_type.name AS location_type
678 LEFT JOIN civicrm_loc_block ON ( civicrm_event.loc_block_id = civicrm_loc_block.id )
679 LEFT JOIN civicrm_address ON ( civicrm_loc_block.address_id = civicrm_address.id )
680 LEFT JOIN civicrm_state_province ON ( civicrm_address.state_province_id = civicrm_state_province.id )
681 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
682 LEFT JOIN civicrm_location_type ON ( civicrm_location_type.id = civicrm_address.location_type_id )
683 WHERE civicrm_address.geo_code_1 IS NOT NULL
684 AND civicrm_address.geo_code_2 IS NOT NULL
685 AND civicrm_event.id = " . CRM_Utils_Type
::escape($id, 'Integer');
687 $dao = new CRM_Core_DAO();
692 $config = CRM_Core_Config
::singleton();
694 while ($dao->fetch()) {
697 $location['displayName'] = addslashes($dao->display_name
);
698 $location['lat'] = $dao->latitude
;
699 $location['marker_class'] = 'Event';
700 $location['lng'] = $dao->longitude
;
702 $params = ['entity_id' => $id, 'entity_table' => 'civicrm_event'];
703 $addressValues = CRM_Core_BAO_Location
::getValues($params, TRUE);
704 $location['address'] = str_replace([
707 ], '', addslashes(nl2br($addressValues['address'][1]['display_text'])));
709 $location['url'] = CRM_Utils_System
::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id
);
710 $location['location_type'] = $dao->location_type
;
711 $eventImage = '<img src="' . $config->resourceBase
. 'i/contact_org.gif" alt="Organization " height="20" width="15" />';
712 $location['image'] = $eventImage;
713 $location['displayAddress'] = str_replace('<br />', ', ', $location['address']);
714 $locations[] = $location;
720 * Get the complete information for one or more events.
723 * Get events with start date >= this date.
724 * @param int $type Get events on the a specific event type (by event_type_id).
725 * Get events on the a specific event type (by event_type_id).
726 * @param int $eventId Return a single event - by event id.
727 * Return a single event - by event id.
729 * Also get events with end date >= this date.
730 * @param bool $onlyPublic Include public events only, default TRUE.
731 * Include public events only, default TRUE.
734 * array of all the events that are searched
736 public static function getCompleteInfo(
743 $publicCondition = NULL;
745 $publicCondition = " AND civicrm_event.is_public = 1";
749 // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133
751 // get events with start_date >= requested start
752 $startDate = CRM_Utils_Type
::escape($start, 'Date');
753 $dateCondition .= " AND ( civicrm_event.start_date >= {$startDate} )";
757 // also get events with end_date <= requested end
758 $endDate = CRM_Utils_Type
::escape($end, 'Date');
759 $dateCondition .= " AND ( civicrm_event.end_date <= '{$endDate}' ) ";
762 // CRM-9421 and CRM-8620 Default mode for ical/rss feeds. No start or end filter passed.
763 // Need to exclude old events with only start date
764 // and not exclude events in progress (start <= today and end >= today). DGG
765 if (empty($start) && empty($end)) {
766 // get events with end date >= today, not sure of this logic
767 // but keeping this for backward compatibility as per issue CRM-5133
768 $today = date("Y-m-d G:i:s");
769 $dateCondition .= " AND ( civicrm_event.end_date >= '{$today}' OR civicrm_event.start_date >= '{$today}' ) ";
773 $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type
::escape($type, 'Integer');
776 // Get the Id of Option Group for Event Types
777 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
778 $optionGroupDAO->name
= 'event_type';
779 $optionGroupId = NULL;
780 if ($optionGroupDAO->find(TRUE)) {
781 $optionGroupId = $optionGroupDAO->id
;
786 civicrm_event.id as event_id,
787 civicrm_email.email as email,
788 civicrm_event.title as title,
789 civicrm_event.summary as summary,
790 civicrm_event.start_date as start,
791 civicrm_event.end_date as end,
792 civicrm_event.description as description,
793 civicrm_event.is_show_location as is_show_location,
794 civicrm_event.is_online_registration as is_online_registration,
795 civicrm_event.registration_link_text as registration_link_text,
796 civicrm_event.registration_start_date as registration_start_date,
797 civicrm_event.registration_end_date as registration_end_date,
798 civicrm_option_value.label as event_type,
799 civicrm_address.name as address_name,
800 civicrm_address.street_address as street_address,
801 civicrm_address.supplemental_address_1 as supplemental_address_1,
802 civicrm_address.supplemental_address_2 as supplemental_address_2,
803 civicrm_address.supplemental_address_3 as supplemental_address_3,
804 civicrm_address.city as city,
805 civicrm_address.postal_code as postal_code,
806 civicrm_address.postal_code_suffix as postal_code_suffix,
807 civicrm_state_province.abbreviation as state,
808 civicrm_country.name AS country
810 LEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id
811 LEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id
812 LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
813 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
814 LEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id
815 LEFT JOIN civicrm_option_value ON (
816 civicrm_event.event_type_id = civicrm_option_value.value AND
817 civicrm_option_value.option_group_id = %1 )
818 WHERE civicrm_event.is_active = 1
819 AND (is_template = 0 OR is_template IS NULL)
823 if (isset($typeCondition)) {
824 $query .= $typeCondition;
827 if (isset($eventId)) {
828 $query .= " AND civicrm_event.id =$eventId ";
830 $query .= " ORDER BY civicrm_event.start_date ASC";
832 $params = [1 => [$optionGroupId, 'Integer']];
833 $dao = CRM_Core_DAO
::executeQuery($query, $params);
835 $config = CRM_Core_Config
::singleton();
837 $baseURL = parse_url($config->userFrameworkBaseURL
);
838 $url = "@" . $baseURL['host'];
839 if (!empty($baseURL['path'])) {
840 $url .= substr($baseURL['path'], 0, -1);
843 // check 'view event info' permission
844 //@todo - per CRM-14626 we have resolved that 'view event info' means 'view ALL event info'
845 if (CRM_Core_Permission
::check('view event info')) {
849 $permissions = CRM_Core_Permission
::event(CRM_Core_Permission
::VIEW
);
852 while ($dao->fetch()) {
853 if (!empty($permissions) && ($permissions === TRUE ||
in_array($dao->event_id
, $permissions))) {
855 $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL
) . $url;
857 $info['title'] = $dao->title
;
858 $info['event_id'] = $dao->event_id
;
859 $info['summary'] = $dao->summary
;
860 $info['description'] = $dao->description
;
861 $info['start_date'] = $dao->start
;
862 $info['end_date'] = $dao->end
;
863 $info['contact_email'] = $dao->email
;
864 $info['event_type'] = $dao->event_type
;
865 $info['is_show_location'] = $dao->is_show_location
;
866 $info['is_online_registration'] = $dao->is_online_registration
;
867 $info['registration_link_text'] = $dao->registration_link_text
;
868 $info['registration_start_date'] = $dao->registration_start_date
;
869 $info['registration_end_date'] = $dao->registration_end_date
;
874 'address_name' => $dao->address_name
,
875 'street_address' => $dao->street_address
,
876 'supplemental_address_1' => $dao->supplemental_address_1
,
877 'supplemental_address_2' => $dao->supplemental_address_2
,
878 'supplemental_address_3' => $dao->supplemental_address_3
,
879 'city' => $dao->city
,
880 'state_province' => $dao->state
,
881 'postal_code' => $dao->postal_code
,
882 'postal_code_suffix' => $dao->postal_code_suffix
,
883 'country' => $dao->country
,
887 CRM_Utils_String
::append($address, ', ',
888 CRM_Utils_Address
::format($addrFields)
890 $info['location'] = $address;
891 $info['url'] = CRM_Utils_System
::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id
, TRUE, NULL, FALSE);
893 // @todo Move to eventcart extension
894 // check if we're in shopping cart mode for events
895 if ((bool) Civi
::settings()->get('enable_cart')) {
896 $reg = CRM_Event_Cart_BAO_EventInCart
::get_registration_link($dao->event_id
);
897 $info['registration_link'] = CRM_Utils_System
::url($reg['path'], $reg['query'], TRUE);
898 $info['registration_link_text'] = $reg['label'];
909 * Make a copy of a Event.
911 * Include all the fields in the event Wizard.
914 * The event id to copy.
915 * @param array $params
917 * @return CRM_Event_DAO_Event
918 * @throws \CRM_Core_Exception
920 public static function copy($id, $params = []) {
921 $session = CRM_Core_Session
::singleton();
924 //get the required event values.
925 $eventParams = ['id' => $id];
926 $returnProperties = [
930 'default_discount_fee_id',
934 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
938 'title' => ts('Copy of') . ' ',
941 'created_id' => $session->get('userID'),
942 'created_date' => date('YmdHis'),
945 if (empty($eventValues['is_show_location'])) {
946 $fieldsFix['prefix']['is_show_location'] = 0;
949 $blockCopyOfCustomValue = (!empty($params['custom']));
951 /** @var \CRM_Event_DAO_Event $copyEvent */
952 $copyEvent = CRM_Core_DAO
::copyGeneric('CRM_Event_DAO_Event',
954 // since the location is sharable, lets use the same loc_block_id.
955 ['loc_block_id' => CRM_Utils_Array
::value('loc_block_id', $eventValues)] +
$params,
958 $blockCopyOfCustomValue
960 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_event', $id, $copyEvent->id
);
961 CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin',
964 'entity_table' => 'civicrm_event',
966 ['entity_id' => $copyEvent->id
]
969 CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend',
972 'entity_table' => 'civicrm_event',
974 ['entity_id' => $copyEvent->id
]
977 CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock',
980 'entity_table' => 'civicrm_event',
982 ['entity_id' => $copyEvent->id
],
983 ['replace' => ['target_entity_id' => $copyEvent->id
]]
986 $oldMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
987 'id' => ($eventValues['is_template'] ? CRM_Event_ActionMapping
::EVENT_TPL_MAPPING_ID
: CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
),
989 $copyMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
990 'id' => ($copyEvent->is_template
== 1 ? CRM_Event_ActionMapping
::EVENT_TPL_MAPPING_ID
: CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
),
992 CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_ActionSchedule',
993 ['entity_value' => $id, 'mapping_id' => $oldMapping->getId()],
994 ['entity_value' => $copyEvent->id
, 'mapping_id' => $copyMapping->getId()]
999 if ($blockCopyOfCustomValue) {
1000 foreach ($params['custom'] as &$values) {
1001 foreach ($values as &$value) {
1002 // Ensure we don't copy over the template's id if it is passed in
1003 // This is a bit hacky but it's unclear what the
1004 // right behaviour is given the whole 'custom'
1005 // field is form layer formatting that is reaching the BAO.
1006 $value['id'] = NULL;
1009 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_event', $copyEvent->id
);
1012 CRM_Utils_System
::flushCache();
1013 CRM_Utils_Hook
::copy('Event', $copyEvent);
1019 * This is sometimes called in a loop (during event search).
1021 * We cache the values to prevent repeated calls to the db.
1027 public static function isMonetary($id) {
1028 static $isMonetary = [];
1029 if (!array_key_exists($id, $isMonetary)) {
1030 $isMonetary[$id] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1035 return $isMonetary[$id];
1039 * This is sometimes called in a loop (during event search).
1041 * We cache the values to prevent repeated calls to the db.
1047 public static function usesPriceSet($id) {
1048 static $usesPriceSet = [];
1049 if (!array_key_exists($id, $usesPriceSet)) {
1050 $usesPriceSet[$id] = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $id);
1052 return $usesPriceSet[$id];
1058 * @param int $contactID
1059 * @param array $values
1060 * @param int $participantId
1061 * @param bool $isTest
1062 * @param bool $returnMessageText
1064 * @return array|null
1065 * @throws \CiviCRM_API3_Exception
1067 public static function sendMail($contactID, $values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) {
1069 $template = CRM_Core_Smarty
::singleton();
1071 'custom_pre_id' => $values['custom_pre_id'],
1072 'custom_post_id' => $values['custom_post_id'],
1075 //get the params submitted by participant.
1076 $participantParams = CRM_Utils_Array
::value($participantId, $values['params'], []);
1078 if (!$returnMessageText) {
1079 //send notification email if field values are set (CRM-1941)
1080 foreach ($gIds as $key => $gIdValues) {
1082 if (!is_array($gIdValues)) {
1083 $gIdValues = [$gIdValues];
1086 foreach ($gIdValues as $gId) {
1087 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
1089 //get values of corresponding profile fields for notification
1090 [$profileValues] = self
::buildCustomDisplay($gId,
1099 [$profileValues] = $profileValues;
1102 'values' => $profileValues,
1105 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
1112 if ($values['event']['is_email_confirm'] ||
$returnMessageText) {
1113 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
1114 $notifyEmail = CRM_Utils_Array
::valueByRegexKey('/^email-/', $participantParams) ??
$email;
1115 //send email only when email is present
1116 if (isset($notifyEmail) ||
$returnMessageText) {
1117 $preProfileID = $values['custom_pre_id'] ??
NULL;
1118 $postProfileID = $values['custom_post_id'] ??
NULL;
1120 if (!empty($values['params']['additionalParticipant'])) {
1121 $preProfileID = CRM_Utils_Array
::value('additional_custom_pre_id', $values, $preProfileID);
1122 $postProfileID = CRM_Utils_Array
::value('additional_custom_post_id', $values, $postProfileID);
1125 $profilePre = self
::buildCustomDisplay($preProfileID,
1135 $profilePost = self
::buildCustomDisplay($postProfileID,
1145 $sessions = CRM_Event_Cart_BAO_Conference
::get_participant_sessions($participantId);
1147 // @todo - the goal is that all params available to the message template are explicitly defined here rather than
1148 // 'in a smattering of places'. Note that leakage can happen between mailings when not explicitly defined.
1149 if ($postProfileID) {
1150 $customPostTitles = empty($profilePost[1]) ?
NULL : [];
1151 foreach ($postProfileID as $offset => $id) {
1152 $customPostTitles[$offset] = CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $id);
1156 $customPostTitles = NULL;
1158 $tplParams = array_merge($values, $participantParams, [
1159 'email' => $notifyEmail,
1160 'confirm_email_text' => $values['event']['confirm_email_text'] ??
NULL,
1161 'isShowLocation' => $values['event']['is_show_location'] ??
NULL,
1162 // The concept of contributeMode is deprecated.
1163 'contributeMode' => $template->_tpl_vars
['contributeMode'] ??
NULL,
1164 'customPre' => $profilePre[0],
1165 'customPre_grouptitle' => empty($profilePre[1]) ?
NULL : [CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $preProfileID)],
1166 'customPost' => $profilePost[0],
1167 'customPost_grouptitle' => $customPostTitles,
1168 'participantID' => $participantId,
1169 'contactID' => $contactID,
1170 'conference_sessions' => $sessions,
1171 'credit_card_number' => CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $participantParams)),
1172 'credit_card_exp_date' => CRM_Utils_Date
::mysqlToIso(CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $participantParams))),
1173 'selfcancelxfer_time' => abs($values['event']['selfcancelxfer_time']),
1174 'selfservice_preposition' => $values['event']['selfcancelxfer_time'] < 0 ?
ts('after') : ts('before'),
1175 'currency' => $values['event']['currency'] ?? CRM_Core_Config
::singleton()->defaultCurrency
,
1178 // CRM-13890 : NOTE wait list condition need to be given so that
1179 // wait list message is shown properly in email i.e. WRT online event registration template
1180 if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) {
1181 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id', TRUE);
1182 $tplParams['participant_status'] = CRM_Event_PseudoConstant
::participantStatus($statusId, NULL, 'label');
1184 //CRM-15754 - if participant_status contains status ID
1185 elseif (!empty($tplParams['participant_status']) && CRM_Utils_Rule
::integer($tplParams['participant_status'])) {
1186 $tplParams['participant_status'] = CRM_Event_PseudoConstant
::participantStatus($tplParams['participant_status'], NULL, 'label');
1189 $sendTemplateParams = [
1190 'groupName' => 'msg_tpl_workflow_event',
1191 'valueName' => 'event_online_receipt',
1192 'contactId' => $contactID,
1193 'isTest' => $isTest,
1194 'tplParams' => $tplParams,
1195 'PDFFilename' => ts('confirmation') . '.pdf',
1198 // address required during receipt processing (pdf and email receipt)
1199 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
1200 $sendTemplateParams['tplParams']['address'] = $displayAddress;
1201 // The concept of contributeMode is deprecated.
1202 $sendTemplateParams['tplParams']['contributeMode'] = NULL;
1205 // set lineItem details
1206 if ($lineItem = CRM_Utils_Array
::value('lineItem', $values)) {
1207 // check if additional participant, if so filter only to relevant ones
1209 if (!empty($values['params']['additionalParticipant'])) {
1211 foreach ($lineItem as $liKey => $liValue) {
1212 $firstElement = array_pop($liValue);
1213 if ($firstElement['entity_id'] == $participantId) {
1214 $ownLineItems[0] = $lineItem[$liKey];
1218 if (!empty($ownLineItems)) {
1219 $sendTemplateParams['tplParams']['lineItem'] = $ownLineItems;
1223 $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
1227 if ($returnMessageText) {
1228 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1230 'subject' => $subject,
1232 'to' => $displayName,
1237 $sendTemplateParams['from'] = CRM_Utils_Array
::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array
::value('confirm_from_email', $values['event']) . ">";
1238 $sendTemplateParams['toName'] = $displayName;
1239 $sendTemplateParams['toEmail'] = $notifyEmail;
1240 $sendTemplateParams['autoSubmitted'] = TRUE;
1241 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_confirm',
1244 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_confirm',
1248 if (Civi
::settings()->get('invoice_is_email_pdf') && !empty($values['contributionId'])) {
1249 $sendTemplateParams['isEmailPdf'] = TRUE;
1250 $sendTemplateParams['contributionId'] = $values['contributionId'];
1252 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1259 * Add the custom fields OR array of participant's profile info.
1262 * @param string $name
1264 * @param string $template
1265 * @param int $participantId
1266 * @param bool $isTest
1267 * @param bool $returnResults
1268 * @param array $participantParams
1270 * @return array|null
1271 * @throws \CRM_Core_Exception
1273 public static function buildCustomDisplay(
1280 $returnResults = FALSE,
1281 $participantParams = []
1284 return [NULL, NULL];
1287 if (!is_array($id)) {
1288 $id = CRM_Utils_Type
::escape($id, 'Positive');
1289 $profileIds = [$id];
1295 $val = $groupTitles = NULL;
1296 foreach ($profileIds as $gid) {
1297 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
1299 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
,
1300 NULL, NULL, FALSE, NULL,
1301 FALSE, NULL, CRM_Core_Permission
::CREATE
,
1305 //this condition is added, since same contact can have multiple event registrations..
1306 $params = [['participant_id', '=', $participantId, 0, 0]];
1308 //add participant id
1309 $fields['participant_id'] = [
1310 'name' => 'participant_id',
1311 'title' => ts('Participant ID'),
1313 //check whether its a text drive
1315 $params[] = ['participant_test', '=', 1, 0, 0];
1318 //display campaign on thankyou page.
1319 if (array_key_exists('participant_campaign_id', $fields)) {
1320 if ($participantId) {
1321 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
1325 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
1326 $values[$fields['participant_campaign_id']['title']] = CRM_Utils_Array
::value($campaignId,
1330 unset($fields['participant_campaign_id']);
1334 foreach ($fields as $k => $v) {
1336 $groupTitle = $v['groupDisplayTitle'];
1338 // suppress all file fields from display
1340 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
1341 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
1342 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
1349 $groupTitles[] = $groupTitle;
1351 //display profile groups those are subscribed by participant.
1352 if (($groups = CRM_Utils_Array
::value('group', $participantParams)) &&
1356 foreach ($groups as $grpId => $isSelected) {
1361 if (!empty($grpIds)) {
1362 //get the group titles.
1364 $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )';
1365 $grp = CRM_Core_DAO
::executeQuery($query);
1366 while ($grp->fetch()) {
1367 $grpTitles[] = $grp->title
;
1369 if (!empty($grpTitles) &&
1370 CRM_Utils_Array
::value('title', CRM_Utils_Array
::value('group', $fields))
1372 $values[$fields['group']['title']] = implode(', ', $grpTitles);
1374 unset($fields['group']);
1378 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
1381 //If the event profile includes a note field and the submitted value of
1382 //that field is "", then remove the old note returned by getValues.
1383 if (isset($participantParams['note']) && empty($participantParams['note'])) {
1384 $noteKeyPos = array_search('note', array_keys($fields));
1385 $valuesKeys = array_keys($values);
1386 $values[$valuesKeys[$noteKeyPos]] = "";
1389 if (isset($fields['participant_status_id']['title']) &&
1390 isset($values[$fields['participant_status_id']['title']]) &&
1391 is_numeric($values[$fields['participant_status_id']['title']])
1394 $status = CRM_Event_PseudoConstant
::participantStatus();
1395 $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]];
1398 if (isset($fields['participant_role_id']['title']) &&
1399 isset($values[$fields['participant_role_id']['title']]) &&
1400 is_numeric($values[$fields['participant_role_id']['title']])
1403 $roles = CRM_Event_PseudoConstant
::participantRole();
1404 $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]];
1407 if (isset($fields['participant_register_date']['title']) &&
1408 isset($values[$fields['participant_register_date']['title']])
1410 $values[$fields['participant_register_date']['title']] = CRM_Utils_Date
::customFormat($values[$fields['participant_register_date']['title']]);
1413 //handle fee_level for price set
1414 if (isset($fields['participant_fee_level']['title']) &&
1415 isset($values[$fields['participant_fee_level']['title']])
1417 $feeLevel = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1418 $values[$fields['participant_fee_level']['title']]
1420 foreach ($feeLevel as $key => $value) {
1422 unset($feeLevel[$key]);
1425 $values[$fields['participant_fee_level']['title']] = implode(',', $feeLevel);
1428 unset($values[$fields['participant_id']['title']]);
1435 $template->assign($name, $val);
1438 if (count($groupTitles)) {
1439 $template->assign($name . '_grouptitle', $groupTitles);
1442 //return if we only require array of participant's info.
1443 if ($returnResults) {
1445 return [$val, $groupTitles];
1454 * Build the array for display the profile fields.
1456 * @param array $params
1460 * @param array $groupTitle
1461 * Profile Group Title.
1462 * @param array $values
1463 * Formatted array of key value.
1465 * @param array $profileFields
1467 * @throws \CRM_Core_Exception
1468 * @throws \API_Exception
1469 * @throws \CiviCRM_API3_Exception
1471 public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) {
1473 $config = CRM_Core_Config
::singleton();
1474 $session = CRM_Core_Session
::singleton();
1475 $contactID = $session->get('userID');
1477 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $contactID)) {
1478 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
);
1482 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::ADD
);
1485 if (!empty($fields)) {
1486 $groupTitle['groupTitle'] = CRM_Core_BAO_UFGroup
::getFrontEndTitle((int) $gid);
1489 $imProviders = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_IM', 'provider_id');
1490 //start of code to set the default values
1491 foreach ($fields as $name => $field) {
1494 // skip fields that should not be displayed separately
1495 if ($field['skipDisplay']) {
1499 $index = $field['title'];
1500 if ($name === 'organization_name') {
1501 $values[$index] = $params[$name];
1504 if ('state_province' == substr($name, 0, 14)) {
1505 if ($params[$name]) {
1506 $values[$index] = CRM_Core_PseudoConstant
::stateProvince($params[$name]);
1509 $values[$index] = '';
1512 elseif ('date' == substr($name, -4)) {
1513 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::processDate($params[$name]),
1514 $config->dateformatFull
);
1516 elseif ('country' == substr($name, 0, 7)) {
1517 if ($params[$name]) {
1518 $values[$index] = CRM_Core_PseudoConstant
::country($params[$name]);
1521 $values[$index] = '';
1524 elseif ('county' == substr($name, 0, 6)) {
1525 if ($params[$name]) {
1526 $values[$index] = CRM_Core_PseudoConstant
::county($params[$name]);
1529 $values[$index] = '';
1532 elseif (in_array(substr($name, 0, -3), ['gender', 'prefix', 'suffix', 'communication_style'])) {
1533 $values[$index] = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
1535 elseif (in_array($name, [
1540 $filterCondition = ['greeting_type' => $name];
1541 $greeting = CRM_Core_PseudoConstant
::greeting($filterCondition);
1542 $values[$index] = $greeting[$params[$name]];
1544 elseif ($name === 'preferred_communication_method') {
1545 $communicationFields = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
1547 $pref = $params[$name];
1548 if (is_array($pref)) {
1549 foreach ($pref as $k => $v) {
1551 $compref[] = $communicationFields[$k];
1555 $values[$index] = implode(',', $compref);
1557 elseif ($name == 'contact_sub_type') {
1558 $values[$index] = implode(', ', $params[$name]);
1560 elseif ($name == 'group') {
1561 $groups = CRM_Contact_BAO_GroupContact
::getGroupList();
1563 foreach ($params[$name] as $gId => $dontCare) {
1565 $title[] = $groups[$gId];
1568 $values[$index] = implode(', ', $title);
1570 elseif ($name == 'tag') {
1571 $entityTags = $params[$name];
1572 $allTags = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]);
1574 if (is_array($entityTags)) {
1575 foreach ($entityTags as $tagId => $dontCare) {
1576 $title[] = $allTags[$tagId];
1579 $values[$index] = implode(', ', $title);
1581 elseif ('participant_role_id' == $name or
1582 'participant_role' == $name
1584 $roles = CRM_Event_PseudoConstant
::participantRole();
1585 $values[$index] = $roles[$params[$name]];
1587 elseif ('participant_status_id' == $name or
1588 'participant_status' == $name
1590 $status = CRM_Event_PseudoConstant
::participantStatus();
1591 $values[$index] = $status[$params[$name]];
1593 elseif (substr($name, -11) == 'campaign_id') {
1594 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($params[$name]);
1595 $values[$index] = $campaigns[$params[$name]] ??
NULL;
1597 elseif (strpos($name, '-') !== FALSE) {
1598 list($fieldName, $id) = CRM_Utils_System
::explode('-', $name, 2);
1599 $detailName = str_replace(' ', '_', $name);
1600 if (in_array($fieldName, [
1605 $values[$index] = $params[$detailName];
1606 $idx = $detailName . '_id';
1607 $values[$index] = $params[$idx];
1609 elseif ($fieldName == 'im') {
1610 $providerName = NULL;
1611 if ($providerId = $detailName . '-provider_id') {
1612 $providerName = $imProviders[$params[$providerId]] ??
NULL;
1614 if ($providerName) {
1615 $values[$index] = $params[$detailName] . " (" . $providerName . ")";
1618 $values[$index] = $params[$detailName];
1621 elseif ($fieldName == 'phone') {
1622 $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
1623 if (isset($params[$phoneExtField])) {
1624 $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
1627 $values[$index] = $params[$detailName];
1631 $values[$index] = $params[$detailName];
1635 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
1636 if ($params[$name]) {
1637 $values[$index] = '[ x ]';
1641 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
1643 SELECT html_type, data_type
1644 FROM civicrm_custom_field
1647 $dao = CRM_Core_DAO
::executeQuery($query);
1649 $htmlType = $dao->html_type
;
1651 if ($htmlType == 'File') {
1652 $path = $params[$name]['name'] ??
NULL;
1653 $fileType = $params[$name]['type'] ??
NULL;
1654 $values[$index] = CRM_Utils_File
::getFileURL($path, $fileType);
1657 if ($dao->data_type
== 'Int' ||
1658 $dao->data_type
== 'Boolean'
1660 $v = $params[$name];
1661 if (!CRM_Utils_System
::isNull($v)) {
1662 $customVal = (int) $v;
1665 elseif ($dao->data_type
== 'Float') {
1666 $customVal = (float ) ($params[$name]);
1668 elseif ($dao->data_type
== 'Date') {
1669 //@todo note the currently we are using default date time formatting. Since you can select/set
1670 // different date and time format specific to custom field we should consider fixing this
1671 // sometime in the future
1672 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1673 CRM_Utils_Date
::processDate($params[$name]), $config->dateformatFull
);
1675 if (!empty($params[$name . '_time'])) {
1676 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1677 CRM_Utils_Date
::processDate($params[$name], $params[$name . '_time']),
1678 $config->dateformatDatetime
);
1682 // for checkboxes, change array of [key => bool] to array of [idx => key]
1683 elseif ($dao->html_type
== 'CheckBox') {
1684 $customVal = array_keys(array_filter($params[$name]));
1687 $customVal = $params[$name];
1689 //take the custom field options
1690 $returnProperties = [$name => 1];
1691 $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
1693 $displayValue = CRM_Core_BAO_CustomField
::displayValue($customVal, $cfID);
1695 //Hack since we dont have function to check empty.
1696 //FIXME in 2.3 using crmIsEmptyArray()
1697 $customValue = TRUE;
1698 if (is_array($customVal) && is_array($displayValue)) {
1699 $customValue = array_diff($customVal, $displayValue);
1701 //use difference of arrays
1702 if (empty($customValue) ||
!$customValue) {
1703 $values[$index] = '';
1706 $values[$index] = $displayValue;
1710 elseif ($name == 'home_URL' &&
1711 !empty($params[$name])
1713 $url = CRM_Utils_System
::fixURL($params[$name]);
1714 $values[$index] = "<a href=\"$url\">{$params[$name]}</a>";
1716 elseif (in_array($name, [
1719 'participant_register_date',
1721 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::format($params[$name]));
1724 $values[$index] = $params[$name] ??
NULL;
1728 $profileFields[$name] = $field;
1734 * Build the array for Additional participant's information array of primary and additional Ids.
1736 * @param int $participantId
1737 * Id of Primary participant.
1738 * @param array $values
1739 * Key/value event info.
1740 * @param int $contactId
1741 * Contact id of Primary participant.
1742 * @param bool $isTest
1743 * Whether test or live transaction.
1744 * @param bool $isIdsArray
1745 * To return an array of Ids.
1747 * @param bool $skipCancel
1750 * array of Additional participant's info OR array of Ids.
1752 public static function buildCustomProfile(
1757 $isIdsArray = FALSE,
1761 $customProfile = $additionalIDs = [];
1762 if (!$participantId) {
1763 throw new CRM_Core_Exception(ts('Cannot find participant ID'));
1766 //set Ids of Primary Participant also.
1767 if ($isIdsArray && $contactId) {
1768 $additionalIDs[$participantId] = $contactId;
1771 //hack to skip cancelled participants, CRM-4320
1772 $where = "participant.registered_by_id={$participantId}";
1774 $cancelStatusId = 0;
1775 $negativeStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
1776 $cancelStatusId = array_search('Cancelled', $negativeStatuses);
1777 $where .= " AND participant.status_id != {$cancelStatusId}";
1780 SELECT participant.id, participant.contact_id
1781 FROM civicrm_participant participant
1784 $dao = CRM_Core_DAO
::executeQuery($query);
1785 while ($dao->fetch()) {
1786 $additionalIDs[$dao->id
] = $dao->contact_id
;
1789 //return if only array is required.
1790 if ($isIdsArray && $contactId) {
1791 return $additionalIDs;
1794 $preProfileID = $values['additional_custom_pre_id'] ??
NULL;
1795 $postProfileID = $values['additional_custom_post_id'] ??
NULL;
1796 //else build array of Additional participant's information.
1797 if (count($additionalIDs)) {
1798 if ($preProfileID ||
$postProfileID) {
1799 $template = CRM_Core_Smarty
::singleton();
1801 $isCustomProfile = TRUE;
1803 $title = $groupTitles = [];
1804 foreach ($additionalIDs as $pId => $cId) {
1805 //get the params submitted by participant.
1806 $participantParams = NULL;
1807 if (isset($values['params'])) {
1808 $participantParams = CRM_Utils_Array
::value($pId, $values['params'], []);
1811 list($profilePre, $groupTitles) = self
::buildCustomDisplay($preProfileID,
1812 'additionalCustomPre',
1822 $profile = $profilePre;
1823 // $customProfile[$i] = array_merge( $groupTitles, $customProfile[$i] );
1825 $title = $groupTitles;
1829 list($profilePost, $groupTitles) = self
::buildCustomDisplay($postProfileID,
1830 'additionalCustomPost',
1840 if (isset($profilePre)) {
1841 $profile = array_merge($profilePre, $profilePost);
1843 $title = array_merge($title, $groupTitles);
1847 $profile = $profilePost;
1849 $title = $groupTitles;
1853 $profiles[] = $profile;
1856 $customProfile['title'] = $title;
1857 $customProfile['profile'] = $profiles;
1861 return $customProfile;
1865 * Retrieve all event addresses.
1869 public static function getLocationEvents() {
1873 'loc_block_id.address_id.name',
1874 'loc_block_id.address_id.street_address',
1875 'loc_block_id.address_id.supplemental_address_1',
1876 'loc_block_id.address_id.supplemental_address_2',
1877 'loc_block_id.address_id.supplemental_address_3',
1878 'loc_block_id.address_id.city',
1879 'loc_block_id.address_id.state_province_id.name',
1882 $result = civicrm_api3('Event', 'get', [
1883 'check_permissions' => TRUE,
1885 'loc_block_id.address_id' => ['IS NOT NULL' => 1],
1891 foreach ($result['values'] as $event) {
1893 foreach ($ret as $field) {
1894 if ($field != 'loc_block_id' && !empty($event[$field])) {
1895 $address .= ($address ?
' :: ' : '') . $event[$field];
1899 $events[$event['loc_block_id']] = $address;
1903 return CRM_Utils_Array
::asort($events);
1907 * @param int $locBlockId
1909 * @return int|null|string
1911 public static function countEventsUsingLocBlockId($locBlockId) {
1916 $locBlockId = CRM_Utils_Type
::escape($locBlockId, 'Integer');
1919 SELECT count(*) FROM civicrm_event ce
1920 WHERE ce.loc_block_id = $locBlockId";
1922 return CRM_Core_DAO
::singleValueQuery($query);
1926 * Check if event registration is valid according to permissions AND Dates.
1928 * @param array $values
1929 * @param int $eventID
1932 public static function validRegistrationRequest($values, $eventID) {
1933 // check that the user has permission to register for this event
1934 $hasPermission = CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
,
1935 $eventID, 'register for events'
1938 return $hasPermission && self
::validRegistrationDate($values);
1946 public static function validRegistrationDate(&$values) {
1947 // make sure that we are between registration start date and end dates
1948 // and that if the event has ended, registration is still specifically open
1949 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $values));
1950 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $values));
1951 $eventEnd = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $values));
1954 if ($startDate && $startDate >= $now) {
1957 elseif ($endDate && $endDate < $now) {
1960 elseif ($eventEnd && $eventEnd < $now && !$endDate) {
1967 /* Function to Show - Hide the Registration Link.
1969 * @param array $values
1970 * Key/value event info.
1972 * true if allow registration otherwise false
1980 public static function showHideRegistrationLink($values) {
1982 $session = CRM_Core_Session
::singleton();
1983 $contactID = $session->get('userID');
1984 $alreadyRegistered = FALSE;
1987 $params = ['contact_id' => $contactID];
1989 if ($eventId = CRM_Utils_Array
::value('id', $values['event'])) {
1990 $params['event_id'] = $eventId;
1992 if ($roleId = CRM_Utils_Array
::value('default_role_id', $values['event'])) {
1993 $params['role_id'] = $roleId;
1995 $alreadyRegistered = self
::checkRegistration($params);
1998 if (!empty($values['event']['allow_same_participant_emails']) ||
2006 /* Function to check if given contact is already registered.
2008 * @param array $params
2009 * Key/value participant info.
2014 * @param array $params
2018 public static function checkRegistration($params) {
2019 $alreadyRegistered = FALSE;
2020 if (empty($params['contact_id'])) {
2021 return $alreadyRegistered;
2024 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
2026 $participant = new CRM_Event_DAO_Participant();
2027 $participant->copyValues($params);
2029 $participant->is_test
= CRM_Utils_Array
::value('is_test', $params, 0);
2030 $participant->selectAdd();
2031 $participant->selectAdd('status_id');
2032 if ($participant->find(TRUE) && array_key_exists($participant->status_id
, $statusTypes)) {
2033 $alreadyRegistered = TRUE;
2036 return $alreadyRegistered;
2040 * Make sure that the user has permission to access this event.
2041 * FIXME: We have separate caches for checkPermission('permission') and getAllPermissions['permissions'] so they don't interfere.
2042 * But it would be nice to clean this up some more.
2044 * @param int $eventId
2045 * @param int $permissionType
2047 * @return bool|array
2048 * Whether the user has permission for this event (or if eventId=NULL an array of permissions)
2049 * @throws \CiviCRM_API3_Exception
2051 public static function checkPermission(int $eventId, $permissionType = CRM_Core_Permission
::VIEW
) {
2052 switch ($permissionType) {
2053 case CRM_Core_Permission
::EDIT
:
2054 // We also set the cached "view" permission to TRUE if "edit" is TRUE
2055 if (isset(Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId])) {
2056 return Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId];
2058 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = FALSE;
2060 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo($eventId);
2061 // Note: for a multisite setup, a user with edit all events, can edit all events
2062 // including those from other sites
2063 if (($permissionType == CRM_Core_Permission
::EDIT
) && CRM_Core_Permission
::check('edit all events')) {
2064 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = TRUE;
2065 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2067 elseif (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_event', $allEvents, $createdEvents))) {
2068 Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId] = TRUE;
2069 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2071 return Civi
::$statics[__CLASS__
]['permission']['edit'][$eventId];
2073 case CRM_Core_Permission
::VIEW
:
2074 if (isset(Civi
::$statics[__CLASS__
]['permission']['view'][$eventId])) {
2075 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId];
2077 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = FALSE;
2079 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo($eventId);
2080 if (CRM_Core_Permission
::check('access CiviEvent')) {
2081 if (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, array_keys($createdEvents)))) {
2082 // User created this event so has permission to view it
2083 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2085 if (CRM_Core_Permission
::check('view event participants')) {
2086 // User has permission to view all events
2087 // use case: allow "view all events" but NOT "edit all events"
2088 // so for a normal site allow users with these two permissions to view all events AND
2089 // at the same time also allow any hook to override if needed.
2090 if (in_array($eventId, CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, array_keys($allEvents)))) {
2091 Civi
::$statics[__CLASS__
]['permission']['view'][$eventId] = TRUE;
2095 return Civi
::$statics[__CLASS__
]['permission']['view'][$eventId];
2097 case CRM_Core_Permission
::DELETE
:
2098 if (isset(Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId])) {
2099 return Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId];
2101 Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId] = FALSE;
2102 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
2103 Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId] = TRUE;
2105 return Civi
::$statics[__CLASS__
]['permission']['delete'][$eventId];
2113 * This is a helper for refactoring checkPermission
2114 * FIXME: We should be able to get rid of these arrays, but that would require understanding how CRM_ACL_API::group actually works!
2116 * @param int $eventId
2118 * @return array $allEvents, $createdEvents
2119 * @throws \CiviCRM_API3_Exception
2121 private static function checkPermissionGetInfo($eventId = NULL) {
2123 'check_permissions' => 1,
2124 'return' => 'id, created_id',
2125 'options' => ['limit' => 0],
2128 $params['id'] = $eventId;
2132 $createdEvents = [];
2133 $eventResult = civicrm_api3('Event', 'get', $params);
2134 if ($eventResult['count'] > 0) {
2135 $contactId = CRM_Core_Session
::getLoggedInContactID();
2136 foreach ($eventResult['values'] as $eventId => $eventDetail) {
2137 $allEvents[$eventId] = $eventId;
2138 if (isset($eventDetail['created_id']) && $contactId == $eventDetail['created_id']) {
2139 $createdEvents[$eventId] = $eventId;
2143 return [$allEvents, $createdEvents];
2147 * Make sure that the user has permission to access this event.
2148 * TODO: This function needs refactoring / cleaning up after being split from checkPermissions()
2151 * Array of events with permissions (array_keys=permissions)
2152 * @throws \CiviCRM_API3_Exception
2154 public static function getAllPermissions() {
2155 if (!isset(Civi
::$statics[__CLASS__
]['permissions'])) {
2156 list($allEvents, $createdEvents) = self
::checkPermissionGetInfo();
2158 // Note: for a multisite setup, a user with edit all events, can edit all events
2159 // including those from other sites
2160 if (CRM_Core_Permission
::check('edit all events')) {
2161 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
] = array_keys($allEvents);
2164 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
] = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_event', $allEvents, $createdEvents);
2167 if (CRM_Core_Permission
::check('edit all events')) {
2168 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
] = array_keys($allEvents);
2171 if (CRM_Core_Permission
::check('access CiviEvent') &&
2172 CRM_Core_Permission
::check('view event participants')
2174 // use case: allow "view all events" but NOT "edit all events"
2175 // so for a normal site allow users with these two permissions to view all events AND
2176 // at the same time also allow any hook to override if needed.
2177 $createdEvents = array_keys($allEvents);
2179 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
] = CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, $createdEvents);
2182 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::DELETE
] = [];
2183 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
2184 // Note: we want to restrict the scope of delete permission to
2185 // events that are editable/viewable (usecase multisite).
2186 // We can remove array_intersect once we have ACL support for delete functionality.
2187 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::DELETE
] = array_intersect(Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::EDIT
],
2188 Civi
::$statics[__CLASS__
]['permissions'][CRM_Core_Permission
::VIEW
]
2193 return Civi
::$statics[__CLASS__
]['permissions'];
2197 * Build From Email as the combination of all the email ids of the logged in user,
2198 * the domain email id and the email id configured for the event
2200 * @param int $eventId
2201 * The id of the event.
2204 * an array of email ids
2206 public static function getFromEmailIds($eventId = NULL) {
2207 $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email
::getFromEmail();
2210 // add the email id configured for the event
2211 $params = ['id' => $eventId];
2212 $returnProperties = ['confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm'];
2215 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $params, $eventEmail, $returnProperties);
2216 if (!empty($eventEmail['confirm_from_name']) && !empty($eventEmail['confirm_from_email'])) {
2217 $eventEmailId = "{$eventEmail['confirm_from_name']} <{$eventEmail['confirm_from_email']}>";
2219 $fromEmailValues['from_email_id'][$eventEmailId] = htmlspecialchars($eventEmailId);
2221 'cc' => $eventEmail['cc_confirm'] ??
NULL,
2222 'bcc' => $eventEmail['bcc_confirm'] ??
NULL,
2224 $fromEmailValues = array_merge($fromEmailValues, $fromEmailId);
2228 return $fromEmailValues;
2232 * Calculate event total seats occupied.
2234 * @param int $eventId
2236 * @param sting $extraWhereClause
2237 * Extra filter on participants.
2240 * event total seats w/ given criteria.
2242 public static function eventTotalSeats($eventId, $extraWhereClause = NULL) {
2243 if (empty($eventId)) {
2247 $extraWhereClause = trim($extraWhereClause);
2248 if (!empty($extraWhereClause)) {
2249 $extraWhereClause = " AND ( {$extraWhereClause} )";
2252 //event seats calculation :
2253 //1. consider event seat as a single when participant does not have line item.
2254 //2. consider event seat as a single when participant has line items but does not
2255 // have count for corresponding price field value ( ie price field value does not carry any seat )
2256 //3. consider event seat as a sum of all seats from line items in case price field value carries count.
2259 SELECT IF ( SUM( value.count*lineItem.qty ),
2260 SUM( value.count*lineItem.qty ) +
2261 COUNT( DISTINCT participant.id ) -
2262 COUNT( DISTINCT IF ( value.count, participant.id, NULL ) ),
2263 COUNT( DISTINCT participant.id ) )
2264 FROM civicrm_participant participant
2265 INNER JOIN civicrm_contact contact ON ( contact.id = participant.contact_id AND contact.is_deleted = 0 )
2266 INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
2267 LEFT JOIN civicrm_line_item lineItem ON ( lineItem.entity_id = participant.id
2268 AND lineItem.entity_table = 'civicrm_participant' )
2269 LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id AND value.count )
2270 WHERE ( participant.event_id = %1 )
2271 AND participant.is_test = 0
2273 GROUP BY participant.event_id";
2275 return (int) CRM_Core_DAO
::singleValueQuery($query, [1 => [$eventId, 'Positive']]);
2279 * Retrieve event template default values to be set.
2280 * as default values for current new event.
2282 * @param int $templateId
2283 * Event template id.
2286 * Array of custom data defaults.
2288 public static function getTemplateDefaultValues($templateId) {
2294 $templateParams = ['id' => $templateId];
2295 CRM_Event_BAO_Event
::retrieve($templateParams, $defaults);
2296 $fieldsToExclude = [
2299 'default_discount_fee_id',
2305 $defaults = array_diff_key($defaults, array_flip($fieldsToExclude));
2306 foreach ($defaults as $key => $value) {
2307 $customFieldInfo = CRM_Core_BAO_CustomField
::getKeyID($key, TRUE);
2308 if (!empty($customFieldInfo[1])) {
2309 $defaults[str_replace($customFieldInfo[1], '-' . $customFieldInfo[1], $key)] = $value;
2310 unset($defaults[$key]);
2317 * @param int $event_id
2321 public static function get_sub_events($event_id) {
2322 $params = ['parent_event_id' => $event_id];
2324 return CRM_Event_BAO_Event
::retrieve($params, $defaults);
2328 * Update the Campaign Id of all the participants of the given event.
2330 * @param int $eventID
2332 * @param int $eventCampaignID
2333 * Campaign id of that event.
2335 public static function updateParticipantCampaignID($eventID, $eventCampaignID) {
2337 $params[1] = [$eventID, 'Integer'];
2339 if (empty($eventCampaignID)) {
2340 $query = "UPDATE civicrm_participant SET campaign_id = NULL WHERE event_id = %1";
2343 $query = "UPDATE civicrm_participant SET campaign_id = %2 WHERE event_id = %1";
2344 $params[2] = [$eventCampaignID, 'Integer'];
2346 CRM_Core_DAO
::executeQuery($query, $params);
2350 * Get options for a given field.
2351 * @see CRM_Core_DAO::buildOptions
2353 * @param string $fieldName
2354 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
2355 * @param array $props : whatever is known about this dao object
2357 * @return array|bool
2359 public static function buildOptions($fieldName, $context = NULL, $props = []) {
2361 // Special logic for fields whose options depend on context or properties
2362 switch ($fieldName) {
2363 case 'financial_type_id':
2364 // @fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
2365 // @fixme - https://lab.civicrm.org/dev/core/issues/547 if CiviContribute not enabled this causes an invalid query
2366 // because $relationTypeId is not set in CRM_Financial_BAO_FinancialType::getIncomeFinancialType()
2367 if (array_key_exists('CiviContribute', CRM_Core_Component
::getEnabledComponents())) {
2368 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
2372 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
2378 public static function getEntityRefFilters() {
2380 ['key' => 'event_type_id', 'value' => ts('Event Type')],
2382 'key' => 'start_date',
2383 'value' => ts('Start Date'),
2385 ['key' => '{">":"now"}', 'value' => ts('Upcoming')],
2387 'key' => '{"BETWEEN":["now - 3 month","now"]}',
2388 'value' => ts('Past 3 Months'),
2391 'key' => '{"BETWEEN":["now - 6 month","now"]}',
2392 'value' => ts('Past 6 Months'),
2395 'key' => '{"BETWEEN":["now - 1 year","now"]}',
2396 'value' => ts('Past Year'),
2404 * Get the appropriate links to iCal pages/feeds.
2406 * @param int $eventId
2409 * All of the icons to show.
2411 public static function getICalLinks($eventId = NULL) {
2412 $return = $eventId ?
[] : [
2414 'url' => CRM_Utils_System
::url('civicrm/event/ical', 'reset=1&list=1&html=1', TRUE, NULL, TRUE),
2415 'text' => ts('HTML listing of current and future public events.'),
2416 'icon' => 'fa-th-list',
2419 'url' => CRM_Utils_System
::url('civicrm/event/ical', 'reset=1&list=1&rss=1', TRUE, NULL, TRUE),
2420 'text' => ts('Get RSS 2.0 feed for current and future public events.'),
2428 $query['id'] = $eventId;
2431 'url' => CRM_Utils_System
::url('civicrm/event/ical', $query, TRUE, NULL, TRUE),
2432 'text' => $eventId ?
ts('Download iCalendar entry for this event.') : ts('Download iCalendar entry for current and future public events.'),
2433 'icon' => 'fa-download',
2437 'url' => CRM_Utils_System
::url('civicrm/event/ical', $query, TRUE, NULL, TRUE),
2438 'text' => $eventId ?
ts('iCalendar feed for this event.') : ts('iCalendar feed for current and future public events.'),
2439 'icon' => 'fa-link',