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