[REF] Preliminary cleanup for #17339
[civicrm-core.git] / CRM / Event / Page / EventInfo.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Event Info Page - Summmary about the event
20 */
21class CRM_Event_Page_EventInfo extends CRM_Core_Page {
22
23 /**
24 * Run the page.
25 *
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.
29 *
30 * @return void
6a488035 31 */
00be9182 32 public function run() {
6a488035
TO
33 //get the event id.
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,
353ffa53
TO
38 $this->_id, 'view event info'
39 )
40 ) {
6a488035
TO
41 CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
42 return CRM_Utils_System::permissionDenied();
43 }
44
45 $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
edc80cda 46 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'register');
6a488035
TO
47 $this->assign('context', $context);
48
679bd095
AH
49 $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks($this->_id));
50
6a488035
TO
51 // Sometimes we want to suppress the Event Full msg
52 $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
53
54 // set breadcrumb to append to 2nd layer pages
55 $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info',
56 "id={$this->_id}&reset=1"
57 );
6a488035
TO
58
59 //retrieve event information
be2fb01f 60 $params = ['id' => $this->_id];
6a488035
TO
61 CRM_Event_BAO_Event::retrieve($params, $values['event']);
62
63 if (!$values['event']['is_active']) {
12cc37ef
SB
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();
6a488035
TO
66 }
67
c6d4092b
RO
68 if (!$values['event']['is_public']) {
69 CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
70 }
71
6a488035
TO
72 if (!empty($values['event']['is_template'])) {
73 // form is an Event Template
e22ec653 74 CRM_Core_Error::statusBounce(ts('The page you requested is currently unavailable.'));
6a488035
TO
75 }
76
4b351970
DG
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());
e2d09ab4 79
6a488035
TO
80 $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
81
82 // show event fees.
8cc574cf 83 if ($this->_id && !empty($values['event']['is_monetary'])) {
85939a77 84 CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($values['event']);
6a488035
TO
85
86 //CRM-10434
d3e86119 87 $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
6a488035
TO
88 if ($discountId) {
89 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
0db6c3e1
TO
90 }
91 else {
9da8dc8c 92 $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
6a488035
TO
93 }
94
95 // get price set options, - CRM-5209
96 if ($priceSetId) {
9da8dc8c 97 $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
6a488035
TO
98
99 $priceSetFields = $setDetails[$priceSetId]['fields'];
100 if (is_array($priceSetFields)) {
101 $fieldCnt = 1;
102 $visibility = CRM_Core_PseudoConstant::visibility('name');
103
c7b3d063 104 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
ab8a593e 105 $adminFieldVisible = FALSE;
c7b3d063 106 if (CRM_Core_Permission::check('administer CiviCRM')) {
4eeb9a5b 107 $adminFieldVisible = TRUE;
c7b3d063
DG
108 }
109
6a488035
TO
110 foreach ($priceSetFields as $fid => $fieldValues) {
111 if (!is_array($fieldValues['options']) ||
112 empty($fieldValues['options']) ||
ab8a593e 113 (CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE)
6a488035
TO
114 ) {
115 continue;
116 }
117
118 if (count($fieldValues['options']) > 1) {
119 $values['feeBlock']['value'][$fieldCnt] = '';
120 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
121 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
9c1bc317 122 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ?? NULL;
6a488035
TO
123 $fieldCnt++;
124 $labelClass = 'price_set_option-label';
125 }
126 else {
127 $labelClass = 'price_set_field-label';
128 }
3a669c96 129 // show tax rate with amount
aaffa79f 130 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
530f1e12 131 $taxTerm = Civi::settings()->get('tax_term');
9c1bc317
CW
132 $displayOpt = $invoiceSettings['tax_display_settings'] ?? NULL;
133 $invoicing = $invoiceSettings['invoicing'] ?? NULL;
6a488035 134 foreach ($fieldValues['options'] as $optionId => $optionVal) {
c6833879
BS
135 if (CRM_Utils_Array::value('visibility_id', $optionVal) != array_search('public', $visibility) &&
136 $adminFieldVisible == FALSE
137 ) {
138 continue;
139 }
140
9c1bc317 141 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ?? NULL;
fe7983e7
PD
142 if ($invoicing && isset($optionVal['tax_amount'])) {
143 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
3a669c96 144 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
145 }
146 else {
147 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
148 }
6a488035
TO
149 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
150 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
151 $fieldCnt++;
152 }
153 }
154 }
155 // Tell tpl we have price set fee data and whether it's a quick_config price set
156 $this->assign('isPriceSet', 1);
157 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
158 }
353ffa53 159 }
6a488035 160
be2fb01f 161 $params = ['entity_id' => $this->_id, 'entity_table' => 'civicrm_event'];
6a488035
TO
162 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
163
45618a70 164 // fix phone type labels
165 if (!empty($values['location']['phone'])) {
166 $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
167 foreach ($values['location']['phone'] as &$val) {
168 if (!empty($val['phone_type_id'])) {
169 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
170 }
171 }
172 }
173
6a488035 174 //retrieve custom field information
0b330e6d 175 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_id, 0, $values['event']['event_type_id'], NULL, TRUE, NULL, FALSE, TRUE, NULL, TRUE);
e34e6979 176 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
6a488035
TO
177 $this->assign('action', CRM_Core_Action::VIEW);
178 //To show the event location on maps directly on event info page
179 $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
8cc574cf 180 if (!empty($locations) && !empty($values['event']['is_map'])) {
6a488035
TO
181 $this->assign('locations', $locations);
182 $this->assign('mapProvider', $config->mapProvider);
183 $this->assign('mapKey', $config->mapAPIKey);
184 $sumLat = $sumLng = 0;
185 $maxLat = $maxLng = -400;
8d7a9d07 186 $minLat = $minLng = 400;
6a488035
TO
187 foreach ($locations as $location) {
188 $sumLat += $location['lat'];
189 $sumLng += $location['lng'];
190
191 if ($location['lat'] > $maxLat) {
192 $maxLat = $location['lat'];
193 }
194 if ($location['lat'] < $minLat) {
195 $minLat = $location['lat'];
196 }
197
198 if ($location['lng'] > $maxLng) {
199 $maxLng = $location['lng'];
200 }
201 if ($location['lng'] < $minLng) {
202 $minLng = $location['lng'];
203 }
204 }
205
be2fb01f 206 $center = [
6ea503d4 207 'lat' => (float ) $sumLat / count($locations),
6a488035 208 'lng' => (float ) $sumLng / count($locations),
be2fb01f
CW
209 ];
210 $span = [
353ffa53
TO
211 'lat' => (float ) ($maxLat - $minLat),
212 'lng' => (float ) ($maxLng - $minLng),
be2fb01f 213 ];
6a488035
TO
214 $this->assign_by_ref('center', $center);
215 $this->assign_by_ref('span', $span);
216 if ($action == CRM_Core_Action::PREVIEW) {
217 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
218 "eid={$this->_id}&reset=1&action=preview",
53c223bf 219 FALSE, NULL, TRUE,
6a488035
TO
220 TRUE
221 );
222 }
223 else {
224 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
225 "eid={$this->_id}&reset=1",
53c223bf 226 FALSE, NULL, TRUE,
6a488035
TO
227 TRUE
228 );
229 }
230
231 $this->assign('skipLocationType', TRUE);
232 $this->assign('mapURL', $mapURL);
233 }
234
4cdc90e9
DH
235 if (CRM_Core_Permission::check('view event participants')) {
236 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
237 $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
238 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
239 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
240 $this->assign('findParticipants', $findParticipants);
241 }
6a488035 242
9c1bc317 243 $participantListingID = $values['event']['participant_listing_id'] ?? NULL;
6a488035
TO
244 if ($participantListingID) {
245 $participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
246 "reset=1&id={$this->_id}",
53c223bf 247 FALSE, NULL, TRUE, TRUE
6a488035
TO
248 );
249 $this->assign('participantListingURL', $participantListingURL);
250 }
251
9c1bc317 252 $hasWaitingList = $values['event']['has_waitlist'] ?? NULL;
6a488035
TO
253 $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id,
254 FALSE,
255 $hasWaitingList
256 );
257
258 $allowRegistration = FALSE;
5c6fa26c 259 $isEventOpenForRegistration = CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id);
a7488080 260 if (!empty($values['event']['is_online_registration'])) {
5c6fa26c 261 if ($isEventOpenForRegistration == 1) {
6a488035
TO
262 // we always generate urls for the front end in joomla
263 $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : '';
264 $url = CRM_Utils_System::url('civicrm/event/register',
265 "id={$this->_id}&reset=1{$action_query}",
53c223bf 266 FALSE, NULL, TRUE,
6a488035
TO
267 TRUE
268 );
269 if (!$eventFullMessage || $hasWaitingList) {
270 $registerText = ts('Register Now');
a7488080 271 if (!empty($values['event']['registration_link_text'])) {
6a488035
TO
272 $registerText = $values['event']['registration_link_text'];
273 }
274
275 // check if we're in shopping cart mode for events
aaffa79f 276 $enable_cart = Civi::settings()->get('enable_cart');
6a488035
TO
277 if ($enable_cart) {
278 $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
279 $registerText = $link['label'];
280
53c223bf 281 $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, FALSE, NULL, TRUE, TRUE);
6a488035
TO
282 }
283
284 //Fixed for CRM-4855
285 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
286
287 $this->assign('registerText', $registerText);
288 $this->assign('registerURL', $url);
289 $this->assign('eventCartEnabled', $enable_cart);
290 }
291 }
292 elseif (CRM_Core_Permission::check('register for events')) {
293 $this->assign('registerClosed', TRUE);
294 }
295 }
296
297 $this->assign('allowRegistration', $allowRegistration);
298
299 $session = CRM_Core_Session::singleton();
be2fb01f 300 $params = [
6ea503d4 301 'contact_id' => $session->get('userID'),
6b409353
CW
302 'event_id' => $values['event']['id'] ?? NULL,
303 'role_id' => $values['event']['default_role_id'] ?? NULL,
be2fb01f 304 ];
6a488035
TO
305
306 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) {
307 $statusMessage = $eventFullMessage;
308 if (CRM_Event_BAO_Event::checkRegistration($params)) {
309 if ($noFullMsg == 'false') {
310 if ($values['event']['allow_same_participant_emails']) {
311 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
312 }
313 else {
314 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
315 "reset=1&id={$values['event']['id']}&cid=0"
316 );
be2fb01f 317 $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]);
6a488035
TO
318 }
319 }
320 }
321 elseif ($hasWaitingList) {
9c1bc317 322 $statusMessage = $values['event']['waitlist_text'] ?? NULL;
6a488035
TO
323 if (!$statusMessage) {
324 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
325 }
326 }
5c6fa26c
JM
327 if ($isEventOpenForRegistration == 1) {
328 CRM_Core_Session::setStatus($statusMessage);
329 }
6a488035
TO
330 }
331 // we do not want to display recently viewed items, so turn off
332 $this->assign('displayRecent', FALSE);
333
334 // set page title = event title
335 CRM_Utils_System::setTitle($values['event']['title']);
336
337 $this->assign('event', $values['event']);
338 if (isset($values['feeBlock'])) {
339 $this->assign('feeBlock', $values['feeBlock']);
340 }
341 $this->assign('location', $values['location']);
342
742b6a7d 343 if (CRM_Core_Permission::check(['access CiviEvent', 'edit all events'])) {
7fffa5fa 344 $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs());
fdf80679
CW
345 }
346
6a488035
TO
347 return parent::run();
348 }
349
0cf587a7
EM
350 /**
351 * @return string
352 */
00be9182 353 public function getTemplateFileName() {
6a488035
TO
354 if ($this->_id) {
355 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
356 $template = CRM_Core_Page::getTemplate();
357
358 if ($template->template_exists($templateFile)) {
359 return $templateFile;
360 }
361 }
362 return parent::getTemplateFileName();
363 }
96025800 364
6a488035 365}