| Total Complexity | 131 |
| Total Lines | 1061 |
| Duplicated Lines | 0 % |
| Changes | 11 | ||
| Bugs | 0 | Features | 0 |
Complex classes like EventController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EventController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 56 | class EventController extends AbstractController |
||
| 57 | { |
||
| 58 | protected EventCacheService $eventCacheService; |
||
| 59 | |||
| 60 | public function injectEventCacheService(EventCacheService $cacheService): void |
||
| 61 | { |
||
| 62 | $this->eventCacheService = $cacheService; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Assign contentObjectData and pageData view |
||
| 67 | */ |
||
| 68 | protected function initializeView(): void |
||
| 69 | { |
||
| 70 | $this->view->assign('contentObjectData', $this->request->getAttribute('currentContentObject')->data ?? null); |
||
| 71 | if ($this->getTypoScriptFrontendController()) { |
||
| 72 | $this->view->assign('pageData', $this->getTypoScriptFrontendController()->page); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Initializes the current action |
||
| 78 | */ |
||
| 79 | public function initializeAction(): void |
||
| 80 | { |
||
| 81 | $typoScriptFrontendController = $this->getTypoScriptFrontendController(); |
||
| 82 | if ($typoScriptFrontendController !== null) { |
||
| 83 | static $cacheTagsSet = false; |
||
| 84 | |||
| 85 | if (!$cacheTagsSet) { |
||
| 86 | $typoScriptFrontendController->addCacheTags(['tx_sfeventmgt']); |
||
| 87 | $cacheTagsSet = true; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Initialize list action and set format |
||
| 94 | */ |
||
| 95 | public function initializeListAction(): void |
||
| 96 | { |
||
| 97 | if (isset($this->settings['list']['format'])) { |
||
| 98 | $this->request = $this->request->withFormat($this->settings['list']['format']); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * List view |
||
| 104 | */ |
||
| 105 | public function listAction(array $overwriteDemand = []): ResponseInterface |
||
| 106 | { |
||
| 107 | $eventDemand = EventDemand::createFromSettings($this->settings); |
||
| 108 | $foreignRecordDemand = ForeignRecordDemand::createFromSettings($this->settings); |
||
| 109 | $categoryDemand = CategoryDemand::createFromSettings($this->settings); |
||
| 110 | if ($this->isOverwriteDemand($overwriteDemand)) { |
||
| 111 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 112 | } |
||
| 113 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 114 | $categories = $this->categoryRepository->findDemanded($categoryDemand); |
||
| 115 | $locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
||
| 116 | $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
||
| 117 | $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand); |
||
| 118 | |||
| 119 | $modifyListViewVariablesEvent = new ModifyListViewVariablesEvent( |
||
| 120 | [ |
||
| 121 | 'events' => $events, |
||
| 122 | 'pagination' => $this->getPagination($events, $this->settings['pagination'] ?? []), |
||
| 123 | 'categories' => $categories, |
||
| 124 | 'locations' => $locations, |
||
| 125 | 'organisators' => $organisators, |
||
| 126 | 'speakers' => $speakers, |
||
| 127 | 'overwriteDemand' => $overwriteDemand, |
||
| 128 | 'eventDemand' => $eventDemand, |
||
| 129 | 'settings' => $this->settings, |
||
| 130 | ], |
||
| 131 | $this |
||
| 132 | ); |
||
| 133 | $this->eventDispatcher->dispatch($modifyListViewVariablesEvent); |
||
| 134 | $variables = $modifyListViewVariablesEvent->getVariables(); |
||
| 135 | $this->view->assignMultiple($variables); |
||
| 136 | |||
| 137 | $this->eventCacheService->addPageCacheTagsByEventDemandObject($eventDemand); |
||
| 138 | |||
| 139 | return $this->htmlResponse(); |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Calendar view |
||
| 144 | */ |
||
| 145 | public function calendarAction(array $overwriteDemand = []): ResponseInterface |
||
| 146 | { |
||
| 147 | $eventDemand = EventDemand::createFromSettings($this->settings); |
||
| 148 | $foreignRecordDemand = ForeignRecordDemand::createFromSettings($this->settings); |
||
| 149 | $categoryDemand = CategoryDemand::createFromSettings($this->settings); |
||
| 150 | if ($this->isOverwriteDemand($overwriteDemand)) { |
||
| 151 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 152 | } |
||
| 153 | |||
| 154 | // Set month/year to demand if not given |
||
| 155 | if (!$eventDemand->getMonth()) { |
||
| 156 | $currentMonth = (int)date('n'); |
||
| 157 | $eventDemand->setMonth($currentMonth); |
||
| 158 | } else { |
||
| 159 | $currentMonth = $eventDemand->getMonth(); |
||
| 160 | } |
||
| 161 | if (!$eventDemand->getYear()) { |
||
| 162 | $currentYear = (int)date('Y'); |
||
| 163 | $eventDemand->setYear($currentYear); |
||
| 164 | } else { |
||
| 165 | $currentYear = $eventDemand->getYear(); |
||
| 166 | } |
||
| 167 | |||
| 168 | // If a weeknumber is given in overwriteDemand['week'], we overwrite the current month |
||
| 169 | if ($overwriteDemand['week'] ?? false) { |
||
| 170 | $firstDayOfWeek = (new DateTime())->setISODate($currentYear, (int)$overwriteDemand['week']); |
||
| 171 | $currentMonth = (int)$firstDayOfWeek->format('m'); |
||
| 172 | $eventDemand->setMonth($currentMonth); |
||
| 173 | } else { |
||
| 174 | $firstDayOfWeek = (new DateTime())->setISODate($currentYear, (int)date('W')); |
||
| 175 | } |
||
| 176 | |||
| 177 | // Set demand from calendar date range instead of month / year |
||
| 178 | if ((bool)($this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks'] ?? false)) { |
||
| 179 | $eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand); |
||
| 180 | } |
||
| 181 | |||
| 182 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 183 | $weeks = $this->calendarService->getCalendarArray( |
||
| 184 | $currentMonth, |
||
| 185 | $currentYear, |
||
| 186 | strtotime('today midnight'), |
||
| 187 | (int)($this->settings['calendar']['firstDayOfWeek'] ?? 1), |
||
| 188 | $events |
||
| 189 | ); |
||
| 190 | |||
| 191 | $modifyCalendarViewVariablesEvent = new ModifyCalendarViewVariablesEvent( |
||
| 192 | [ |
||
| 193 | 'events' => $events, |
||
| 194 | 'weeks' => $weeks, |
||
| 195 | 'categories' => $this->categoryRepository->findDemanded($categoryDemand), |
||
| 196 | 'locations' => $this->locationRepository->findDemanded($foreignRecordDemand), |
||
| 197 | 'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand), |
||
| 198 | 'eventDemand' => $eventDemand, |
||
| 199 | 'overwriteDemand' => $overwriteDemand, |
||
| 200 | 'currentPageId' => $this->getTypoScriptFrontendController()->id, |
||
| 201 | 'firstDayOfMonth' => DateTime::createFromFormat( |
||
| 202 | 'd.m.Y', |
||
| 203 | sprintf('1.%s.%s', $currentMonth, $currentYear) |
||
| 204 | ), |
||
| 205 | 'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'), |
||
| 206 | 'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month'), |
||
| 207 | 'weekConfig' => $this->calendarService->getWeekConfig($firstDayOfWeek), |
||
| 208 | 'settings' => $this->settings, |
||
| 209 | ], |
||
| 210 | $this |
||
| 211 | ); |
||
| 212 | $this->eventDispatcher->dispatch($modifyCalendarViewVariablesEvent); |
||
| 213 | $variables = $modifyCalendarViewVariablesEvent->getVariables(); |
||
| 214 | |||
| 215 | $this->view->assignMultiple($variables); |
||
| 216 | return $this->htmlResponse(); |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Changes the given event demand object to select a date range for a calendar month including days of the previous |
||
| 221 | * month for the first week and they days for the next month for the last week |
||
| 222 | */ |
||
| 223 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand): EventDemand |
||
| 224 | { |
||
| 225 | $calendarDateRange = $this->calendarService->getCalendarDateRange( |
||
| 226 | $eventDemand->getMonth(), |
||
| 227 | $eventDemand->getYear(), |
||
| 228 | (int)($this->settings['calendar']['firstDayOfWeek'] ?? 0) |
||
| 229 | ); |
||
| 230 | |||
| 231 | $eventDemand->setMonth(0); |
||
| 232 | $eventDemand->setYear(0); |
||
| 233 | |||
| 234 | $startDate = new DateTime(); |
||
| 235 | $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']); |
||
| 236 | $endDate = new DateTime(); |
||
| 237 | $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']); |
||
| 238 | $endDate->setTime(23, 59, 59); |
||
| 239 | |||
| 240 | $searchDemand = GeneralUtility::makeInstance(SearchDemand::class); |
||
| 241 | $searchDemand->setStartDate($startDate); |
||
| 242 | $searchDemand->setEndDate($endDate); |
||
| 243 | $eventDemand->setSearchDemand($searchDemand); |
||
| 244 | |||
| 245 | return $eventDemand; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Detail view for an event |
||
| 250 | * |
||
| 251 | * @return mixed |
||
| 252 | */ |
||
| 253 | public function detailAction(?Event $event = null) |
||
| 254 | { |
||
| 255 | $event = $this->evaluateSingleEventSetting($event); |
||
| 256 | $event = $this->evaluateIsShortcutSetting($event); |
||
| 257 | $event = $this->evaluateEventPreviewSetting($event); |
||
| 258 | if (is_a($event, Event::class) && ($this->settings['detail']['checkPidOfEventRecord'] ?? false)) { |
||
| 259 | $event = $this->checkPidOfEventRecord($event); |
||
| 260 | } |
||
| 261 | |||
| 262 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 263 | return $this->handleEventNotFoundError($this->settings); |
||
| 264 | } |
||
| 265 | |||
| 266 | $modifyDetailViewVariablesEvent = new ModifyDetailViewVariablesEvent(['event' => $event, 'settings' => $this->settings], $this); |
||
| 267 | $this->eventDispatcher->dispatch($modifyDetailViewVariablesEvent); |
||
| 268 | $variables = $modifyDetailViewVariablesEvent->getVariables(); |
||
| 269 | |||
| 270 | $this->view->assignMultiple($variables); |
||
| 271 | if ($event !== null) { |
||
| 272 | $this->eventCacheService->addCacheTagsByEventRecords([$event]); |
||
| 273 | } |
||
| 274 | |||
| 275 | return $this->htmlResponse(); |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Error handling if event is not found |
||
| 280 | * |
||
| 281 | * @param array $settings |
||
| 282 | * @return ResponseInterface |
||
| 283 | * @throws Exception |
||
| 284 | * @throws PropagateResponseException |
||
| 285 | * @throws PageNotFoundException |
||
| 286 | */ |
||
| 287 | protected function handleEventNotFoundError(array $settings): ResponseInterface |
||
| 288 | { |
||
| 289 | if (empty($settings['event']['errorHandling'])) { |
||
| 290 | throw new Exception('Event errorHandling not configured. Please check settings.event.errorHandling', 1671205677); |
||
| 291 | } |
||
| 292 | |||
| 293 | $configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true); |
||
| 294 | |||
| 295 | switch ($configuration[0]) { |
||
| 296 | case 'redirectToListView': |
||
| 297 | $listPid = (int)($settings['listPid'] ?? 0) > 0 ? (int)$settings['listPid'] : 1; |
||
| 298 | return $this->redirect('list', null, null, null, $listPid); |
||
| 299 | case 'pageNotFoundHandler': |
||
| 300 | $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction( |
||
| 301 | $this->request, |
||
| 302 | 'Event not found.' |
||
| 303 | ); |
||
| 304 | throw new PropagateResponseException($response, 1631261423); |
||
| 305 | case 'showStandaloneTemplate': |
||
| 306 | default: |
||
| 307 | $status = (int)($configuration[2] ?? 200); |
||
| 308 | $standaloneTemplate = GeneralUtility::makeInstance(StandaloneView::class); |
||
| 309 | $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1])); |
||
| 310 | |||
| 311 | $response = $this->responseFactory->createResponse() |
||
| 312 | ->withStatus($status) |
||
| 313 | ->withHeader('Content-Type', 'text/html; charset=utf-8'); |
||
| 314 | $response->getBody()->write($standaloneTemplate->render()); |
||
| 315 | return $response; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Initiates the iCalendar download for the given event |
||
| 321 | * |
||
| 322 | * @return mixed |
||
| 323 | */ |
||
| 324 | public function icalDownloadAction(?Event $event = null) |
||
| 325 | { |
||
| 326 | if (is_a($event, Event::class) && ($this->settings['detail']['checkPidOfEventRecord'] ?? false)) { |
||
| 327 | $event = $this->checkPidOfEventRecord($event); |
||
| 328 | } |
||
| 329 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 330 | return $this->handleEventNotFoundError($this->settings); |
||
| 331 | } |
||
| 332 | $this->icalendarService->downloadiCalendarFile($event); |
||
| 333 | exit(); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Registration view for an event |
||
| 338 | */ |
||
| 339 | public function registrationAction(?Event $event = null): ResponseInterface |
||
| 340 | { |
||
| 341 | $event = $this->evaluateSingleEventSetting($event); |
||
| 342 | if (is_a($event, Event::class) && ($this->settings['registration']['checkPidOfEventRecord'] ?? false)) { |
||
| 343 | $event = $this->checkPidOfEventRecord($event); |
||
| 344 | } |
||
| 345 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 346 | return $this->handleEventNotFoundError($this->settings); |
||
| 347 | } |
||
| 348 | if ($event->getRestrictPaymentMethods()) { |
||
| 349 | $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event); |
||
| 350 | } else { |
||
| 351 | $paymentMethods = $this->paymentService->getPaymentMethods(); |
||
| 352 | } |
||
| 353 | |||
| 354 | $modifyRegistrationViewVariablesEvent = new ModifyRegistrationViewVariablesEvent( |
||
| 355 | [ |
||
| 356 | 'event' => $event, |
||
| 357 | 'paymentMethods' => $paymentMethods, |
||
| 358 | 'settings' => $this->settings, |
||
| 359 | ], |
||
| 360 | $this |
||
| 361 | ); |
||
| 362 | $this->eventDispatcher->dispatch($modifyRegistrationViewVariablesEvent); |
||
| 363 | $variables = $modifyRegistrationViewVariablesEvent->getVariables(); |
||
| 364 | $this->view->assignMultiple($variables); |
||
| 365 | |||
| 366 | return $this->htmlResponse(); |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Removes all possible spamcheck fields (which do not belong to the domain model) from arguments. |
||
| 371 | */ |
||
| 372 | protected function removePossibleSpamCheckFieldsFromArguments(): void |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Processes incoming registrations fields and adds field values to arguments |
||
| 395 | */ |
||
| 396 | protected function setRegistrationFieldValuesToArguments(): void |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Initialize arguments for saveRegistrationAction and ensures, action is only called via POST |
||
| 479 | */ |
||
| 480 | public function initializeSaveRegistrationAction(): void |
||
| 481 | { |
||
| 482 | if ($this->request->getMethod() !== 'POST') { |
||
| 483 | $response = GeneralUtility::makeInstance(ErrorController::class)->accessDeniedAction( |
||
| 484 | $this->request, |
||
| 485 | 'HTTP method is not allowed' |
||
| 486 | ); |
||
| 487 | throw new PropagateResponseException($response, 1726573183); |
||
| 488 | } |
||
| 489 | |||
| 490 | $this->arguments->getArgument('registration') |
||
| 491 | ->getPropertyMappingConfiguration()->forProperty('dateOfBirth') |
||
| 492 | ->setTypeConverterOption( |
||
| 493 | DateTimeConverter::class, |
||
| 494 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 495 | $this->settings['registration']['formatDateOfBirth'] ?? 'd.m.Y' |
||
| 496 | ); |
||
| 497 | $this->removePossibleSpamCheckFieldsFromArguments(); |
||
| 498 | $this->setRegistrationFieldValuesToArguments(); |
||
| 499 | } |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Saves the registration |
||
| 503 | * |
||
| 504 | * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationFieldValidator", param="registration") |
||
| 505 | * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator", param="registration") |
||
| 506 | */ |
||
| 507 | public function saveRegistrationAction(Registration $registration, Event $event): ResponseInterface |
||
| 508 | { |
||
| 509 | if (is_a($event, Event::class) && ($this->settings['registration']['checkPidOfEventRecord'] ?? false)) { |
||
| 510 | $event = $this->checkPidOfEventRecord($event); |
||
| 511 | } |
||
| 512 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 513 | return $this->handleEventNotFoundError($this->settings); |
||
| 514 | } |
||
| 515 | $autoConfirmation = (bool)($this->settings['registration']['autoConfirmation'] ?? false) || |
||
| 516 | $event->getEnableAutoconfirm(); |
||
| 517 | $result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
||
| 518 | [$success, $result] = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
||
| 519 | |||
| 520 | // Save registration if no errors |
||
| 521 | $registrationUid = 0; |
||
| 522 | if ($success) { |
||
| 523 | $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
||
| 524 | $event, |
||
| 525 | $registration->getAmountOfRegistrations() |
||
| 526 | ); |
||
| 527 | $linkValidity = (int)($this->settings['confirmation']['linkValidity'] ?? 3600); |
||
| 528 | if ($linkValidity === 0) { |
||
| 529 | // Use 3600 seconds as default value if not set or zero |
||
| 530 | $linkValidity = 3600; |
||
| 531 | } |
||
| 532 | $confirmationUntil = new DateTime(); |
||
| 533 | $confirmationUntil->add(new DateInterval('PT' . $linkValidity . 'S')); |
||
| 534 | |||
| 535 | $registration->setEvent($event); |
||
| 536 | $registration->setPid($event->getPid()); |
||
| 537 | $registration->setRegistrationDate(new DateTime()); |
||
| 538 | $registration->setConfirmationUntil($confirmationUntil); |
||
| 539 | $registration->setLanguage($this->getCurrentLanguageCode()); |
||
| 540 | $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
||
| 541 | $registration->setWaitlist($isWaitlistRegistration); |
||
| 542 | $this->registrationRepository->add($registration); |
||
| 543 | |||
| 544 | // Persist registration, so we have an UID |
||
| 545 | $this->persistAll(); |
||
| 546 | $registrationUid = $registration->getUid(); |
||
| 547 | |||
| 548 | if ($isWaitlistRegistration) { |
||
| 549 | $messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
||
| 550 | } else { |
||
| 551 | $messageType = MessageType::REGISTRATION_NEW; |
||
| 552 | } |
||
| 553 | |||
| 554 | $this->eventDispatcher->dispatch(new AfterRegistrationSavedEvent($registration, $this)); |
||
| 555 | |||
| 556 | // Send notifications to user and admin if confirmation link should be sent |
||
| 557 | if (!$autoConfirmation) { |
||
| 558 | $this->notificationService->sendUserMessage( |
||
| 559 | $event, |
||
| 560 | $registration, |
||
| 561 | $this->settings, |
||
| 562 | $messageType |
||
| 563 | ); |
||
| 564 | $this->notificationService->sendAdminMessage( |
||
| 565 | $event, |
||
| 566 | $registration, |
||
| 567 | $this->settings, |
||
| 568 | $messageType |
||
| 569 | ); |
||
| 570 | } |
||
| 571 | |||
| 572 | // Create given amount of registrations if necessary |
||
| 573 | $modifyCreateDependingRegistrationsEvent = new ModifyCreateDependingRegistrationsEvent( |
||
| 574 | $registration, |
||
| 575 | ($registration->getAmountOfRegistrations() > 1), |
||
| 576 | $this |
||
| 577 | ); |
||
| 578 | $this->eventDispatcher->dispatch($modifyCreateDependingRegistrationsEvent); |
||
| 579 | $createDependingRegistrations = $modifyCreateDependingRegistrationsEvent->getCreateDependingRegistrations(); |
||
| 580 | if ($createDependingRegistrations) { |
||
| 581 | $this->registrationService->createDependingRegistrations($registration); |
||
| 582 | } |
||
| 583 | |||
| 584 | // Flush page cache for event, since new registration has been added |
||
| 585 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
||
| 586 | } |
||
| 587 | |||
| 588 | if ($autoConfirmation && $success) { |
||
| 589 | return $this->redirect( |
||
| 590 | 'confirmRegistration', |
||
| 591 | null, |
||
| 592 | null, |
||
| 593 | [ |
||
| 594 | 'reguid' => $registration->getUid(), |
||
| 595 | 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()), |
||
| 596 | ] |
||
| 597 | ); |
||
| 598 | } |
||
| 599 | |||
| 600 | return $this->redirect( |
||
| 601 | 'saveRegistrationResult', |
||
| 602 | null, |
||
| 603 | null, |
||
| 604 | [ |
||
| 605 | 'result' => $result, |
||
| 606 | 'eventuid' => $event->getUid(), |
||
| 607 | 'reguid' => $registrationUid, |
||
| 608 | 'hmac' => $this->hashService->generateHmac('event-' . $event->getUid() . '-reg-' . $registrationUid), |
||
| 609 | ] |
||
| 610 | ); |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Shows the result of the saveRegistrationAction |
||
| 615 | */ |
||
| 616 | public function saveRegistrationResultAction(int $result, int $eventuid, string $hmac): ResponseInterface |
||
| 617 | { |
||
| 618 | $reguid = $this->request->hasArgument('reguid') ? (int)$this->request->getArgument('reguid') : 0; |
||
| 619 | |||
| 620 | $event = null; |
||
| 621 | $registration = null; |
||
| 622 | $failed = true; |
||
| 623 | |||
| 624 | switch ($result) { |
||
| 625 | case RegistrationResult::REGISTRATION_SUCCESSFUL: |
||
| 626 | $messageKey = 'event.message.registrationsuccessful'; |
||
| 627 | $titleKey = 'registrationResult.title.successful'; |
||
| 628 | $failed = false; |
||
| 629 | break; |
||
| 630 | case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST: |
||
| 631 | $messageKey = 'event.message.registrationwaitlistsuccessful'; |
||
| 632 | $titleKey = 'registrationWaitlistResult.title.successful'; |
||
| 633 | $failed = false; |
||
| 634 | break; |
||
| 635 | case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED: |
||
| 636 | $messageKey = 'event.message.registrationfailedeventexpired'; |
||
| 637 | $titleKey = 'registrationResult.title.failed'; |
||
| 638 | break; |
||
| 639 | case RegistrationResult::REGISTRATION_FAILED_EVENT_ENDED: |
||
| 640 | $messageKey = 'event.message.registrationfailedeventended'; |
||
| 641 | $titleKey = 'registrationResult.title.failed'; |
||
| 642 | break; |
||
| 643 | case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS: |
||
| 644 | $messageKey = 'event.message.registrationfailedmaxparticipants'; |
||
| 645 | $titleKey = 'registrationResult.title.failed'; |
||
| 646 | break; |
||
| 647 | case RegistrationResult::REGISTRATION_NOT_ENABLED: |
||
| 648 | $messageKey = 'event.message.registrationfailednotenabled'; |
||
| 649 | $titleKey = 'registrationResult.title.failed'; |
||
| 650 | break; |
||
| 651 | case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED: |
||
| 652 | $messageKey = 'event.message.registrationfaileddeadlineexpired'; |
||
| 653 | $titleKey = 'registrationResult.title.failed'; |
||
| 654 | break; |
||
| 655 | case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES: |
||
| 656 | $messageKey = 'event.message.registrationfailednotenoughfreeplaces'; |
||
| 657 | $titleKey = 'registrationResult.title.failed'; |
||
| 658 | break; |
||
| 659 | case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED: |
||
| 660 | $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded'; |
||
| 661 | $titleKey = 'registrationResult.title.failed'; |
||
| 662 | break; |
||
| 663 | case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE: |
||
| 664 | $messageKey = 'event.message.registrationfailedemailnotunique'; |
||
| 665 | $titleKey = 'registrationResult.title.failed'; |
||
| 666 | break; |
||
| 667 | default: |
||
| 668 | $messageKey = ''; |
||
| 669 | $titleKey = ''; |
||
| 670 | } |
||
| 671 | |||
| 672 | if (!$this->hashService->validateHmac('event-' . $eventuid . '-reg-' . $reguid, $hmac)) { |
||
| 673 | $messageKey = 'event.message.registrationsuccessfulwrongeventhmac'; |
||
| 674 | $titleKey = 'registrationResult.title.failed'; |
||
| 675 | } else { |
||
| 676 | $event = $this->eventRepository->findByUid($eventuid); |
||
| 677 | $registration = $this->registrationRepository->findByUid($reguid); |
||
| 678 | } |
||
| 679 | |||
| 680 | $this->view->assignMultiple([ |
||
| 681 | 'messageKey' => $messageKey, |
||
| 682 | 'titleKey' => $titleKey, |
||
| 683 | 'event' => $event, |
||
| 684 | 'registration' => $registration, |
||
| 685 | 'result' => $result, |
||
| 686 | 'failed' => $failed, |
||
| 687 | ]); |
||
| 688 | |||
| 689 | return $this->htmlResponse(); |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Shows the verify confirmation registration view, where the user has to submit a form to finally confirm the registration |
||
| 694 | */ |
||
| 695 | public function verifyConfirmRegistrationAction(int $reguid, string $hmac): ResponseInterface |
||
| 696 | { |
||
| 697 | /* @var $registration Registration */ |
||
| 698 | [$failed, $registration, $messageKey, $titleKey] = $this->registrationService->checkConfirmRegistration( |
||
| 699 | $reguid, |
||
| 700 | $hmac |
||
| 701 | ); |
||
| 702 | |||
| 703 | $variables = [ |
||
| 704 | 'reguid' => $reguid, |
||
| 705 | 'hmac' => $hmac, |
||
| 706 | 'confirmationPossible' => $registration && !$registration->getConfirmed(), |
||
| 707 | 'failed' => $failed, |
||
| 708 | 'messageKey' => $messageKey, |
||
| 709 | 'titleKey' => $titleKey, |
||
| 710 | 'event' => $registration?->getEvent(), |
||
| 711 | 'registration' => $registration, |
||
| 712 | 'settings' => $this->settings, |
||
| 713 | ]; |
||
| 714 | |||
| 715 | $this->view->assignMultiple($variables); |
||
| 716 | |||
| 717 | return $this->htmlResponse(); |
||
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Confirms the registration if possible and sends emails to admin and user |
||
| 722 | */ |
||
| 723 | public function confirmRegistrationAction(int $reguid, string $hmac): ResponseInterface |
||
| 724 | { |
||
| 725 | $event = null; |
||
| 726 | |||
| 727 | /* @var $registration Registration */ |
||
| 728 | [$failed, $registration, $messageKey, $titleKey] = $this->registrationService->checkConfirmRegistration( |
||
| 729 | $reguid, |
||
| 730 | $hmac |
||
| 731 | ); |
||
| 732 | |||
| 733 | if ($failed === false) { |
||
| 734 | $registration->setConfirmed(true); |
||
| 735 | $event = $registration->getEvent(); |
||
| 736 | $this->registrationRepository->update($registration); |
||
| 737 | |||
| 738 | $this->eventDispatcher->dispatch(new AfterRegistrationConfirmedEvent($registration, $this)); |
||
| 739 | |||
| 740 | $messageType = MessageType::REGISTRATION_CONFIRMED; |
||
| 741 | if ($registration->getWaitlist()) { |
||
| 742 | $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED; |
||
| 743 | } |
||
| 744 | |||
| 745 | // Send notifications to user and admin |
||
| 746 | $this->notificationService->sendUserMessage( |
||
| 747 | $registration->getEvent(), |
||
| 748 | $registration, |
||
| 749 | $this->settings, |
||
| 750 | $messageType |
||
| 751 | ); |
||
| 752 | $this->notificationService->sendAdminMessage( |
||
| 753 | $registration->getEvent(), |
||
| 754 | $registration, |
||
| 755 | $this->settings, |
||
| 756 | $messageType |
||
| 757 | ); |
||
| 758 | |||
| 759 | // Confirm registrations depending on main registration if necessary |
||
| 760 | if ($registration->getAmountOfRegistrations() > 1) { |
||
| 761 | $this->registrationService->confirmDependingRegistrations($registration); |
||
| 762 | } |
||
| 763 | } |
||
| 764 | |||
| 765 | // Redirect to payment provider if payment/redirect is enabled. |
||
| 766 | // Skip if the registration is a waitlist registration, since it is not sure, if the user will participate. |
||
| 767 | $paymentPid = (int)($this->settings['paymentPid'] ?? 0); |
||
| 768 | $paymentRedirectResponse = null; |
||
| 769 | $processRedirect = !$failed && |
||
| 770 | $paymentPid > 0 && |
||
| 771 | $registration && |
||
| 772 | !$registration->getWaitlist() && |
||
| 773 | $this->registrationService->redirectPaymentEnabled($registration); |
||
| 774 | if ($processRedirect) { |
||
| 775 | $paymentRedirectResponse = $this->getRedirectToPaymentResponse($paymentPid, $registration); |
||
| 776 | } |
||
| 777 | |||
| 778 | if ($paymentRedirectResponse instanceof ResponseInterface) { |
||
| 779 | return $paymentRedirectResponse; |
||
| 780 | } |
||
| 781 | |||
| 782 | $modifyConfirmRegistrationViewVariablesEvent = new ModifyConfirmRegistrationViewVariablesEvent( |
||
| 783 | [ |
||
| 784 | 'failed' => $failed, |
||
| 785 | 'messageKey' => $messageKey, |
||
| 786 | 'titleKey' => $titleKey, |
||
| 787 | 'event' => $event, |
||
| 788 | 'registration' => $registration, |
||
| 789 | 'settings' => $this->settings, |
||
| 790 | ], |
||
| 791 | $this |
||
| 792 | ); |
||
| 793 | $this->eventDispatcher->dispatch($modifyConfirmRegistrationViewVariablesEvent); |
||
| 794 | $variables = $modifyConfirmRegistrationViewVariablesEvent->getVariables(); |
||
| 795 | $this->view->assignMultiple($variables); |
||
| 796 | |||
| 797 | return $this->htmlResponse(); |
||
| 798 | } |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Returns a response object to the given payment PID. Extension authors can use ProcessRedirectToPaymentEvent |
||
| 802 | * PSR-14 event to intercept the redirect response. |
||
| 803 | */ |
||
| 804 | private function getRedirectToPaymentResponse(int $paymentPid, Registration $registration): ?ResponseInterface |
||
| 825 | } |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Shows the verify cancel registration view, where the user has to submit a form to finally cancel the registration |
||
| 829 | */ |
||
| 830 | public function verifyCancelRegistrationAction(int $reguid, string $hmac): ResponseInterface |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Cancels the registration if possible and sends emails to admin and user |
||
| 857 | */ |
||
| 858 | public function cancelRegistrationAction(int $reguid, string $hmac): ResponseInterface |
||
| 859 | { |
||
| 860 | $event = null; |
||
| 861 | |||
| 862 | /* @var $registration Registration */ |
||
| 863 | [$failed, $registration, $messageKey, $titleKey] = $this->registrationService->checkCancelRegistration( |
||
| 864 | $reguid, |
||
| 865 | $hmac |
||
| 866 | ); |
||
| 867 | |||
| 868 | if ($failed === false) { |
||
| 869 | $event = $registration->getEvent(); |
||
| 870 | |||
| 871 | // Send notifications (must run before cancelling the registration) |
||
| 872 | $this->notificationService->sendUserMessage( |
||
| 873 | $registration->getEvent(), |
||
| 874 | $registration, |
||
| 875 | $this->settings, |
||
| 876 | MessageType::REGISTRATION_CANCELLED |
||
| 877 | ); |
||
| 878 | $this->notificationService->sendAdminMessage( |
||
| 879 | $registration->getEvent(), |
||
| 880 | $registration, |
||
| 881 | $this->settings, |
||
| 882 | MessageType::REGISTRATION_CANCELLED |
||
| 883 | ); |
||
| 884 | |||
| 885 | // First cancel depending registrations |
||
| 886 | $processCancelDependingRegistrations = new ProcessCancelDependingRegistrationsEvent( |
||
| 887 | $registration, |
||
| 888 | $registration->getAmountOfRegistrations() > 1 |
||
| 889 | ); |
||
| 890 | $this->eventDispatcher->dispatch($processCancelDependingRegistrations); |
||
| 891 | if ($processCancelDependingRegistrations->getProcessCancellation()) { |
||
| 892 | $this->registrationService->cancelDependingRegistrations($registration); |
||
| 893 | } |
||
| 894 | |||
| 895 | // Finally cancel registration |
||
| 896 | $this->registrationRepository->remove($registration); |
||
| 897 | |||
| 898 | // Persist changes, so following functions can work with $event properties (e.g. amount of registrations) |
||
| 899 | $this->persistAll(); |
||
| 900 | |||
| 901 | $afterRegistrationCancelledEvent = new AfterRegistrationCancelledEvent($registration, $this); |
||
| 902 | $this->eventDispatcher->dispatch($afterRegistrationCancelledEvent); |
||
| 903 | |||
| 904 | // Dispatch event, so waitlist registrations can be moved up and default move up process can be stopped |
||
| 905 | $waitlistMoveUpEvent = new WaitlistMoveUpEvent($event, $this, true); |
||
| 906 | $this->eventDispatcher->dispatch($waitlistMoveUpEvent); |
||
| 907 | |||
| 908 | // Move up waitlist registrations if configured on event basis and if not disabled by $waitlistMoveUpEvent |
||
| 909 | if ($waitlistMoveUpEvent->getProcessDefaultMoveUp()) { |
||
| 910 | $this->registrationService->moveUpWaitlistRegistrations($event, $this->settings); |
||
| 911 | } |
||
| 912 | |||
| 913 | // Flush page cache for event, since amount of registrations has changed |
||
| 914 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
||
| 915 | } |
||
| 916 | |||
| 917 | $modifyCancelRegistrationViewVariablesEvent = new ModifyCancelRegistrationViewVariablesEvent( |
||
| 918 | [ |
||
| 919 | 'failed' => $failed, |
||
| 920 | 'messageKey' => $messageKey, |
||
| 921 | 'titleKey' => $titleKey, |
||
| 922 | 'event' => $event, |
||
| 923 | 'settings' => $this->settings, |
||
| 924 | ], |
||
| 925 | $this |
||
| 926 | ); |
||
| 927 | $this->eventDispatcher->dispatch($modifyCancelRegistrationViewVariablesEvent); |
||
| 928 | $variables = $modifyCancelRegistrationViewVariablesEvent->getVariables(); |
||
| 929 | $this->view->assignMultiple($variables); |
||
| 930 | |||
| 931 | return $this->htmlResponse(); |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Set date format for field startDate and endDate |
||
| 936 | */ |
||
| 937 | public function initializeSearchAction(): void |
||
| 938 | { |
||
| 939 | if ($this->settings !== null && ($this->settings['search']['dateFormat'] ?? false)) { |
||
| 940 | $this->arguments->getArgument('searchDemand') |
||
| 941 | ->getPropertyMappingConfiguration()->forProperty('startDate') |
||
| 942 | ->setTypeConverterOption( |
||
| 943 | DateTimeConverter::class, |
||
| 944 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 945 | $this->settings['search']['dateFormat'] |
||
| 946 | ); |
||
| 947 | $this->arguments->getArgument('searchDemand') |
||
| 948 | ->getPropertyMappingConfiguration()->forProperty('endDate') |
||
| 949 | ->setTypeConverterOption( |
||
| 950 | DateTimeConverter::class, |
||
| 951 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 952 | $this->settings['search']['dateFormat'] |
||
| 953 | ); |
||
| 954 | } |
||
| 955 | if ($this->arguments->hasArgument('searchDemand')) { |
||
| 956 | $propertyMappingConfiguration = $this->arguments->getArgument('searchDemand') |
||
| 957 | ->getPropertyMappingConfiguration(); |
||
| 958 | $propertyMappingConfiguration->allowAllProperties(); |
||
| 959 | $propertyMappingConfiguration->setTypeConverterOption( |
||
| 960 | PersistentObjectConverter::class, |
||
| 961 | PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, |
||
| 962 | true |
||
| 963 | ); |
||
| 964 | } |
||
| 965 | } |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Search view |
||
| 969 | */ |
||
| 970 | public function searchAction(?SearchDemand $searchDemand = null, array $overwriteDemand = []): ResponseInterface |
||
| 971 | { |
||
| 972 | $eventDemand = EventDemand::createFromSettings($this->settings); |
||
| 973 | $eventDemand->setSearchDemand($searchDemand); |
||
| 974 | $foreignRecordDemand = ForeignRecordDemand::createFromSettings($this->settings); |
||
| 975 | $categoryDemand = CategoryDemand::createFromSettings($this->settings); |
||
| 976 | |||
| 977 | if ($searchDemand !== null) { |
||
| 978 | $searchDemand->setFields($this->settings['search']['fields'] ?? ''); |
||
| 979 | |||
| 980 | $adjustTime = (bool)($this->settings['search']['adjustTime'] ?? false); |
||
| 981 | if ($adjustTime && $searchDemand->getStartDate() !== null) { |
||
| 982 | $searchDemand->getStartDate()->setTime(0, 0); |
||
| 983 | } |
||
| 984 | |||
| 985 | if ($adjustTime && $searchDemand->getEndDate() !== null) { |
||
| 986 | $searchDemand->getEndDate()->setTime(23, 59, 59); |
||
| 987 | } |
||
| 988 | } |
||
| 989 | |||
| 990 | if ($this->isOverwriteDemand($overwriteDemand)) { |
||
| 991 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 992 | } |
||
| 993 | |||
| 994 | $categories = $this->categoryRepository->findDemanded($categoryDemand); |
||
| 995 | $locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
||
| 996 | $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
||
| 997 | $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand); |
||
| 998 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 999 | |||
| 1000 | $modifySearchViewVariablesEvent = new ModifySearchViewVariablesEvent( |
||
| 1001 | [ |
||
| 1002 | 'events' => $events, |
||
| 1003 | 'categories' => $categories, |
||
| 1004 | 'locations' => $locations, |
||
| 1005 | 'organisators' => $organisators, |
||
| 1006 | 'speakers' => $speakers, |
||
| 1007 | 'searchDemand' => $searchDemand, |
||
| 1008 | 'overwriteDemand' => $overwriteDemand, |
||
| 1009 | 'settings' => $this->settings, |
||
| 1010 | ], |
||
| 1011 | $this |
||
| 1012 | ); |
||
| 1013 | $this->eventDispatcher->dispatch($modifySearchViewVariablesEvent); |
||
| 1014 | $variables = $modifySearchViewVariablesEvent->getVariables(); |
||
| 1015 | $this->view->assignMultiple($variables); |
||
| 1016 | |||
| 1017 | return $this->htmlResponse(); |
||
| 1018 | } |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
| 1022 | */ |
||
| 1023 | protected function isOverwriteDemand(array $overwriteDemand): bool |
||
| 1024 | { |
||
| 1025 | return (int)($this->settings['disableOverrideDemand'] ?? 0) !== 1 && $overwriteDemand !== []; |
||
| 1026 | } |
||
| 1027 | |||
| 1028 | /** |
||
| 1029 | * If no event is given and the singleEvent setting is set, the configured single event is returned |
||
| 1030 | */ |
||
| 1031 | protected function evaluateSingleEventSetting(?Event $event): ?Event |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * If no event is given and the isShortcut setting is set, the event is displayed using the "Insert Record" |
||
| 1042 | * content element and should be loaded from contect object data |
||
| 1043 | */ |
||
| 1044 | protected function evaluateIsShortcutSetting(?Event $event): ?Event |
||
| 1045 | { |
||
| 1046 | if ($event === null && (bool)($this->settings['detail']['isShortcut'] ?? false)) { |
||
| 1047 | $eventRawData = $this->request->getAttribute('currentContentObject')->data; |
||
| 1048 | $event = $this->eventRepository->findByUid($eventRawData['uid']); |
||
| 1049 | } |
||
| 1050 | |||
| 1051 | return $event; |
||
| 1052 | } |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * If no event is given and the the `event_preview` argument is set, the event is displayed for preview |
||
| 1056 | */ |
||
| 1057 | protected function evaluateEventPreviewSetting(?Event $event): ?Event |
||
| 1058 | { |
||
| 1059 | if ($event === null && $this->request->hasArgument('event_preview')) { |
||
| 1060 | $context = GeneralUtility::makeInstance(Context::class); |
||
| 1061 | $hasBackendUser = $context->getPropertyFromAspect('backend.user', 'isLoggedIn'); |
||
| 1062 | $previewEventId = (int)$this->request->getArgument('event_preview'); |
||
| 1063 | if ($previewEventId > 0 && $hasBackendUser) { |
||
| 1064 | if ($this->settings['previewHiddenRecords'] ?? false) { |
||
| 1065 | $event = $this->eventRepository->findByUidIncludeHidden($previewEventId); |
||
| 1066 | } else { |
||
| 1067 | $event = $this->eventRepository->findByUid($previewEventId); |
||
| 1068 | } |
||
| 1069 | } |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | return $event; |
||
| 1073 | } |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Checks if the event pid could be found in the storagePage settings of the detail plugin and |
||
| 1077 | * if the pid could not be found it return null instead of the event object. |
||
| 1078 | */ |
||
| 1079 | protected function checkPidOfEventRecord(Event $event): ?Event |
||
| 1095 | } |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Calls persistAll() of the persistenceManager |
||
| 1099 | */ |
||
| 1100 | protected function persistAll(): void |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Returns the language code of the current language |
||
| 1107 | */ |
||
| 1108 | protected function getCurrentLanguageCode(): string |
||
| 1117 | } |
||
| 1118 | } |
||
| 1119 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths