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 | 1 | $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
|
| 138 | $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']); |
||
| 139 | $demand->setCategories($settings['categoryMenu']['categories']); |
||
| 140 | 1 | $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']); |
|
| 141 | 1 | ||
| 142 | 1 | return $demand; |
|
| 143 | 1 | } |
|
| 144 | 1 | ||
| 145 | 1 | /** |
|
| 146 | 1 | * Hook into request processing and catch exceptions |
|
| 147 | 1 | * |
|
| 148 | 1 | * @param RequestInterface $request |
|
| 149 | 1 | * @param ResponseInterface $response |
|
| 150 | 1 | * @throws \Exception |
|
| 151 | */ |
||
| 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) |
||
| 179 | 1 | ||
| 180 | 1 | /** |
|
| 181 | 1 | * Initialize list action and set format |
|
| 182 | 1 | * |
|
| 183 | 1 | * @return void |
|
| 184 | 1 | */ |
|
| 185 | public function initializeListAction() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * List view |
||
| 194 | * |
||
| 195 | 2 | * @param array $overwriteDemand OverwriteDemand |
|
| 196 | * |
||
| 197 | 2 | * @return void |
|
| 198 | 2 | */ |
|
| 199 | 2 | public function listAction(array $overwriteDemand = []) |
|
| 200 | { |
||
| 201 | 2 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
|
| 202 | 2 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
|
| 203 | 2 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
| 204 | 2 | if ($this->isOverwriteDemand($overwriteDemand)) { |
|
| 205 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 206 | } |
||
| 207 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 208 | $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 | 3 | $this->eventCacheService->addPageCacheTagsByEventDemandObject($eventDemand); |
|
| 227 | } |
||
| 228 | 3 | ||
| 229 | 3 | /** |
|
| 230 | 3 | * Calendar view |
|
| 231 | 3 | * |
|
| 232 | 1 | * @param array $overwriteDemand OverwriteDemand |
|
| 233 | 1 | * |
|
| 234 | 3 | * @return void |
|
| 235 | 3 | */ |
|
| 236 | 3 | public function calendarAction(array $overwriteDemand = []) |
|
| 237 | 3 | { |
|
| 238 | 3 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
|
| 239 | 3 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
|
| 240 | 3 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
| 241 | 3 | if ($this->isOverwriteDemand($overwriteDemand)) { |
|
| 242 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 243 | } |
||
| 244 | |||
| 245 | // Set month/year to demand if not given |
||
| 246 | if (!$eventDemand->getMonth()) { |
||
| 247 | $currentMonth = date('n'); |
||
| 248 | $eventDemand->setMonth($currentMonth); |
||
| 249 | } else { |
||
| 250 | 1 | $currentMonth = $eventDemand->getMonth(); |
|
| 251 | } |
||
| 252 | 1 | if (!$eventDemand->getYear()) { |
|
| 253 | 1 | $currentYear = date('Y'); |
|
| 254 | $eventDemand->setYear($currentYear); |
||
| 255 | } else { |
||
| 256 | $currentYear = $eventDemand->getYear(); |
||
| 257 | } |
||
| 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 | 1 | } |
|
| 263 | |||
| 264 | 1 | $events = $this->eventRepository->findDemanded($eventDemand); |
|
| 265 | 1 | $weeks = $this->calendarService->getCalendarArray( |
|
| 266 | $currentMonth, |
||
| 267 | $currentYear, |
||
| 268 | strtotime('today midnight'), |
||
| 269 | (int)$this->settings['calendar']['firstDayOfWeek'], |
||
| 270 | $events |
||
| 271 | ); |
||
| 272 | |||
| 273 | $values = [ |
||
| 274 | 'weeks' => $weeks, |
||
| 275 | 1 | 'categories' => $this->categoryRepository->findDemanded($categoryDemand), |
|
| 276 | 'locations' => $this->locationRepository->findDemanded($foreignRecordDemand), |
||
| 277 | 1 | 'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand), |
|
| 278 | 'eventDemand' => $eventDemand, |
||
| 279 | 'overwriteDemand' => $overwriteDemand, |
||
| 280 | 1 | 'currentPageId' => $GLOBALS['TSFE']->id, |
|
| 281 | 'firstDayOfMonth' => \DateTime::createFromFormat('d.m.Y', sprintf('1.%s.%s', $currentMonth, $currentYear)), |
||
| 282 | 1 | 'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'), |
|
| 283 | 1 | 'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month') |
|
| 284 | 1 | ]; |
|
| 285 | |||
| 286 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
||
| 287 | $this->view->assignMultiple($values); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | 1 | * 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 | 1 | * |
|
| 294 | 1 | * @param EventDemand $eventDemand |
|
| 295 | 1 | * @return EventDemand |
|
| 296 | 1 | */ |
|
| 297 | 1 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
|
| 298 | 1 | { |
|
| 299 | 1 | $calendarDateRange = $this->calendarService->getCalendarDateRange( |
|
| 300 | 1 | $eventDemand->getMonth(), |
|
| 301 | $eventDemand->getYear(), |
||
| 302 | $this->settings['calendar']['firstDayOfWeek'] |
||
| 303 | ); |
||
| 304 | |||
| 305 | $eventDemand->setMonth(0); |
||
| 306 | $eventDemand->setYear(0); |
||
| 307 | |||
| 308 | $startDate = new \DateTime(); |
||
| 309 | $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']); |
||
| 310 | $endDate = new \DateTime(); |
||
| 311 | 11 | $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']); |
|
| 312 | $endDate->setTime(23, 59, 59); |
||
| 313 | 11 | ||
| 314 | 11 | $searchDemand = new SearchDemand(); |
|
| 315 | 11 | $searchDemand->setStartDate($startDate); |
|
| 316 | $searchDemand->setEndDate($endDate); |
||
| 317 | $eventDemand->setSearchDemand($searchDemand); |
||
| 318 | 11 | ||
| 319 | 4 | return $eventDemand; |
|
| 320 | 4 | } |
|
| 321 | 4 | ||
| 322 | 4 | /** |
|
| 323 | 4 | * Detail view for an event |
|
| 324 | 4 | * |
|
| 325 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 326 | 4 | * @return mixed string|void |
|
| 327 | 4 | */ |
|
| 328 | 4 | public function detailAction(Event $event = null) |
|
| 329 | 4 | { |
|
| 330 | $event = $this->evaluateSingleEventSetting($event); |
||
| 331 | 4 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
|
| 332 | 4 | $event = $this->checkPidOfEventRecord($event); |
|
|
|
|||
| 333 | 4 | } |
|
| 334 | 4 | ||
| 335 | 4 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 336 | 4 | return $this->handleEventNotFoundError($this->settings); |
|
| 337 | 4 | } |
|
| 338 | 4 | $values = ['event' => $event]; |
|
| 339 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
||
| 340 | $this->view->assignMultiple($values); |
||
| 341 | 4 | if ($event !== null) { |
|
| 342 | $this->eventCacheService->addCacheTagsByEventRecords([$event]); |
||
| 343 | } |
||
| 344 | 4 | } |
|
| 345 | 1 | ||
| 346 | 1 | /** |
|
| 347 | 1 | * Error handling if event is not found |
|
| 348 | 3 | * |
|
| 349 | 3 | * @param array $settings |
|
| 350 | * @return string |
||
| 351 | 4 | */ |
|
| 352 | protected function handleEventNotFoundError($settings) |
||
| 353 | { |
||
| 354 | 4 | if (empty($settings['event']['errorHandling'])) { |
|
| 355 | 3 | return null; |
|
| 356 | 3 | } |
|
| 357 | 3 | ||
| 358 | 3 | $configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true); |
|
| 359 | |||
| 360 | 3 | switch ($configuration[0]) { |
|
| 361 | 3 | case 'redirectToListView': |
|
| 362 | 3 | $listPid = (int)$settings['listPid'] > 0 ? (int)$settings['listPid'] : 1; |
|
| 363 | 3 | $this->redirect('list', null, null, null, $listPid); |
|
| 364 | 3 | break; |
|
| 365 | case 'pageNotFoundHandler': |
||
| 366 | 3 | $GLOBALS['TSFE']->pageNotFoundAndExit('Event not found.'); |
|
| 367 | 3 | break; |
|
| 368 | case 'showStandaloneTemplate': |
||
| 369 | if (isset($configuration[2])) { |
||
| 370 | 4 | $statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $configuration[2]); |
|
| 371 | 1 | HttpUtility::setResponseCode($statusCode); |
|
| 372 | 1 | } |
|
| 373 | $standaloneTemplate = $this->objectManager->get(StandaloneView::class); |
||
| 374 | $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1])); |
||
| 375 | 4 | ||
| 376 | 4 | return $standaloneTemplate->render(); |
|
| 377 | break; |
||
| 378 | 11 | default: |
|
| 379 | 1 | } |
|
| 380 | 1 | } |
|
| 381 | 1 | ||
| 382 | 1 | /** |
|
| 383 | * Initiates the iCalendar download for the given event |
||
| 384 | 1 | * |
|
| 385 | 1 | * @param Event $event The event |
|
| 386 | 1 | * |
|
| 387 | 1 | * @return string|false |
|
| 388 | 1 | */ |
|
| 389 | 10 | public function icalDownloadAction(Event $event = null) |
|
| 390 | 10 | { |
|
| 391 | 10 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
|
| 392 | 10 | $event = $this->checkPidOfEventRecord($event); |
|
| 393 | 10 | } |
|
| 394 | 10 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 395 | return $this->handleEventNotFoundError($this->settings); |
||
| 396 | 11 | } |
|
| 397 | $this->icalendarService->downloadiCalendarFile($event); |
||
| 398 | exit(); |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Registration view for an event |
||
| 403 | * |
||
| 404 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 405 | 9 | * |
|
| 406 | * @return mixed string|void |
||
| 407 | */ |
||
| 408 | 9 | public function registrationAction(Event $event = null) |
|
| 409 | 1 | { |
|
| 410 | 1 | $event = $this->evaluateSingleEventSetting($event); |
|
| 411 | 1 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
|
| 412 | 8 | $event = $this->checkPidOfEventRecord($event); |
|
| 413 | } |
||
| 414 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 415 | return $this->handleEventNotFoundError($this->settings); |
||
| 416 | 8 | } |
|
| 417 | 1 | if ($event->getRestrictPaymentMethods()) { |
|
| 418 | 1 | $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event); |
|
| 419 | 1 | } else { |
|
| 420 | 7 | $paymentMethods = $this->paymentService->getPaymentMethods(); |
|
| 421 | 1 | } |
|
| 422 | 1 | ||
| 423 | 1 | $values = [ |
|
| 424 | 6 | 'event' => $event, |
|
| 425 | 1 | 'paymentMethods' => $paymentMethods, |
|
| 426 | 1 | ]; |
|
| 427 | 1 | ||
| 428 | 5 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 429 | 1 | $this->view->assignMultiple($values); |
|
| 430 | 1 | } |
|
| 431 | 1 | ||
| 432 | 4 | /** |
|
| 433 | 1 | * Processes incoming registrations fields and adds field values to arguments |
|
| 434 | 1 | * |
|
| 435 | 1 | * @return void |
|
| 436 | 3 | */ |
|
| 437 | 1 | protected function setRegistrationFieldValuesToArguments() |
|
| 438 | 1 | { |
|
| 439 | 1 | $arguments = $this->request->getArguments(); |
|
| 440 | 2 | if (!isset($arguments['registration']['fields']) || !isset($arguments['event'])) { |
|
| 441 | 1 | return; |
|
| 442 | 1 | } |
|
| 443 | 1 | ||
| 444 | 1 | $registrationMvcArgument = $this->arguments->getArgument('registration'); |
|
| 445 | 1 | $propertyMapping = $registrationMvcArgument->getPropertyMappingConfiguration(); |
|
| 446 | 1 | $propertyMapping->allowProperties('fieldValues'); |
|
| 447 | 1 | $propertyMapping->allowCreationForSubProperty('fieldValues'); |
|
| 448 | $propertyMapping->allowModificationForSubProperty('fieldValues'); |
||
| 449 | 9 | ||
| 450 | 9 | // allow creation of new objects (for validation) |
|
| 451 | 9 | $propertyMapping->setTypeConverterOptions( |
|
| 452 | PersistentObjectConverter::class, |
||
| 453 | [ |
||
| 454 | PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true, |
||
| 455 | 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 | 3 | $propertyMapping->allowProperties('event'); |
|
| 462 | $propertyMapping->allowCreationForSubProperty('event'); |
||
| 463 | $propertyMapping->allowModificationForSubProperty('event'); |
||
| 464 | 3 | $arguments['registration']['event'] = (int)$this->request->getArgument('event'); |
|
| 465 | |||
| 466 | 3 | $index = 0; |
|
| 467 | 2 | foreach ((array)$arguments['registration']['fields'] as $fieldUid => $value) { |
|
| 468 | 2 | // Only accept registration fields of the current event |
|
| 469 | if (!in_array((int)$fieldUid, $event->getRegistrationFieldsUids(), true)) { |
||
| 470 | 2 | continue; |
|
| 471 | 2 | } |
|
| 472 | 1 | ||
| 473 | 1 | // allow subvalues in new property mapper |
|
| 474 | $propertyMapping->forProperty('fieldValues')->allowProperties($index); |
||
| 475 | $propertyMapping->forProperty('fieldValues.' . $index)->allowAllProperties(); |
||
| 476 | 2 | $propertyMapping->allowCreationForSubProperty('fieldValues.' . $index); |
|
| 477 | 2 | $propertyMapping->allowModificationForSubProperty('fieldValues.' . $index); |
|
| 478 | 2 | ||
| 479 | 2 | if (is_array($value)) { |
|
| 480 | if (empty($value)) { |
||
| 481 | 2 | $value = ''; |
|
| 482 | 2 | } else { |
|
| 483 | 2 | $value = json_encode($value); |
|
| 484 | 2 | } |
|
| 485 | 2 | } |
|
| 486 | |||
| 487 | 2 | /** @var Registration\Field $field */ |
|
| 488 | $field = $this->fieldRepository->findByUid((int)$fieldUid); |
||
| 489 | |||
| 490 | 2 | $arguments['registration']['fieldValues'][$index] = [ |
|
| 491 | 2 | 'pid' => $field->getPid(), |
|
| 492 | 2 | 'value' => $value, |
|
| 493 | 2 | 'field' => strval($fieldUid), |
|
| 494 | 'valueType' => $field->getValueType() |
||
| 495 | ]; |
||
| 496 | 3 | ||
| 497 | 3 | $index++; |
|
| 498 | } |
||
| 499 | |||
| 500 | // Remove temporary "fields" field |
||
| 501 | $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 | 3 | ->setTypeConverterOption( |
|
| 515 | 3 | DateTimeConverter::class, |
|
| 516 | 3 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
|
| 517 | $this->settings['registration']['formatDateOfBirth'] |
||
| 518 | ); |
||
| 519 | $this->setRegistrationFieldValuesToArguments(); |
||
| 520 | } |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Saves the registration |
||
| 524 | * |
||
| 525 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 526 | 2 | * @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 | 2 | * |
|
| 530 | * @return mixed string|void |
||
| 531 | 2 | */ |
|
| 532 | public function saveRegistrationAction(Registration $registration, Event $event) |
||
| 533 | 1 | { |
|
| 534 | 1 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
|
| 535 | 1 | $event = $this->checkPidOfEventRecord($event); |
|
| 536 | 1 | } |
|
| 537 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 538 | 1 | return $this->handleEventNotFoundError($this->settings); |
|
| 539 | 1 | } |
|
| 540 | 1 | $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm(); |
|
| 541 | 1 | $result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
|
| 542 | 1 | list($success, $result) = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
|
| 543 | |||
| 544 | 1 | // Save registration if no errors |
|
| 545 | if ($success) { |
||
| 546 | $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
||
| 547 | 1 | $event, |
|
| 548 | 1 | $registration->getAmountOfRegistrations() |
|
| 549 | 1 | ); |
|
| 550 | $linkValidity = (int)$this->settings['confirmation']['linkValidity']; |
||
| 551 | if ($linkValidity === 0) { |
||
| 552 | 1 | // Use 3600 seconds as default value if not set |
|
| 553 | $linkValidity = 3600; |
||
| 554 | } |
||
| 555 | 1 | $confirmationUntil = new \DateTime(); |
|
| 556 | 1 | $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); |
|
| 557 | 2 | ||
| 558 | 2 | $registration->setEvent($event); |
|
| 559 | 2 | $registration->setPid($event->getPid()); |
|
| 560 | $registration->setConfirmationUntil($confirmationUntil); |
||
| 561 | $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); |
||
| 562 | $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
||
| 563 | $registration->setWaitlist($isWaitlistRegistration); |
||
| 564 | $registration->_setProperty('_languageUid', $this->getSysLanguageUid()); |
||
| 565 | $this->registrationRepository->add($registration); |
||
| 566 | 1 | ||
| 567 | // Persist registration, so we have an UID |
||
| 568 | 1 | $this->objectManager->get(PersistenceManager::class)->persistAll(); |
|
| 569 | 1 | ||
| 570 | 1 | if ($isWaitlistRegistration) { |
|
| 571 | 1 | $messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
|
| 572 | 1 | } else { |
|
| 573 | 1 | $messageType = MessageType::REGISTRATION_NEW; |
|
| 574 | 1 | } |
|
| 575 | 1 | ||
| 576 | 1 | // Fix event in registration for language other than default language |
|
| 577 | 1 | $this->registrationService->fixRegistrationEvent($registration, $event); |
|
| 578 | 1 | ||
| 579 | 1 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'AfterRegistrationSaved', [$registration, $this]); |
|
| 580 | 1 | ||
| 581 | 1 | // Send notifications to user and admin if confirmation link should be sent |
|
| 582 | 1 | if (!$autoConfirmation) { |
|
| 583 | 1 | $this->notificationService->sendUserMessage( |
|
| 584 | 1 | $event, |
|
| 585 | $registration, |
||
| 586 | $this->settings, |
||
| 587 | $messageType |
||
| 588 | ); |
||
| 589 | $this->notificationService->sendAdminMessage( |
||
| 590 | $event, |
||
| 591 | $registration, |
||
| 592 | $this->settings, |
||
| 593 | $messageType |
||
| 594 | 6 | ); |
|
| 595 | } |
||
| 596 | 6 | ||
| 597 | 6 | // Create given amount of registrations if necessary |
|
| 598 | 6 | if ($registration->getAmountOfRegistrations() > 1) { |
|
| 599 | 6 | $this->registrationService->createDependingRegistrations($registration); |
|
| 600 | } |
||
| 601 | 6 | ||
| 602 | 5 | // Flush page cache for event, since new registration has been added |
|
| 603 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
||
| 604 | 5 | } |
|
| 605 | 1 | ||
| 606 | 1 | if ($autoConfirmation && $success) { |
|
| 607 | $this->redirect( |
||
| 608 | 5 | 'confirmRegistration', |
|
| 609 | 1 | null, |
|
| 610 | 1 | null, |
|
| 611 | 5 | [ |
|
| 612 | 'reguid' => $registration->getUid(), |
||
| 613 | 6 | 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()) |
|
| 614 | 1 | ] |
|
| 615 | 1 | ); |
|
| 616 | } else { |
||
| 617 | 6 | $this->redirect( |
|
| 618 | 6 | 'saveRegistrationResult', |
|
| 619 | null, |
||
| 620 | 6 | null, |
|
| 621 | [ |
||
| 622 | 6 | 'result' => $result, |
|
| 623 | 6 | 'eventuid' => $event->getUid(), |
|
| 624 | 6 | 'hmac' => $this->hashService->generateHmac('event-' . $event->getUid()) |
|
| 625 | 6 | ] |
|
| 626 | 6 | ); |
|
| 627 | 6 | } |
|
| 628 | } |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Shows the result of the saveRegistrationAction |
||
| 632 | * |
||
| 633 | * @param int $result Result |
||
| 634 | * @param int $eventuid |
||
| 635 | 9 | * @param string $hmac |
|
| 636 | * |
||
| 637 | 9 | * @return void |
|
| 638 | */ |
||
| 639 | public function saveRegistrationResultAction($result, $eventuid, $hmac) |
||
| 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) |
||
| 708 | { |
||
| 709 | $event = null; |
||
| 710 | |||
| 711 | /* @var $registration Registration */ |
||
| 712 | list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration( |
||
| 713 | $reguid, |
||
| 714 | $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: