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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 |
||
| 36 | class EventController extends AbstractController |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var EventCacheService |
||
| 40 | */ |
||
| 41 | protected $eventCacheService = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param EventCacheService $cacheService |
||
| 45 | */ |
||
| 46 | public function injectEventCacheService(EventCacheService $cacheService) |
||
| 47 | { |
||
| 48 | $this->eventCacheService = $cacheService; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Assign contentObjectData and pageData to earch view |
||
| 53 | * |
||
| 54 | * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view |
||
| 55 | */ |
||
| 56 | protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) |
||
| 57 | { |
||
| 58 | $view->assign('contentObjectData', $this->configurationManager->getContentObject()->data); |
||
| 59 | if (is_object($GLOBALS['TSFE'])) { |
||
| 60 | $view->assign('pageData', $GLOBALS['TSFE']->page); |
||
| 61 | } |
||
| 62 | parent::initializeView($view); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Initializes the current action |
||
| 67 | */ |
||
| 68 | public function initializeAction() |
||
| 69 | { |
||
| 70 | $typoScriptFrontendController = $this->getTypoScriptFrontendController(); |
||
| 71 | if ($typoScriptFrontendController !== null) { |
||
| 72 | static $cacheTagsSet = false; |
||
| 73 | |||
| 74 | if (!$cacheTagsSet) { |
||
| 75 | $typoScriptFrontendController->addCacheTags(['tx_sfeventmgt']); |
||
| 76 | $cacheTagsSet = true; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Creates an event demand object with the given settings |
||
| 83 | * |
||
| 84 | * @param array $settings The settings |
||
| 85 | * |
||
| 86 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
| 87 | */ |
||
| 88 | public function createEventDemandObjectFromSettings(array $settings) |
||
| 89 | { |
||
| 90 | /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */ |
||
| 91 | $demand = $this->objectManager->get(EventDemand::class); |
||
| 92 | $demand->setDisplayMode($settings['displayMode']); |
||
| 93 | $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
||
| 94 | $demand->setCategoryConjunction($settings['categoryConjunction']); |
||
| 95 | $demand->setCategory($settings['category']); |
||
| 96 | $demand->setIncludeSubcategories($settings['includeSubcategories']); |
||
| 97 | $demand->setTopEventRestriction((int)$settings['topEventRestriction']); |
||
| 98 | $demand->setOrderField($settings['orderField']); |
||
| 99 | $demand->setOrderFieldAllowed($settings['orderFieldAllowed']); |
||
| 100 | $demand->setOrderDirection($settings['orderDirection']); |
||
| 101 | $demand->setQueryLimit($settings['queryLimit']); |
||
| 102 | $demand->setLocation($settings['location']); |
||
| 103 | $demand->setOrganisator($settings['organisator']); |
||
| 104 | $demand->setSpeaker($settings['speaker']); |
||
| 105 | |||
| 106 | return $demand; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Creates a foreign record demand object with the given settings |
||
| 111 | * |
||
| 112 | * @param array $settings The settings |
||
| 113 | * |
||
| 114 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
||
| 115 | */ |
||
| 116 | public function createForeignRecordDemandObjectFromSettings(array $settings) |
||
| 117 | { |
||
| 118 | /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */ |
||
| 119 | $demand = $this->objectManager->get(ForeignRecordDemand::class); |
||
| 120 | $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
||
| 121 | $demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']); |
||
| 122 | |||
| 123 | return $demand; |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Creates a category demand object with the given settings |
||
| 128 | * |
||
| 129 | * @param array $settings The settings |
||
| 130 | * |
||
| 131 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
||
| 132 | */ |
||
| 133 | public function createCategoryDemandObjectFromSettings(array $settings) |
||
| 134 | { |
||
| 135 | /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */ |
||
| 136 | $demand = $this->objectManager->get(CategoryDemand::class); |
||
| 137 | 2 | $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
|
| 138 | $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']); |
||
| 139 | $demand->setCategories($settings['categoryMenu']['categories']); |
||
| 140 | 2 | $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']); |
|
| 141 | 2 | ||
| 142 | 2 | return $demand; |
|
| 143 | 2 | } |
|
| 144 | 2 | ||
| 145 | 2 | /** |
|
| 146 | 2 | * Hook into request processing and catch exceptions |
|
| 147 | 2 | * |
|
| 148 | 2 | * @param RequestInterface $request |
|
| 149 | 2 | * @param ResponseInterface $response |
|
| 150 | 2 | * @throws \Exception |
|
| 151 | 2 | */ |
|
| 152 | public function processRequest(RequestInterface $request, ResponseInterface $response) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Handle known exceptions |
||
| 163 | * |
||
| 164 | * @param \Exception $exception |
||
| 165 | * @throws \Exception |
||
| 166 | */ |
||
| 167 | private function handleKnownExceptionsElseThrowAgain(\Exception $exception) |
||
| 168 | { |
||
| 169 | $previousException = $exception->getPrevious(); |
||
| 170 | $actions = ['detailAction', 'registrationAction', 'icalDownloadAction']; |
||
| 171 | if (in_array($this->actionMethodName, $actions, true) |
||
| 172 | && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception |
||
| 173 | ) { |
||
| 174 | $this->handleEventNotFoundError($this->settings); |
||
| 175 | } else { |
||
| 176 | throw $exception; |
||
| 177 | 2 | } |
|
| 178 | } |
||
| 179 | |||
| 180 | 2 | /** |
|
| 181 | 2 | * Initialize list action and set format |
|
| 182 | 2 | * |
|
| 183 | 2 | * @return void |
|
| 184 | 2 | */ |
|
| 185 | 2 | public function initializeListAction() |
|
| 186 | { |
||
| 187 | if (isset($this->settings['list']['format'])) { |
||
| 188 | $this->request->setFormat($this->settings['list']['format']); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * List view |
||
| 194 | * |
||
| 195 | * @param array $overwriteDemand OverwriteDemand |
||
| 196 | 4 | * |
|
| 197 | * @return void |
||
| 198 | 4 | */ |
|
| 199 | 4 | public function listAction(array $overwriteDemand = []) |
|
| 200 | 4 | { |
|
| 201 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
||
| 202 | 4 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
|
| 203 | 4 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
| 204 | 2 | if ($this->isOverwriteDemand($overwriteDemand)) { |
|
| 205 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 206 | 4 | } |
|
| 207 | 4 | $events = $this->eventRepository->findDemanded($eventDemand); |
|
| 208 | 4 | $categories = $this->categoryRepository->findDemanded($categoryDemand); |
|
| 209 | $locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
||
| 210 | $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
||
| 211 | $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand); |
||
| 212 | |||
| 213 | $values = [ |
||
| 214 | 'events' => $events, |
||
| 215 | 'categories' => $categories, |
||
| 216 | 'locations' => $locations, |
||
| 217 | 'organisators' => $organisators, |
||
| 218 | 'speakers' => $speakers, |
||
| 219 | 'overwriteDemand' => $overwriteDemand, |
||
| 220 | 'eventDemand' => $eventDemand |
||
| 221 | ]; |
||
| 222 | |||
| 223 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
||
| 224 | $this->view->assignMultiple($values); |
||
| 225 | |||
| 226 | $this->eventCacheService->addPageCacheTagsByEventDemandObject($eventDemand); |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | 6 | * Calendar view |
|
| 231 | * |
||
| 232 | 6 | * @param array $overwriteDemand OverwriteDemand |
|
| 233 | 6 | * |
|
| 234 | 6 | * @return void |
|
| 235 | 6 | */ |
|
| 236 | 2 | public function calendarAction(array $overwriteDemand = []) |
|
| 237 | 2 | { |
|
| 238 | 6 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
|
| 239 | 6 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
|
| 240 | 6 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
| 241 | 6 | if ($this->isOverwriteDemand($overwriteDemand)) { |
|
| 242 | 6 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
|
| 243 | 6 | } |
|
| 244 | 6 | ||
| 245 | 6 | // Set month/year to demand if not given |
|
| 246 | if (!$eventDemand->getMonth()) { |
||
| 247 | $currentMonth = date('n'); |
||
| 248 | $eventDemand->setMonth($currentMonth); |
||
| 249 | } else { |
||
| 250 | $currentMonth = $eventDemand->getMonth(); |
||
| 251 | } |
||
| 252 | if (!$eventDemand->getYear()) { |
||
| 253 | $currentYear = date('Y'); |
||
| 254 | 2 | $eventDemand->setYear($currentYear); |
|
| 255 | } else { |
||
| 256 | 2 | $currentYear = $eventDemand->getYear(); |
|
| 257 | 2 | } |
|
| 258 | |||
| 259 | // Set demand from calendar date range instead of month / year |
||
| 260 | if ((bool)$this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks']) { |
||
| 261 | $eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand); |
||
| 262 | } |
||
| 263 | |||
| 264 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 265 | $weeks = $this->calendarService->getCalendarArray( |
||
| 266 | 2 | $currentMonth, |
|
| 267 | $currentYear, |
||
| 268 | 2 | strtotime('today midnight'), |
|
| 269 | 2 | (int)$this->settings['calendar']['firstDayOfWeek'], |
|
| 270 | $events |
||
| 271 | ); |
||
| 272 | |||
| 273 | $values = [ |
||
| 274 | 'weeks' => $weeks, |
||
| 275 | 'categories' => $this->categoryRepository->findDemanded($categoryDemand), |
||
| 276 | 'locations' => $this->locationRepository->findDemanded($foreignRecordDemand), |
||
| 277 | 'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand), |
||
| 278 | 'eventDemand' => $eventDemand, |
||
| 279 | 2 | 'overwriteDemand' => $overwriteDemand, |
|
| 280 | 'currentPageId' => $GLOBALS['TSFE']->id, |
||
| 281 | 2 | 'firstDayOfMonth' => \DateTime::createFromFormat('d.m.Y', sprintf('1.%s.%s', $currentMonth, $currentYear)), |
|
| 282 | 'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'), |
||
| 283 | 'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month') |
||
| 284 | 2 | ]; |
|
| 285 | |||
| 286 | 2 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 287 | 2 | $this->view->assignMultiple($values); |
|
| 288 | 2 | } |
|
| 289 | |||
| 290 | /** |
||
| 291 | * Changes the given event demand object to select a date range for a calendar month including days of the previous |
||
| 292 | * month for the first week and they days for the next month for the last week |
||
| 293 | * |
||
| 294 | * @param EventDemand $eventDemand |
||
| 295 | 2 | * @return EventDemand |
|
| 296 | */ |
||
| 297 | 2 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
|
| 298 | 2 | { |
|
| 299 | 2 | $calendarDateRange = $this->calendarService->getCalendarDateRange( |
|
| 300 | 2 | $eventDemand->getMonth(), |
|
| 301 | 2 | $eventDemand->getYear(), |
|
| 302 | 2 | $this->settings['calendar']['firstDayOfWeek'] |
|
| 303 | 2 | ); |
|
| 304 | 2 | ||
| 305 | $eventDemand->setMonth(0); |
||
| 306 | $eventDemand->setYear(0); |
||
| 307 | |||
| 308 | $startDate = new \DateTime(); |
||
| 309 | $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']); |
||
| 310 | $endDate = new \DateTime(); |
||
| 311 | $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']); |
||
| 312 | $endDate->setTime(23, 59, 59); |
||
| 313 | |||
| 314 | $searchDemand = new SearchDemand(); |
||
| 315 | 22 | $searchDemand->setStartDate($startDate); |
|
| 316 | $searchDemand->setEndDate($endDate); |
||
| 317 | 22 | $eventDemand->setSearchDemand($searchDemand); |
|
| 318 | 22 | ||
| 319 | 22 | return $eventDemand; |
|
| 320 | } |
||
| 321 | |||
| 322 | 22 | /** |
|
| 323 | 8 | * Detail view for an event |
|
| 324 | 8 | * |
|
| 325 | 8 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
| 326 | 8 | * @return mixed string|void |
|
| 327 | 8 | */ |
|
| 328 | 8 | public function detailAction(Event $event = null) |
|
| 329 | { |
||
| 330 | 8 | $event = $this->evaluateSingleEventSetting($event); |
|
| 331 | 8 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
|
| 332 | 8 | $event = $this->checkPidOfEventRecord($event); |
|
|
|
|||
| 333 | 8 | } |
|
| 334 | |||
| 335 | 8 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 336 | 8 | return $this->handleEventNotFoundError($this->settings); |
|
| 337 | 8 | } |
|
| 338 | 8 | $values = ['event' => $event]; |
|
| 339 | 8 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 340 | 8 | $this->view->assignMultiple($values); |
|
| 341 | 8 | if ($event !== null) { |
|
| 342 | 8 | $this->eventCacheService->addCacheTagsByEventRecords([$event]); |
|
| 343 | } |
||
| 344 | } |
||
| 345 | 8 | ||
| 346 | /** |
||
| 347 | * Error handling if event is not found |
||
| 348 | 8 | * |
|
| 349 | 2 | * @param array $settings |
|
| 350 | 2 | * @return string |
|
| 351 | 2 | */ |
|
| 352 | 6 | protected function handleEventNotFoundError($settings) |
|
| 381 | |||
| 382 | 22 | /** |
|
| 383 | 2 | * Initiates the iCalendar download for the given event |
|
| 384 | 2 | * |
|
| 385 | 2 | * @param Event $event The event |
|
| 386 | 2 | * |
|
| 387 | * @return string|false |
||
| 388 | 2 | */ |
|
| 389 | 2 | public function icalDownloadAction(Event $event = null) |
|
| 390 | 2 | { |
|
| 391 | 2 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
|
| 392 | 2 | $event = $this->checkPidOfEventRecord($event); |
|
| 393 | 20 | } |
|
| 394 | 20 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 395 | 20 | return $this->handleEventNotFoundError($this->settings); |
|
| 396 | 20 | } |
|
| 397 | 20 | $this->icalendarService->downloadiCalendarFile($event); |
|
| 398 | 20 | exit(); |
|
| 399 | } |
||
| 400 | 22 | ||
| 401 | /** |
||
| 402 | * Registration view for an event |
||
| 403 | * |
||
| 404 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 405 | * |
||
| 406 | * @return mixed string|void |
||
| 407 | */ |
||
| 408 | public function registrationAction(Event $event = null) |
||
| 409 | 18 | { |
|
| 410 | $event = $this->evaluateSingleEventSetting($event); |
||
| 411 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
||
| 412 | 18 | $event = $this->checkPidOfEventRecord($event); |
|
| 413 | 2 | } |
|
| 414 | 2 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 415 | 2 | return $this->handleEventNotFoundError($this->settings); |
|
| 416 | 16 | } |
|
| 417 | if ($event->getRestrictPaymentMethods()) { |
||
| 418 | $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event); |
||
| 419 | } else { |
||
| 420 | 16 | $paymentMethods = $this->paymentService->getPaymentMethods(); |
|
| 421 | 2 | } |
|
| 422 | 2 | ||
| 423 | 2 | $values = [ |
|
| 424 | 14 | 'event' => $event, |
|
| 425 | 2 | 'paymentMethods' => $paymentMethods, |
|
| 426 | 2 | ]; |
|
| 427 | 2 | ||
| 428 | 12 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 429 | 2 | $this->view->assignMultiple($values); |
|
| 430 | 2 | } |
|
| 431 | 2 | ||
| 432 | 10 | /** |
|
| 433 | 2 | * Processes incoming registrations fields and adds field values to arguments |
|
| 434 | 2 | * |
|
| 435 | 2 | * @return void |
|
| 436 | 8 | */ |
|
| 437 | 2 | protected function setRegistrationFieldValuesToArguments() |
|
| 438 | 2 | { |
|
| 439 | 2 | $arguments = $this->request->getArguments(); |
|
| 440 | 6 | if (!isset($arguments['registration']['fields']) || !isset($arguments['event'])) { |
|
| 441 | 2 | return; |
|
| 442 | 2 | } |
|
| 443 | 2 | ||
| 444 | 4 | $registrationMvcArgument = $this->arguments->getArgument('registration'); |
|
| 445 | 2 | $propertyMapping = $registrationMvcArgument->getPropertyMappingConfiguration(); |
|
| 446 | 2 | $propertyMapping->allowProperties('fieldValues'); |
|
| 447 | 2 | $propertyMapping->allowCreationForSubProperty('fieldValues'); |
|
| 448 | 2 | $propertyMapping->allowModificationForSubProperty('fieldValues'); |
|
| 449 | 2 | ||
| 450 | 2 | // allow creation of new objects (for validation) |
|
| 451 | 2 | $propertyMapping->setTypeConverterOptions( |
|
| 452 | PersistentObjectConverter::class, |
||
| 453 | 18 | [ |
|
| 454 | 18 | PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true, |
|
| 455 | 18 | PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => true |
|
| 456 | ] |
||
| 457 | ); |
||
| 458 | |||
| 459 | // Set event to registration (required for validation) |
||
| 460 | $event = $this->eventRepository->findByUid((int)$this->request->getArgument('event')); |
||
| 461 | $propertyMapping->allowProperties('event'); |
||
| 462 | $propertyMapping->allowCreationForSubProperty('event'); |
||
| 463 | $propertyMapping->allowModificationForSubProperty('event'); |
||
| 464 | $arguments['registration']['event'] = (int)$this->request->getArgument('event'); |
||
| 465 | 6 | ||
| 466 | $index = 0; |
||
| 467 | foreach ((array)$arguments['registration']['fields'] as $fieldUid => $value) { |
||
| 468 | 6 | // Only accept registration fields of the current event |
|
| 469 | if (!in_array((int)$fieldUid, $event->getRegistrationFieldsUids(), true)) { |
||
| 470 | 6 | continue; |
|
| 471 | 4 | } |
|
| 472 | 4 | ||
| 473 | // allow subvalues in new property mapper |
||
| 474 | 4 | $propertyMapping->forProperty('fieldValues')->allowProperties($index); |
|
| 475 | 4 | $propertyMapping->forProperty('fieldValues.' . $index)->allowAllProperties(); |
|
| 476 | 2 | $propertyMapping->allowCreationForSubProperty('fieldValues.' . $index); |
|
| 477 | 2 | $propertyMapping->allowModificationForSubProperty('fieldValues.' . $index); |
|
| 478 | |||
| 479 | if (is_array($value)) { |
||
| 480 | 4 | if (empty($value)) { |
|
| 481 | 4 | $value = ''; |
|
| 482 | 4 | } else { |
|
| 483 | 4 | $value = json_encode($value); |
|
| 484 | } |
||
| 485 | 4 | } |
|
| 486 | 4 | ||
| 487 | 4 | /** @var Registration\Field $field */ |
|
| 488 | 4 | $field = $this->fieldRepository->findByUid((int)$fieldUid); |
|
| 489 | 4 | ||
| 490 | $arguments['registration']['fieldValues'][$index] = [ |
||
| 491 | 4 | 'pid' => $field->getPid(), |
|
| 492 | 'value' => $value, |
||
| 493 | 'field' => strval($fieldUid), |
||
| 494 | 4 | 'valueType' => $field->getValueType() |
|
| 495 | 4 | ]; |
|
| 496 | 4 | ||
| 497 | 4 | $index++; |
|
| 498 | } |
||
| 499 | |||
| 500 | 6 | // Remove temporary "fields" field |
|
| 501 | 6 | $arguments = ArrayUtility::removeByPath($arguments, 'registration/fields'); |
|
| 502 | $this->request->setArguments($arguments); |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Set date format for field dateOfBirth |
||
| 507 | * |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | public function initializeSaveRegistrationAction() |
||
| 511 | { |
||
| 512 | $this->arguments->getArgument('registration') |
||
| 513 | ->getPropertyMappingConfiguration()->forProperty('dateOfBirth') |
||
| 514 | ->setTypeConverterOption( |
||
| 515 | DateTimeConverter::class, |
||
| 516 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 517 | $this->settings['registration']['formatDateOfBirth'] |
||
| 518 | 6 | ); |
|
| 519 | 6 | $this->setRegistrationFieldValuesToArguments(); |
|
| 520 | 6 | } |
|
| 521 | |||
| 522 | /** |
||
| 523 | * Saves the registration |
||
| 524 | * |
||
| 525 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 526 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 527 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationFieldValidator |
||
| 528 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
||
| 529 | * |
||
| 530 | 4 | * @return mixed string|void |
|
| 531 | */ |
||
| 532 | public function saveRegistrationAction(Registration $registration, Event $event) |
||
| 533 | 4 | { |
|
| 534 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
||
| 535 | 4 | $event = $this->checkPidOfEventRecord($event); |
|
| 536 | } |
||
| 537 | 2 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 538 | 2 | return $this->handleEventNotFoundError($this->settings); |
|
| 539 | 2 | } |
|
| 540 | 2 | $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm(); |
|
| 541 | $result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
||
| 542 | 2 | list($success, $result) = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
|
| 543 | 2 | ||
| 544 | 2 | // Save registration if no errors |
|
| 545 | 2 | if ($success) { |
|
| 546 | 2 | $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
|
| 547 | $event, |
||
| 548 | 2 | $registration->getAmountOfRegistrations() |
|
| 549 | ); |
||
| 550 | $linkValidity = (int)$this->settings['confirmation']['linkValidity']; |
||
| 551 | 2 | if ($linkValidity === 0) { |
|
| 552 | 2 | // Use 3600 seconds as default value if not set |
|
| 553 | 2 | $linkValidity = 3600; |
|
| 554 | } |
||
| 555 | $confirmationUntil = new \DateTime(); |
||
| 556 | 2 | $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); |
|
| 557 | |||
| 558 | $registration->setEvent($event); |
||
| 559 | 2 | $registration->setPid($event->getPid()); |
|
| 560 | 2 | $registration->setConfirmationUntil($confirmationUntil); |
|
| 561 | 4 | $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); |
|
| 562 | 4 | $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
|
| 563 | 4 | $registration->setWaitlist($isWaitlistRegistration); |
|
| 564 | $registration->_setProperty('_languageUid', $this->getSysLanguageUid()); |
||
| 565 | $this->registrationRepository->add($registration); |
||
| 566 | |||
| 567 | // Persist registration, so we have an UID |
||
| 568 | $this->objectManager->get(PersistenceManager::class)->persistAll(); |
||
| 569 | |||
| 570 | 2 | if ($isWaitlistRegistration) { |
|
| 571 | $messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
||
| 572 | 2 | } else { |
|
| 573 | 2 | $messageType = MessageType::REGISTRATION_NEW; |
|
| 574 | 2 | } |
|
| 575 | 2 | ||
| 576 | 2 | // Fix event in registration for language other than default language |
|
| 577 | 2 | $this->registrationService->fixRegistrationEvent($registration, $event); |
|
| 578 | 2 | ||
| 579 | 2 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'AfterRegistrationSaved', [$registration, $this]); |
|
| 580 | 2 | ||
| 581 | 2 | // Send notifications to user and admin if confirmation link should be sent |
|
| 582 | 2 | if (!$autoConfirmation) { |
|
| 583 | 2 | $this->notificationService->sendUserMessage( |
|
| 584 | 2 | $event, |
|
| 585 | 2 | $registration, |
|
| 586 | 2 | $this->settings, |
|
| 587 | 2 | $messageType |
|
| 588 | 2 | ); |
|
| 589 | $this->notificationService->sendAdminMessage( |
||
| 590 | $event, |
||
| 591 | $registration, |
||
| 592 | $this->settings, |
||
| 593 | $messageType |
||
| 594 | ); |
||
| 595 | } |
||
| 596 | |||
| 597 | // Create given amount of registrations if necessary |
||
| 598 | 12 | if ($registration->getAmountOfRegistrations() > 1) { |
|
| 599 | $this->registrationService->createDependingRegistrations($registration); |
||
| 600 | 12 | } |
|
| 601 | 12 | ||
| 602 | 12 | // Flush page cache for event, since new registration has been added |
|
| 603 | 12 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
|
| 604 | } |
||
| 605 | 12 | ||
| 606 | 10 | if ($autoConfirmation && $success) { |
|
| 607 | $this->redirect( |
||
| 608 | 10 | 'confirmRegistration', |
|
| 609 | 2 | null, |
|
| 610 | 2 | null, |
|
| 611 | [ |
||
| 612 | 10 | 'reguid' => $registration->getUid(), |
|
| 613 | 2 | 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()) |
|
| 614 | 2 | ] |
|
| 615 | 10 | ); |
|
| 616 | } else { |
||
| 617 | 12 | $this->redirect( |
|
| 618 | 2 | 'saveRegistrationResult', |
|
| 619 | 2 | null, |
|
| 620 | null, |
||
| 621 | 12 | [ |
|
| 622 | 12 | 'result' => $result, |
|
| 623 | 'eventuid' => $event->getUid(), |
||
| 624 | 12 | 'hmac' => $this->hashService->generateHmac('event-' . $event->getUid()) |
|
| 625 | ] |
||
| 626 | 12 | ); |
|
| 627 | 12 | } |
|
| 628 | 12 | } |
|
| 629 | 12 | ||
| 630 | 12 | /** |
|
| 631 | 12 | * Shows the result of the saveRegistrationAction |
|
| 632 | * |
||
| 633 | * @param int $result Result |
||
| 634 | * @param int $eventuid |
||
| 635 | * @param string $hmac |
||
| 636 | * |
||
| 637 | * @return void |
||
| 638 | */ |
||
| 639 | 18 | public function saveRegistrationResultAction($result, $eventuid, $hmac) |
|
| 640 | { |
||
| 641 | 18 | $event = null; |
|
| 642 | |||
| 643 | switch ($result) { |
||
| 644 | case RegistrationResult::REGISTRATION_SUCCESSFUL: |
||
| 645 | $messageKey = 'event.message.registrationsuccessful'; |
||
| 646 | $titleKey = 'registrationResult.title.successful'; |
||
| 647 | break; |
||
| 648 | case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST: |
||
| 649 | $messageKey = 'event.message.registrationwaitlistsuccessful'; |
||
| 650 | $titleKey = 'registrationWaitlistResult.title.successful'; |
||
| 651 | break; |
||
| 652 | case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED: |
||
| 653 | $messageKey = 'event.message.registrationfailedeventexpired'; |
||
| 654 | $titleKey = 'registrationResult.title.failed'; |
||
| 655 | break; |
||
| 656 | case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS: |
||
| 657 | $messageKey = 'event.message.registrationfailedmaxparticipants'; |
||
| 658 | $titleKey = 'registrationResult.title.failed'; |
||
| 659 | break; |
||
| 660 | case RegistrationResult::REGISTRATION_NOT_ENABLED: |
||
| 661 | $messageKey = 'event.message.registrationfailednotenabled'; |
||
| 662 | $titleKey = 'registrationResult.title.failed'; |
||
| 663 | break; |
||
| 664 | case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED: |
||
| 665 | $messageKey = 'event.message.registrationfaileddeadlineexpired'; |
||
| 666 | $titleKey = 'registrationResult.title.failed'; |
||
| 667 | break; |
||
| 668 | case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES: |
||
| 669 | $messageKey = 'event.message.registrationfailednotenoughfreeplaces'; |
||
| 670 | $titleKey = 'registrationResult.title.failed'; |
||
| 671 | break; |
||
| 672 | case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED: |
||
| 673 | $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded'; |
||
| 674 | $titleKey = 'registrationResult.title.failed'; |
||
| 675 | break; |
||
| 676 | case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE: |
||
| 677 | $messageKey = 'event.message.registrationfailedemailnotunique'; |
||
| 678 | $titleKey = 'registrationResult.title.failed'; |
||
| 679 | break; |
||
| 680 | default: |
||
| 681 | $messageKey = ''; |
||
| 682 | $titleKey = ''; |
||
| 683 | } |
||
| 684 | |||
| 685 | if (!$this->hashService->validateHmac('event-' . $eventuid, $hmac)) { |
||
| 686 | $messageKey = 'event.message.registrationsuccessfulwrongeventhmac'; |
||
| 687 | $titleKey = 'registrationResult.title.failed'; |
||
| 688 | } else { |
||
| 689 | $event = $this->eventRepository->findByUid((int)$eventuid); |
||
| 690 | } |
||
| 691 | |||
| 692 | $this->view->assignMultiple([ |
||
| 693 | 'messageKey' => $messageKey, |
||
| 694 | 'titleKey' => $titleKey, |
||
| 695 | 'event' => $event, |
||
| 696 | ]); |
||
| 697 | } |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Confirms the registration if possible and sends e-mails to admin and user |
||
| 701 | * |
||
| 702 | * @param int $reguid UID of registration |
||
| 703 | * @param string $hmac HMAC for parameters |
||
| 704 | * |
||
| 705 | * @return void |
||
| 706 | */ |
||
| 707 | public function confirmRegistrationAction($reguid, $hmac) |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Cancels the registration if possible and sends e-mails to admin and user |
||
| 781 | * |
||
| 782 | * @param int $reguid UID of registration |
||
| 783 | * @param string $hmac HMAC for parameters |
||
| 784 | * |
||
| 785 | * @return void |
||
| 786 | */ |
||
| 787 | public function cancelRegistrationAction($reguid, $hmac) |
||
| 835 | |||
| 836 | /** |
||
| 837 | * Set date format for field startDate and endDate |
||
| 838 | * |
||
| 839 | * @return void |
||
| 840 | */ |
||
| 841 | public function initializeSearchAction() |
||
| 870 | |||
| 871 | /** |
||
| 872 | * Search view |
||
| 873 | * |
||
| 874 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
| 875 | * @param array $overwriteDemand OverwriteDemand |
||
| 876 | * |
||
| 877 | * @return void |
||
| 878 | */ |
||
| 879 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
| 924 | * |
||
| 925 | * @param array $overwriteDemand |
||
| 926 | * @return bool |
||
| 927 | */ |
||
| 928 | protected function isOverwriteDemand($overwriteDemand) |
||
| 932 | |||
| 933 | /** |
||
| 934 | * If no event is given and the singleEvent setting is set, the configured single event is returned |
||
| 935 | * |
||
| 936 | * @param Event|null $event |
||
| 937 | * @return Event|null |
||
| 938 | */ |
||
| 939 | protected function evaluateSingleEventSetting($event) |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Checks if the event pid could be found in the storagePage settings of the detail plugin and |
||
| 950 | * if the pid could not be found it return null instead of the event object. |
||
| 951 | * |
||
| 952 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
| 953 | * @return null|\DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 954 | */ |
||
| 955 | protected function checkPidOfEventRecord(Event $event) |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Returns the current sys_language_uid |
||
| 982 | * |
||
| 983 | * @return int |
||
| 984 | */ |
||
| 985 | protected function getSysLanguageUid() |
||
| 989 | } |
||
| 990 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: