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 |
||
| 35 | class EventController extends AbstractController |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * Assign contentObjectData and pageData to earch view |
||
| 39 | * |
||
| 40 | * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view |
||
| 41 | */ |
||
| 42 | protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Properties in this array will be ignored by overwriteDemandObject() |
||
| 53 | * |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | protected $ignoredSettingsForOverwriteDemand = ['storagepage', 'orderfieldallowed']; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Initializes the current action |
||
| 60 | */ |
||
| 61 | public function initializeAction() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Creates an event demand object with the given settings |
||
| 76 | * |
||
| 77 | * @param array $settings The settings |
||
| 78 | * |
||
| 79 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
| 80 | */ |
||
| 81 | public function createEventDemandObjectFromSettings(array $settings) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Creates a foreign record demand object with the given settings |
||
| 103 | * |
||
| 104 | * @param array $settings The settings |
||
| 105 | * |
||
| 106 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
||
| 107 | */ |
||
| 108 | public function createForeignRecordDemandObjectFromSettings(array $settings) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Creates a category demand object with the given settings |
||
| 120 | * |
||
| 121 | * @param array $settings The settings |
||
| 122 | * |
||
| 123 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
||
| 124 | */ |
||
| 125 | public function createCategoryDemandObjectFromSettings(array $settings) |
||
| 136 | |||
| 137 | 2 | /** |
|
| 138 | * Overwrites a given demand object by an propertyName => $propertyValue array |
||
| 139 | * |
||
| 140 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand |
|
| 141 | 2 | * @param array $overwriteDemand OwerwriteDemand |
|
| 142 | 2 | * |
|
| 143 | 2 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
|
| 144 | 2 | */ |
|
| 145 | 2 | protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand) |
|
| 146 | 2 | { |
|
| 147 | 2 | foreach ($this->ignoredSettingsForOverwriteDemand as $property) { |
|
| 148 | 2 | unset($overwriteDemand[$property]); |
|
| 149 | 2 | } |
|
| 150 | 2 | ||
| 151 | 2 | foreach ($overwriteDemand as $propertyName => $propertyValue) { |
|
| 152 | if (in_array(strtolower($propertyName), $this->ignoredSettingsForOverwriteDemand, true)) { |
||
| 153 | continue; |
||
| 154 | } |
||
| 155 | \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue); |
||
| 156 | } |
||
| 157 | |||
| 158 | return $demand; |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Hook into request processing and catch exceptions |
||
| 163 | * |
||
| 164 | * @param RequestInterface $request |
||
| 165 | * @param ResponseInterface $response |
||
| 166 | * @throws \Exception |
||
| 167 | */ |
||
| 168 | public function processRequest(RequestInterface $request, ResponseInterface $response) |
||
| 176 | |||
| 177 | 2 | /** |
|
| 178 | * Handle known exceptions |
||
| 179 | * |
||
| 180 | 2 | * @param \Exception $exception |
|
| 181 | 2 | * @throws \Exception |
|
| 182 | 2 | */ |
|
| 183 | 2 | private function handleKnownExceptionsElseThrowAgain(\Exception $exception) |
|
| 184 | 2 | { |
|
| 185 | 2 | $previousException = $exception->getPrevious(); |
|
| 186 | $actions = ['detailAction', 'registrationAction', 'icalDownloadAction']; |
||
| 187 | if (in_array($this->actionMethodName, $actions, true) |
||
| 188 | && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception |
||
| 189 | ) { |
||
| 190 | $this->handleEventNotFoundError($this->settings); |
||
| 191 | } else { |
||
| 192 | throw $exception; |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | 4 | /** |
|
| 197 | * Initialize list action and set format |
||
| 198 | 4 | * |
|
| 199 | 4 | * @return void |
|
| 200 | 4 | */ |
|
| 201 | public function initializeListAction() |
||
| 207 | 4 | ||
| 208 | 4 | /** |
|
| 209 | * List view |
||
| 210 | * |
||
| 211 | * @param array $overwriteDemand OverwriteDemand |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function listAction(array $overwriteDemand = []) |
||
| 216 | { |
||
| 217 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
||
| 218 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
||
| 219 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
||
| 220 | if ($this->isOverwriteDemand($overwriteDemand)) { |
||
| 221 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
||
| 222 | } |
||
| 223 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 224 | $categories = $this->categoryRepository->findDemanded($categoryDemand); |
||
| 225 | $locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
||
| 226 | $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
||
| 227 | |||
| 228 | $values = [ |
||
| 229 | 'events' => $events, |
||
| 230 | 6 | 'categories' => $categories, |
|
| 231 | 'locations' => $locations, |
||
| 232 | 6 | 'organisators' => $organisators, |
|
| 233 | 6 | 'overwriteDemand' => $overwriteDemand, |
|
| 234 | 6 | 'eventDemand' => $eventDemand |
|
| 235 | 6 | ]; |
|
| 236 | 2 | ||
| 237 | 2 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 238 | 6 | $this->view->assignMultiple($values); |
|
| 239 | 6 | ||
| 240 | 6 | $this->addPageCacheTagsByEventDemandObject($eventDemand); |
|
| 241 | 6 | } |
|
| 242 | 6 | ||
| 243 | 6 | /** |
|
| 244 | 6 | * Calendar view |
|
| 245 | 6 | * |
|
| 246 | * @param array $overwriteDemand OverwriteDemand |
||
| 247 | * |
||
| 248 | * @return void |
||
| 249 | */ |
||
| 250 | public function calendarAction(array $overwriteDemand = []) |
||
| 251 | { |
||
| 252 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
||
| 253 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
||
| 254 | 2 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
| 255 | if ($this->isOverwriteDemand($overwriteDemand)) { |
||
| 256 | 2 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
|
| 257 | 2 | } |
|
| 258 | |||
| 259 | // Set month/year to demand if not given |
||
| 260 | if (!$eventDemand->getMonth()) { |
||
| 261 | $currentMonth = date('n'); |
||
| 262 | $eventDemand->setMonth($currentMonth); |
||
| 263 | } else { |
||
| 264 | $currentMonth = $eventDemand->getMonth(); |
||
| 265 | } |
||
| 266 | 2 | if (!$eventDemand->getYear()) { |
|
| 267 | $currentYear = date('Y'); |
||
| 268 | 2 | $eventDemand->setYear($currentYear); |
|
| 269 | 2 | } else { |
|
| 270 | $currentYear = $eventDemand->getYear(); |
||
| 271 | } |
||
| 272 | |||
| 273 | // Set demand from calendar date range instead of month / year |
||
| 274 | if ((bool)$this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks']) { |
||
| 275 | $eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand); |
||
| 276 | } |
||
| 277 | |||
| 278 | $events = $this->eventRepository->findDemanded($eventDemand); |
||
| 279 | 2 | $weeks = $this->calendarService->getCalendarArray( |
|
| 280 | $currentMonth, |
||
| 281 | 2 | $currentYear, |
|
| 282 | strtotime('today midnight'), |
||
| 283 | (int)$this->settings['calendar']['firstDayOfWeek'], |
||
| 284 | 2 | $events |
|
| 285 | ); |
||
| 286 | 2 | ||
| 287 | 2 | $values = [ |
|
| 288 | 2 | 'weeks' => $weeks, |
|
| 289 | 'categories' => $this->categoryRepository->findDemanded($categoryDemand), |
||
| 290 | 'locations' => $this->locationRepository->findDemanded($foreignRecordDemand), |
||
| 291 | 'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand), |
||
| 292 | 'eventDemand' => $eventDemand, |
||
| 293 | 'overwriteDemand' => $overwriteDemand, |
||
| 294 | 'currentPageId' => $GLOBALS['TSFE']->id, |
||
| 295 | 2 | 'firstDayOfMonth' => \DateTime::createFromFormat('d.m.Y', sprintf('1.%s.%s', $currentMonth, $currentYear)), |
|
| 296 | 'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'), |
||
| 297 | 2 | 'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month') |
|
| 298 | 2 | ]; |
|
| 299 | 2 | ||
| 300 | 2 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 301 | 2 | $this->view->assignMultiple($values); |
|
| 302 | 2 | } |
|
| 303 | 2 | ||
| 304 | 2 | /** |
|
| 305 | * Changes the given event demand object to select a date range for a calendar month including days of the previous |
||
| 306 | * month for the first week and they days for the next month for the last week |
||
| 307 | * |
||
| 308 | * @param EventDemand $eventDemand |
||
| 309 | * @return EventDemand |
||
| 310 | */ |
||
| 311 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
||
| 312 | { |
||
| 313 | $calendarDateRange = $this->calendarService->getCalendarDateRange( |
||
| 314 | $eventDemand->getMonth(), |
||
| 315 | 22 | $eventDemand->getYear(), |
|
| 316 | $this->settings['calendar']['firstDayOfWeek'] |
||
| 317 | 22 | ); |
|
| 318 | 22 | ||
| 319 | 22 | $eventDemand->setMonth(0); |
|
| 320 | $eventDemand->setYear(0); |
||
| 321 | |||
| 322 | 22 | $startDate = new \DateTime(); |
|
| 323 | 8 | $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']); |
|
| 324 | 8 | $endDate = new \DateTime(); |
|
| 325 | 8 | $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']); |
|
| 326 | 8 | $endDate->setTime(23, 59, 59); |
|
| 327 | 8 | ||
| 328 | 8 | $searchDemand = new SearchDemand(); |
|
| 329 | $searchDemand->setStartDate($startDate); |
||
| 330 | 8 | $searchDemand->setEndDate($endDate); |
|
| 331 | 8 | $eventDemand->setSearchDemand($searchDemand); |
|
| 332 | 8 | ||
| 333 | 8 | return $eventDemand; |
|
| 334 | } |
||
| 335 | 8 | ||
| 336 | 8 | /** |
|
| 337 | 8 | * Detail view for an event |
|
| 338 | 8 | * |
|
| 339 | 8 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
| 340 | 8 | * @return mixed string|void |
|
| 341 | 8 | */ |
|
| 342 | 8 | public function detailAction(Event $event = null) |
|
| 343 | { |
||
| 344 | $event = $this->evaluateSingleEventSetting($event); |
||
| 345 | 8 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
|
| 346 | $event = $this->checkPidOfEventRecord($event); |
||
|
|
|||
| 347 | } |
||
| 348 | 8 | ||
| 349 | 2 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 350 | 2 | return $this->handleEventNotFoundError($this->settings); |
|
| 351 | 2 | } |
|
| 352 | 6 | $values = ['event' => $event]; |
|
| 353 | 6 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [&$values, $this]); |
|
| 354 | $this->view->assignMultiple($values); |
||
| 355 | 8 | if ($event !== null) { |
|
| 356 | $this->addCacheTagsByEventRecords([$event]); |
||
| 357 | } |
||
| 358 | 8 | } |
|
| 359 | 6 | ||
| 360 | 6 | /** |
|
| 361 | 6 | * Error handling if event is not found |
|
| 362 | 6 | * |
|
| 363 | * @param array $settings |
||
| 364 | 6 | * @return string |
|
| 365 | 6 | */ |
|
| 366 | 6 | protected function handleEventNotFoundError($settings) |
|
| 367 | 6 | { |
|
| 368 | 6 | if (empty($settings['event']['errorHandling'])) { |
|
| 369 | return null; |
||
| 370 | 6 | } |
|
| 371 | 6 | ||
| 372 | $configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true); |
||
| 373 | |||
| 374 | 8 | switch ($configuration[0]) { |
|
| 375 | 2 | case 'redirectToListView': |
|
| 376 | 2 | $listPid = (int)$settings['listPid'] > 0 ? (int)$settings['listPid'] : 1; |
|
| 377 | $this->redirect('list', null, null, null, $listPid); |
||
| 378 | break; |
||
| 379 | 8 | case 'pageNotFoundHandler': |
|
| 380 | 8 | $GLOBALS['TSFE']->pageNotFoundAndExit('Event not found.'); |
|
| 381 | break; |
||
| 382 | 22 | case 'showStandaloneTemplate': |
|
| 383 | 2 | if (isset($configuration[2])) { |
|
| 384 | 2 | $statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $configuration[2]); |
|
| 385 | 2 | HttpUtility::setResponseCode($statusCode); |
|
| 386 | 2 | } |
|
| 387 | $standaloneTemplate = $this->objectManager->get(StandaloneView::class); |
||
| 388 | 2 | $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1])); |
|
| 389 | 2 | ||
| 390 | 2 | return $standaloneTemplate->render(); |
|
| 391 | 2 | break; |
|
| 392 | 2 | default: |
|
| 393 | 20 | } |
|
| 394 | 20 | } |
|
| 395 | 20 | ||
| 396 | 20 | /** |
|
| 397 | 20 | * Initiates the iCalendar download for the given event |
|
| 398 | 20 | * |
|
| 399 | * @param Event $event The event |
||
| 400 | 22 | * |
|
| 401 | * @return string|false |
||
| 402 | */ |
||
| 403 | public function icalDownloadAction(Event $event = null) |
||
| 404 | { |
||
| 405 | if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) { |
||
| 406 | $event = $this->checkPidOfEventRecord($event); |
||
| 407 | } |
||
| 408 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 409 | 18 | return $this->handleEventNotFoundError($this->settings); |
|
| 410 | } |
||
| 411 | $this->icalendarService->downloadiCalendarFile($event); |
||
| 412 | 18 | ||
| 413 | 2 | return false; |
|
| 414 | 2 | } |
|
| 415 | 2 | ||
| 416 | 16 | /** |
|
| 417 | * Registration view for an event |
||
| 418 | * |
||
| 419 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 420 | 16 | * |
|
| 421 | 2 | * @return mixed string|void |
|
| 422 | 2 | */ |
|
| 423 | 2 | public function registrationAction(Event $event = null) |
|
| 446 | 2 | ||
| 447 | 2 | /** |
|
| 448 | 2 | * Processes incoming registrations fields and adds field values to arguments |
|
| 449 | 2 | * |
|
| 450 | 2 | * @return void |
|
| 451 | 2 | */ |
|
| 452 | protected function setRegistrationFieldValuesToArguments() |
||
| 453 | 18 | { |
|
| 454 | 18 | $arguments = $this->request->getArguments(); |
|
| 455 | 18 | if (!isset($arguments['registration']['fields']) || !isset($arguments['event'])) { |
|
| 456 | return; |
||
| 457 | } |
||
| 458 | |||
| 459 | $registrationMvcArgument = $this->arguments->getArgument('registration'); |
||
| 460 | $propertyMapping = $registrationMvcArgument->getPropertyMappingConfiguration(); |
||
| 461 | $propertyMapping->allowProperties('fieldValues'); |
||
| 462 | $propertyMapping->allowCreationForSubProperty('fieldValues'); |
||
| 463 | $propertyMapping->allowModificationForSubProperty('fieldValues'); |
||
| 464 | |||
| 465 | 6 | // allow creation of new objects (for validation) |
|
| 466 | $propertyMapping->setTypeConverterOptions( |
||
| 467 | PersistentObjectConverter::class, |
||
| 468 | 6 | [ |
|
| 469 | PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true, |
||
| 470 | 6 | PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => true |
|
| 471 | 4 | ] |
|
| 472 | 4 | ); |
|
| 473 | |||
| 474 | 4 | // Set event to registration (required for validation) |
|
| 475 | 4 | $event = $this->eventRepository->findByUid((int)$this->request->getArgument('event')); |
|
| 476 | 2 | $propertyMapping->allowProperties('event'); |
|
| 477 | 2 | $propertyMapping->allowCreationForSubProperty('event'); |
|
| 478 | $propertyMapping->allowModificationForSubProperty('event'); |
||
| 479 | $arguments['registration']['event'] = (int)$this->request->getArgument('event'); |
||
| 480 | 4 | ||
| 481 | 4 | $index = 0; |
|
| 482 | 4 | foreach ((array)$arguments['registration']['fields'] as $fieldUid => $value) { |
|
| 483 | 4 | // Only accept registration fields of the current event |
|
| 484 | if (!in_array((int)$fieldUid, $event->getRegistrationFieldsUids(), true)) { |
||
| 485 | 4 | continue; |
|
| 486 | 4 | } |
|
| 487 | 4 | ||
| 488 | 4 | // allow subvalues in new property mapper |
|
| 489 | 4 | $propertyMapping->forProperty('fieldValues')->allowProperties($index); |
|
| 490 | $propertyMapping->forProperty('fieldValues.' . $index)->allowAllProperties(); |
||
| 491 | 4 | $propertyMapping->allowCreationForSubProperty('fieldValues.' . $index); |
|
| 492 | $propertyMapping->allowModificationForSubProperty('fieldValues.' . $index); |
||
| 493 | |||
| 494 | 4 | if (is_array($value)) { |
|
| 495 | 4 | if (empty($value)) { |
|
| 496 | 4 | $value = ''; |
|
| 497 | 4 | } else { |
|
| 498 | $value = json_encode($value); |
||
| 499 | } |
||
| 500 | 6 | } |
|
| 501 | 6 | ||
| 502 | /** @var Registration\Field $field */ |
||
| 503 | $field = $this->fieldRepository->findByUid((int)$fieldUid); |
||
| 504 | |||
| 505 | $arguments['registration']['fieldValues'][$index] = [ |
||
| 506 | 'pid' => $field->getPid(), |
||
| 507 | 'value' => $value, |
||
| 508 | 'field' => strval($fieldUid), |
||
| 509 | 'valueType' => $field->getValueType() |
||
| 510 | ]; |
||
| 511 | |||
| 512 | $index++; |
||
| 513 | } |
||
| 514 | |||
| 515 | // Remove temporary "fields" field |
||
| 516 | $arguments = ArrayUtility::removeByPath($arguments, 'registration/fields'); |
||
| 517 | $this->request->setArguments($arguments); |
||
| 518 | 6 | } |
|
| 519 | 6 | ||
| 520 | 6 | /** |
|
| 521 | * Set date format for field dateOfBirth |
||
| 522 | * |
||
| 523 | * @return void |
||
| 524 | */ |
||
| 525 | public function initializeSaveRegistrationAction() |
||
| 526 | { |
||
| 527 | $this->arguments->getArgument('registration') |
||
| 528 | ->getPropertyMappingConfiguration()->forProperty('dateOfBirth') |
||
| 529 | ->setTypeConverterOption( |
||
| 530 | 4 | DateTimeConverter::class, |
|
| 531 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 532 | $this->settings['registration']['formatDateOfBirth'] |
||
| 533 | 4 | ); |
|
| 534 | $this->setRegistrationFieldValuesToArguments(); |
||
| 535 | 4 | } |
|
| 536 | |||
| 537 | 2 | /** |
|
| 538 | 2 | * Saves the registration |
|
| 539 | 2 | * |
|
| 540 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
| 541 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 542 | 2 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationFieldValidator |
|
| 543 | 2 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
|
| 544 | 2 | * |
|
| 545 | 2 | * @return mixed string|void |
|
| 546 | 2 | */ |
|
| 547 | public function saveRegistrationAction(Registration $registration, Event $event) |
||
| 548 | 2 | { |
|
| 549 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
||
| 550 | $event = $this->checkPidOfEventRecord($event); |
||
| 551 | 2 | } |
|
| 552 | 2 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
|
| 553 | 2 | return $this->handleEventNotFoundError($this->settings); |
|
| 554 | } |
||
| 555 | $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm(); |
||
| 556 | 2 | $result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
|
| 557 | $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
||
| 558 | |||
| 559 | 2 | // Save registration if no errors |
|
| 560 | 2 | if ($success) { |
|
| 561 | 4 | $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
|
| 562 | 4 | $event, |
|
| 563 | 4 | $registration->getAmountOfRegistrations() |
|
| 564 | ); |
||
| 565 | $linkValidity = (int)$this->settings['confirmation']['linkValidity']; |
||
| 566 | if ($linkValidity === 0) { |
||
| 567 | // Use 3600 seconds as default value if not set |
||
| 568 | $linkValidity = 3600; |
||
| 569 | } |
||
| 570 | 2 | $confirmationUntil = new \DateTime(); |
|
| 571 | $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); |
||
| 572 | 2 | ||
| 573 | 2 | $registration->setEvent($event); |
|
| 574 | 2 | $registration->setPid($event->getPid()); |
|
| 575 | 2 | $registration->setConfirmationUntil($confirmationUntil); |
|
| 576 | 2 | $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); |
|
| 577 | 2 | $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
|
| 578 | 2 | $registration->setWaitlist($isWaitlistRegistration); |
|
| 579 | 2 | $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid); |
|
| 580 | 2 | $this->registrationRepository->add($registration); |
|
| 581 | 2 | ||
| 582 | 2 | // Persist registration, so we have an UID |
|
| 583 | 2 | $this->objectManager->get(PersistenceManager::class)->persistAll(); |
|
| 584 | 2 | ||
| 585 | 2 | // Add new registration (or waitlist registration) to event |
|
| 586 | 2 | if ($isWaitlistRegistration) { |
|
| 587 | 2 | $event->addRegistrationWaitlist($registration); |
|
| 588 | 2 | $messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
|
| 589 | } else { |
||
| 590 | $event->addRegistration($registration); |
||
| 591 | $messageType = MessageType::REGISTRATION_NEW; |
||
| 592 | } |
||
| 593 | $this->eventRepository->update($event); |
||
| 594 | |||
| 595 | $this->signalDispatch(__CLASS__, __FUNCTION__ . 'AfterRegistrationSaved', [$registration, $this]); |
||
| 596 | |||
| 597 | // Send notifications to user and admin if confirmation link should be sent |
||
| 598 | 12 | if (!$autoConfirmation) { |
|
| 599 | $this->notificationService->sendUserMessage( |
||
| 600 | 12 | $event, |
|
| 601 | 12 | $registration, |
|
| 602 | 12 | $this->settings, |
|
| 603 | 12 | $messageType |
|
| 604 | ); |
||
| 605 | 12 | $this->notificationService->sendAdminMessage( |
|
| 606 | 10 | $event, |
|
| 607 | $registration, |
||
| 608 | 10 | $this->settings, |
|
| 609 | 2 | $messageType |
|
| 610 | 2 | ); |
|
| 611 | } |
||
| 612 | 10 | ||
| 613 | 2 | // Create given amount of registrations if necessary |
|
| 614 | 2 | if ($registration->getAmountOfRegistrations() > 1) { |
|
| 615 | 10 | $this->registrationService->createDependingRegistrations($registration); |
|
| 616 | } |
||
| 617 | 12 | ||
| 618 | 2 | // Clear cache for configured pages |
|
| 619 | 2 | $this->utilityService->clearCacheForConfiguredUids($this->settings); |
|
| 620 | } |
||
| 621 | 12 | ||
| 622 | 12 | if ($autoConfirmation && $success) { |
|
| 623 | $this->redirect( |
||
| 624 | 12 | 'confirmRegistration', |
|
| 625 | null, |
||
| 626 | 12 | null, |
|
| 627 | 12 | [ |
|
| 628 | 12 | 'reguid' => $registration->getUid(), |
|
| 629 | 12 | 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()) |
|
| 630 | 12 | ] |
|
| 631 | 12 | ); |
|
| 632 | } else { |
||
| 633 | $this->redirect( |
||
| 634 | 'saveRegistrationResult', |
||
| 635 | null, |
||
| 636 | null, |
||
| 637 | [ |
||
| 638 | 'result' => $result, |
||
| 639 | 18 | 'eventuid' => $event->getUid(), |
|
| 640 | 'hmac' => $this->hashService->generateHmac('event-' . $event->getUid()) |
||
| 641 | 18 | ] |
|
| 642 | ); |
||
| 643 | } |
||
| 644 | } |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Shows the result of the saveRegistrationAction |
||
| 648 | * |
||
| 649 | * @param int $result Result |
||
| 650 | * @param int $eventuid |
||
| 651 | * @param string $hmac |
||
| 652 | * |
||
| 653 | * @return void |
||
| 654 | */ |
||
| 655 | public function saveRegistrationResultAction($result, $eventuid, $hmac) |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Confirms the registration if possible and sends e-mails to admin and user |
||
| 717 | * |
||
| 718 | * @param int $reguid UID of registration |
||
| 719 | * @param string $hmac HMAC for parameters |
||
| 720 | * |
||
| 721 | * @return void |
||
| 722 | */ |
||
| 723 | public function confirmRegistrationAction($reguid, $hmac) |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Cancels the registration if possible and sends e-mails to admin and user |
||
| 795 | * |
||
| 796 | * @param int $reguid UID of registration |
||
| 797 | * @param string $hmac HMAC for parameters |
||
| 798 | * |
||
| 799 | * @return void |
||
| 800 | */ |
||
| 801 | public function cancelRegistrationAction($reguid, $hmac) |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Set date format for field startDate and endDate |
||
| 852 | * |
||
| 853 | * @return void |
||
| 854 | */ |
||
| 855 | public function initializeSearchAction() |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Search view |
||
| 887 | * |
||
| 888 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
| 889 | * @param array $overwriteDemand OverwriteDemand |
||
| 890 | * |
||
| 891 | * @return void |
||
| 892 | */ |
||
| 893 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
| 936 | * |
||
| 937 | * @param array $overwriteDemand |
||
| 938 | * @return bool |
||
| 939 | */ |
||
| 940 | protected function isOverwriteDemand($overwriteDemand) |
||
| 944 | |||
| 945 | /** |
||
| 946 | * If no event is given and the singleEvent setting is set, the configured single event is returned |
||
| 947 | * |
||
| 948 | * @param Event|null $event |
||
| 949 | * @return Event|null |
||
| 950 | */ |
||
| 951 | protected function evaluateSingleEventSetting($event) |
||
| 959 | |||
| 960 | /** |
||
| 961 | * Adds cache tags to page cache by event records. |
||
| 962 | * |
||
| 963 | * Following cache tags will be added to tsfe: |
||
| 964 | * "tx_sfeventmgt_uid_[event:uid]" |
||
| 965 | * |
||
| 966 | * @param array $eventRecords array with event records |
||
| 967 | */ |
||
| 968 | public function addCacheTagsByEventRecords(array $eventRecords) |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Adds page cache tags by used storagePages. |
||
| 982 | * This adds tags with the scheme tx_sfeventmgt_pid_[event:pid] |
||
| 983 | * |
||
| 984 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand |
||
| 985 | */ |
||
| 986 | public function addPageCacheTagsByEventDemandObject(\DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand) |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Checks if the event pid could be found in the storagePage settings of the detail plugin and |
||
| 1002 | * if the pid could not be found it return null instead of the event object. |
||
| 1003 | * |
||
| 1004 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
| 1005 | * @return null|\DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 1006 | */ |
||
| 1007 | protected function checkPidOfEventRecord(Event $event) |
||
| 1031 | } |
||
| 1032 |
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: