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
19 * Event Info Page - Summary about the event
21 class CRM_Event_Page_EventInfo
extends CRM_Core_Page
{
26 * This method is called after the page is created. It checks for the
27 * type of action and executes that action.
28 * Finally it calls the parent's run method.
32 public function run() {
34 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
35 $config = CRM_Core_Config
::singleton();
36 // ensure that the user has permission to see this page
37 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::VIEW
,
38 $this->_id
, 'view event info'
41 CRM_Utils_System
::setUFMessage(ts('You do not have permission to view this event'));
42 return CRM_Utils_System
::permissionDenied();
45 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
46 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'register');
47 $this->assign('context', $context);
49 $this->assign('iCal', CRM_Event_BAO_Event
::getICalLinks($this->_id
));
51 // Sometimes we want to suppress the Event Full msg
52 $noFullMsg = CRM_Utils_Request
::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
54 // set breadcrumb to append to 2nd layer pages
55 $breadCrumbPath = CRM_Utils_System
::url('civicrm/event/info',
56 "id={$this->_id}&reset=1"
59 //retrieve event information
60 $params = ['id' => $this->_id
];
61 CRM_Event_BAO_Event
::retrieve($params, $values['event']);
63 if (!$values['event']['is_active']) {
64 CRM_Utils_System
::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
65 return CRM_Utils_System
::permissionDenied();
68 if (!$values['event']['is_public']) {
69 CRM_Utils_System
::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
72 if (!empty($values['event']['is_template'])) {
73 // form is an Event Template
74 CRM_Core_Error
::statusBounce(ts('The page you requested is currently unavailable.'));
77 // Add Event Type to $values in case folks want to display it
78 $values['event']['event_type'] = CRM_Utils_Array
::value($values['event']['event_type_id'], CRM_Event_PseudoConstant
::eventType());
80 $this->assign('isShowLocation', CRM_Utils_Array
::value('is_show_location', $values['event']));
82 // Reset event time zone info
83 $values['event']['event_start_date_utc'] = CRM_Utils_Date
::convertTimeZone($values['event']['event_start_date'], 'UTC');
84 $values['event']['event_start_date'] = CRM_Utils_Date
::convertTimeZone($values['event']['event_start_date'], $values['event']['event_tz']);
85 $values['event']['event_end_date_utc'] = CRM_Utils_Date
::convertTimeZone($values['event']['event_end_date'], 'UTC');
86 $values['event']['event_end_date'] = CRM_Utils_Date
::convertTimeZone($values['event']['event_end_date'], $values['event']['event_tz']);
89 $values['event']['event_tz'] = CRM_Core_SelectValues
::timezone()[$values['event']['event_tz']];
92 if ($this->_id
&& !empty($values['event']['is_monetary'])) {
93 CRM_Contribute_BAO_Contribution_Utils
::overrideDefaultCurrency($values['event']);
96 $discountId = CRM_Core_BAO_Discount
::findSet($this->_id
, 'civicrm_event');
98 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
101 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_id
);
104 // get price set options, - CRM-5209
106 $setDetails = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, TRUE);
108 $priceSetFields = $setDetails[$priceSetId]['fields'];
109 if (is_array($priceSetFields)) {
111 $visibility = CRM_Core_PseudoConstant
::visibility('name');
113 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
114 $adminFieldVisible = FALSE;
115 if (CRM_Core_Permission
::check('administer CiviCRM')) {
116 $adminFieldVisible = TRUE;
119 foreach ($priceSetFields as $fid => $fieldValues) {
120 if (!is_array($fieldValues['options']) ||
121 empty($fieldValues['options']) ||
122 (CRM_Utils_Array
::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE)
127 if (count($fieldValues['options']) > 1) {
128 $values['feeBlock']['value'][$fieldCnt] = '';
129 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
130 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
131 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ??
NULL;
133 $labelClass = 'price_set_option-label';
136 $labelClass = 'price_set_field-label';
138 // show tax rate with amount
139 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
140 $taxTerm = Civi
::settings()->get('tax_term');
141 $displayOpt = $invoiceSettings['tax_display_settings'] ??
NULL;
143 foreach ($fieldValues['options'] as $optionId => $optionVal) {
144 if (CRM_Utils_Array
::value('visibility_id', $optionVal) != array_search('public', $visibility) &&
145 $adminFieldVisible == FALSE
150 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ??
NULL;
151 if (Civi
::settings()->get('invoicing') && isset($optionVal['tax_amount'])) {
152 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField
::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
153 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
156 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
157 $values['feeBlock']['tax_amount'][$fieldCnt] = 0;
159 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
160 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
165 // Tell tpl we have price set fee data and whether it's a quick_config price set
166 $this->assign('isPriceSet', 1);
167 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
171 $params = ['entity_id' => $this->_id
, 'entity_table' => 'civicrm_event'];
172 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
174 // fix phone type labels
175 if (!empty($values['location']['phone'])) {
176 $phoneTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Phone', 'phone_type_id');
177 foreach ($values['location']['phone'] as &$val) {
178 if (!empty($val['phone_type_id'])) {
179 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
184 //retrieve custom field information
185 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Event', NULL, $this->_id
, 0, $values['event']['event_type_id'], NULL,
186 TRUE, NULL, FALSE, CRM_Core_Permission
::VIEW
, NULL, TRUE);
187 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id
);
188 $this->assign('action', CRM_Core_Action
::VIEW
);
189 //To show the event location on maps directly on event info page
190 $locations = CRM_Event_BAO_Event
::getMapInfo($this->_id
);
191 if (!empty($locations) && !empty($values['event']['is_map'])) {
192 $this->assign('locations', $locations);
193 $this->assign('mapProvider', $config->mapProvider
);
194 $this->assign('mapKey', $config->mapAPIKey
);
195 $sumLat = $sumLng = 0;
196 $maxLat = $maxLng = -400;
197 $minLat = $minLng = 400;
198 foreach ($locations as $location) {
199 $sumLat +
= $location['lat'];
200 $sumLng +
= $location['lng'];
202 if ($location['lat'] > $maxLat) {
203 $maxLat = $location['lat'];
205 if ($location['lat'] < $minLat) {
206 $minLat = $location['lat'];
209 if ($location['lng'] > $maxLng) {
210 $maxLng = $location['lng'];
212 if ($location['lng'] < $minLng) {
213 $minLng = $location['lng'];
218 'lat' => (float ) $sumLat / count($locations),
219 'lng' => (float ) $sumLng / count($locations),
222 'lat' => (float ) ($maxLat - $minLat),
223 'lng' => (float ) ($maxLng - $minLng),
225 $this->assign_by_ref('center', $center);
226 $this->assign_by_ref('span', $span);
227 if ($action == CRM_Core_Action
::PREVIEW
) {
228 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
229 "eid={$this->_id}&reset=1&action=preview",
235 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
236 "eid={$this->_id}&reset=1",
242 $this->assign('skipLocationType', TRUE);
243 $this->assign('mapURL', $mapURL);
246 if (CRM_Core_Permission
::check('view event participants')) {
247 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
248 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
249 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
250 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
251 $this->assign('findParticipants', $findParticipants);
254 $participantListingID = $values['event']['participant_listing_id'] ??
NULL;
255 if ($participantListingID) {
256 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
257 "reset=1&id={$this->_id}",
258 FALSE, NULL, TRUE, TRUE
260 $this->assign('participantListingURL', $participantListingURL);
263 $hasWaitingList = $values['event']['has_waitlist'] ??
NULL;
264 $eventFullMessage = CRM_Event_BAO_Participant
::eventFull($this->_id
,
269 $allowRegistration = FALSE;
270 $isEventOpenForRegistration = CRM_Event_BAO_Event
::validRegistrationRequest($values['event'], $this->_id
);
271 if (!empty($values['event']['is_online_registration'])) {
272 if ($isEventOpenForRegistration == 1) {
273 // we always generate urls for the front end in joomla
274 $action_query = $action === CRM_Core_Action
::PREVIEW ?
"&action=$action" : '';
275 $url = CRM_Utils_System
::url('civicrm/event/register',
276 "id={$this->_id}&reset=1{$action_query}",
280 if (!$eventFullMessage ||
$hasWaitingList) {
281 $registerText = ts('Register Now');
282 if (!empty($values['event']['registration_link_text'])) {
283 $registerText = $values['event']['registration_link_text'];
287 $allowRegistration = CRM_Event_BAO_Event
::showHideRegistrationLink($values);
289 $this->assign('registerText', $registerText);
290 $this->assign('registerURL', $url);
293 elseif (CRM_Core_Permission
::check('register for events')) {
294 $this->assign('registerClosed', TRUE);
298 $this->assign('allowRegistration', $allowRegistration);
300 $session = CRM_Core_Session
::singleton();
302 'contact_id' => $session->get('userID'),
303 'event_id' => $values['event']['id'] ??
NULL,
304 'role_id' => $values['event']['default_role_id'] ??
NULL,
307 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event
::checkRegistration($params)) {
308 $statusMessage = $eventFullMessage;
309 if (CRM_Event_BAO_Event
::checkRegistration($params)) {
310 if ($noFullMsg == 'false') {
311 if ($values['event']['allow_same_participant_emails']) {
312 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
315 $registerUrl = CRM_Utils_System
::url('civicrm/event/register',
316 "reset=1&id={$values['event']['id']}&cid=0"
318 $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', [1 => $registerUrl]);
322 elseif ($hasWaitingList) {
323 $statusMessage = $values['event']['waitlist_text'] ??
NULL;
324 if (!$statusMessage) {
325 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
328 if ($isEventOpenForRegistration == 1) {
329 CRM_Core_Session
::setStatus($statusMessage);
332 // we do not want to display recently viewed items, so turn off
333 $this->assign('displayRecent', FALSE);
335 // set page title = event title
336 CRM_Utils_System
::setTitle($values['event']['title']);
338 $this->assign('event', $values['event']);
339 if (isset($values['feeBlock'])) {
340 $this->assign('feeBlock', $values['feeBlock']);
342 $this->assign('location', $values['location']);
344 if (CRM_Core_Permission
::check(['access CiviEvent', 'edit all events'])) {
345 $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent
::tabs());
348 return parent
::run();
354 public function getTemplateFileName() {
356 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
357 $template = CRM_Core_Page
::getTemplate();
359 if ($template->template_exists($templateFile)) {
360 return $templateFile;
363 return parent
::getTemplateFileName();