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 |
||
| 53 | class EventController extends AbstractController |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * @var EventCacheService |
||
| 57 | */ |
||
| 58 | protected $eventCacheService; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param EventCacheService $cacheService |
||
| 62 | */ |
||
| 63 | public function injectEventCacheService(EventCacheService $cacheService) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Assign contentObjectData and pageData to earch view |
||
| 70 | * |
||
| 71 | * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view |
||
| 72 | */ |
||
| 73 | protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Initializes the current action |
||
| 84 | */ |
||
| 85 | public function initializeAction() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Creates an event demand object with the given settings |
||
| 100 | * |
||
| 101 | * @param array $settings The settings |
||
| 102 | * |
||
| 103 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
| 104 | */ |
||
| 105 | public function createEventDemandObjectFromSettings(array $settings) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Creates a foreign record demand object with the given settings |
||
| 128 | * |
||
| 129 | * @param array $settings The settings |
||
| 130 | * |
||
| 131 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
||
| 132 | */ |
||
| 133 | public function createForeignRecordDemandObjectFromSettings(array $settings) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Creates a category demand object with the given settings |
||
| 145 | * |
||
| 146 | * @param array $settings The settings |
||
| 147 | * |
||
| 148 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
||
| 149 | */ |
||
| 150 | public function createCategoryDemandObjectFromSettings(array $settings) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Hook into request processing and catch exceptions |
||
| 164 | * |
||
| 165 | * @param RequestInterface $request |
||
| 166 | * @param ResponseInterface $response |
||
| 167 | * @throws \Exception |
||
| 168 | */ |
||
| 169 | public function processRequest(RequestInterface $request, ResponseInterface $response) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Handle known exceptions |
||
| 180 | * |
||
| 181 | * @param \Exception $exception |
||
| 182 | * @throws \Exception |
||
| 183 | */ |
||
| 184 | private function handleKnownExceptionsElseThrowAgain(\Exception $exception) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Initialize list action and set format |
||
| 199 | */ |
||
| 200 | public function initializeListAction() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * List view |
||
| 209 | * |
||
| 210 | * @param array $overwriteDemand OverwriteDemand |
||
| 211 | */ |
||
| 212 | public function listAction(array $overwriteDemand = []) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Calendar view |
||
| 247 | * |
||
| 248 | * @param array $overwriteDemand OverwriteDemand |
||
| 249 | */ |
||
| 250 | public function calendarAction(array $overwriteDemand = []) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Changes the given event demand object to select a date range for a calendar month including days of the previous |
||
| 314 | * month for the first week and they days for the next month for the last week |
||
| 315 | * |
||
| 316 | * @param EventDemand $eventDemand |
||
| 317 | * @return EventDemand |
||
| 318 | */ |
||
| 319 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Detail view for an event |
||
| 346 | * |
||
| 347 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 348 | * @return mixed string|void |
||
| 349 | */ |
||
| 350 | public function detailAction(Event $event = null) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Error handling if event is not found |
||
| 374 | * |
||
| 375 | * @param array $settings |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | protected function handleEventNotFoundError($settings) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Initiates the iCalendar download for the given event |
||
| 414 | * |
||
| 415 | * @param Event $event The event |
||
| 416 | * |
||
| 417 | * @return string|false |
||
| 418 | */ |
||
| 419 | public function icalDownloadAction(Event $event = null) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Registration view for an event |
||
| 433 | * |
||
| 434 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 435 | * |
||
| 436 | * @return mixed string|void |
||
| 437 | */ |
||
| 438 | public function registrationAction(Event $event = null) |
||
| 439 | { |
||
| 440 | $event = $this->evaluateSingleEventSetting($event); |
||
| 441 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
||
| 442 | $event = $this->checkPidOfEventRecord($event); |
||
| 443 | } |
||
| 444 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 445 | return $this->handleEventNotFoundError($this->settings); |
||
| 446 | } |
||
| 447 | if ($event->getRestrictPaymentMethods()) { |
||
| 448 | $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event); |
||
| 449 | } else { |
||
| 450 | $paymentMethods = $this->paymentService->getPaymentMethods(); |
||
| 451 | } |
||
| 452 | |||
| 453 | $modifyRegistrationViewVariablesEvent = new ModifyRegistrationViewVariablesEvent( |
||
| 454 | [ |
||
| 455 | 'event' => $event, |
||
| 456 | 'paymentMethods' => $paymentMethods, |
||
| 457 | ], |
||
| 458 | $this |
||
| 459 | ); |
||
| 460 | $this->eventDispatcher->dispatch($modifyRegistrationViewVariablesEvent); |
||
| 461 | $variables = $modifyRegistrationViewVariablesEvent->getVariables(); |
||
| 462 | $this->view->assignMultiple($variables); |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Removes all possible spamcheck fields (which do not belong to the domain model) from arguments. |
||
| 467 | */ |
||
| 468 | protected function removePossibleSpamCheckFieldsFromArguments() |
||
| 469 | { |
||
| 470 | $arguments = $this->request->getArguments(); |
||
| 471 | if (!isset($arguments['event'])) { |
||
| 472 | return; |
||
| 473 | } |
||
| 474 | |||
| 475 | // Remove a possible honeypot field |
||
| 476 | $honeypotField = 'hp' . (int)$arguments['event']; |
||
| 477 | if (isset($arguments['registration'][$honeypotField])) { |
||
| 478 | unset($arguments['registration'][$honeypotField]); |
||
| 479 | } |
||
| 480 | |||
| 481 | // Remove a possible challenge/response field |
||
| 482 | if (isset($arguments['registration']['cr-response'])) { |
||
| 483 | unset($arguments['registration']['cr-response']); |
||
| 484 | } |
||
| 485 | |||
| 486 | $this->request->setArguments($arguments); |
||
| 487 | } |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Processes incoming registrations fields and adds field values to arguments |
||
| 491 | */ |
||
| 492 | protected function setRegistrationFieldValuesToArguments() |
||
| 493 | { |
||
| 494 | $arguments = $this->request->getArguments(); |
||
| 495 | if (!isset($arguments['event'])) { |
||
| 496 | return; |
||
| 497 | } |
||
| 498 | |||
| 499 | /** @var Event $event */ |
||
| 500 | $event = $this->eventRepository->findByUid((int)$this->request->getArgument('event')); |
||
| 501 | if (!$event || $event->getRegistrationFields()->count() === 0) { |
||
| 502 | return; |
||
| 503 | } |
||
| 504 | |||
| 505 | $registrationMvcArgument = $this->arguments->getArgument('registration'); |
||
| 506 | $propertyMapping = $registrationMvcArgument->getPropertyMappingConfiguration(); |
||
| 507 | $propertyMapping->allowProperties('fieldValues'); |
||
| 508 | $propertyMapping->allowCreationForSubProperty('fieldValues'); |
||
| 509 | $propertyMapping->allowModificationForSubProperty('fieldValues'); |
||
| 510 | |||
| 511 | // allow creation of new objects (for validation) |
||
| 512 | $propertyMapping->setTypeConverterOptions( |
||
| 513 | PersistentObjectConverter::class, |
||
| 514 | [ |
||
| 515 | PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true, |
||
| 516 | PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => true |
||
| 517 | ] |
||
| 518 | ); |
||
| 519 | |||
| 520 | // Set event to registration (required for validation) |
||
| 521 | $propertyMapping->allowProperties('event'); |
||
| 522 | $propertyMapping->allowCreationForSubProperty('event'); |
||
| 523 | $propertyMapping->allowModificationForSubProperty('event'); |
||
| 524 | $arguments['registration']['event'] = (int)$this->request->getArgument('event'); |
||
| 525 | |||
| 526 | $index = 0; |
||
| 527 | foreach ((array)$arguments['registration']['fields'] as $fieldUid => $value) { |
||
| 528 | // Only accept registration fields of the current event |
||
| 529 | if (!in_array((int)$fieldUid, $event->getRegistrationFieldsUids(), true)) { |
||
| 530 | continue; |
||
| 531 | } |
||
| 532 | |||
| 533 | // allow subvalues in new property mapper |
||
| 534 | $propertyMapping->forProperty('fieldValues')->allowProperties($index); |
||
| 535 | $propertyMapping->forProperty('fieldValues.' . $index)->allowAllProperties(); |
||
| 536 | $propertyMapping->allowCreationForSubProperty('fieldValues.' . $index); |
||
| 537 | $propertyMapping->allowModificationForSubProperty('fieldValues.' . $index); |
||
| 538 | |||
| 539 | if (is_array($value)) { |
||
| 540 | if (empty($value)) { |
||
| 541 | $value = ''; |
||
| 542 | } else { |
||
| 543 | $value = json_encode($value); |
||
| 544 | } |
||
| 545 | } |
||
| 546 | |||
| 547 | /** @var Registration\Field $field */ |
||
| 548 | $field = $this->fieldRepository->findByUid((int)$fieldUid); |
||
| 549 | |||
| 550 | $arguments['registration']['fieldValues'][$index] = [ |
||
| 551 | 'pid' => $field->getPid(), |
||
| 552 | 'value' => $value, |
||
| 553 | 'field' => (string)$fieldUid, |
||
| 554 | 'valueType' => $field->getValueType() |
||
| 555 | ]; |
||
| 556 | |||
| 557 | $index++; |
||
| 558 | } |
||
| 559 | |||
| 560 | // Remove temporary "fields" field |
||
| 561 | if (isset($arguments['registration']['fields'])) { |
||
| 562 | $arguments = ArrayUtility::removeByPath($arguments, 'registration/fields'); |
||
| 563 | } |
||
| 564 | $this->request->setArguments($arguments); |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Set date format for field dateOfBirth |
||
| 569 | */ |
||
| 570 | public function initializeSaveRegistrationAction() |
||
| 571 | { |
||
| 572 | $this->arguments->getArgument('registration') |
||
| 573 | ->getPropertyMappingConfiguration()->forProperty('dateOfBirth') |
||
| 574 | ->setTypeConverterOption( |
||
| 575 | DateTimeConverter::class, |
||
| 576 | DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
||
| 577 | $this->settings['registration']['formatDateOfBirth'] |
||
| 578 | ); |
||
| 579 | $this->removePossibleSpamCheckFieldsFromArguments(); |
||
| 580 | $this->setRegistrationFieldValuesToArguments(); |
||
| 581 | } |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Saves the registration |
||
| 585 | * |
||
| 586 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 587 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 588 | * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationFieldValidator", param="registration") |
||
| 589 | * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator", param="registration") |
||
| 590 | * |
||
| 591 | * @return mixed string|void |
||
| 592 | */ |
||
| 593 | public function saveRegistrationAction(Registration $registration, Event $event) |
||
| 594 | { |
||
| 595 | if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) { |
||
| 596 | $event = $this->checkPidOfEventRecord($event); |
||
| 597 | } |
||
| 598 | if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
||
| 599 | return $this->handleEventNotFoundError($this->settings); |
||
| 600 | } |
||
| 601 | $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm(); |
||
| 602 | $result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
||
| 603 | list($success, $result) = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
||
| 604 | |||
| 605 | // Save registration if no errors |
||
| 606 | if ($success) { |
||
| 607 | $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
||
| 608 | $event, |
||
| 609 | $registration->getAmountOfRegistrations() |
||
| 610 | ); |
||
| 611 | $linkValidity = (int)$this->settings['confirmation']['linkValidity']; |
||
| 612 | if ($linkValidity === 0) { |
||
| 613 | // Use 3600 seconds as default value if not set |
||
| 614 | $linkValidity = 3600; |
||
| 615 | } |
||
| 616 | $confirmationUntil = new \DateTime(); |
||
| 617 | $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); |
||
| 618 | |||
| 619 | $registration->setEvent($event); |
||
| 620 | $registration->setPid($event->getPid()); |
||
| 621 | $registration->setRegistrationDate(new \DateTime()); |
||
| 622 | $registration->setConfirmationUntil($confirmationUntil); |
||
| 623 | $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); |
||
| 624 | $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
||
| 625 | $registration->setWaitlist($isWaitlistRegistration); |
||
| 626 | $registration->_setProperty('_languageUid', $this->getSysLanguageUid()); |
||
| 627 | $this->registrationRepository->add($registration); |
||
| 628 | |||
| 629 | // Persist registration, so we have an UID |
||
| 630 | $this->persistAll(); |
||
| 631 | |||
| 632 | if ($isWaitlistRegistration) { |
||
| 633 | $messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
||
| 634 | } else { |
||
| 635 | $messageType = MessageType::REGISTRATION_NEW; |
||
| 636 | } |
||
| 637 | |||
| 638 | // Fix event in registration for language other than default language |
||
| 639 | $this->registrationService->fixRegistrationEvent($registration, $event); |
||
| 640 | |||
| 641 | // Fix language of registration fields if other than default language |
||
| 642 | $this->registrationService->fixRegistationFieldValueLanguage($registration, $event); |
||
| 643 | |||
| 644 | $this->eventDispatcher->dispatch(new AfterRegistrationSavedEvent($registration, $this)); |
||
| 645 | |||
| 646 | // Send notifications to user and admin if confirmation link should be sent |
||
| 647 | if (!$autoConfirmation) { |
||
| 648 | $this->notificationService->sendUserMessage( |
||
| 649 | $event, |
||
| 650 | $registration, |
||
| 651 | $this->settings, |
||
| 652 | $messageType |
||
| 653 | ); |
||
| 654 | $this->notificationService->sendAdminMessage( |
||
| 655 | $event, |
||
| 656 | $registration, |
||
| 657 | $this->settings, |
||
| 658 | $messageType |
||
| 659 | ); |
||
| 660 | } |
||
| 661 | |||
| 662 | // Create given amount of registrations if necessary |
||
| 663 | $modifyCreateDependingRegistrationsEvent = new ModifyCreateDependingRegistrationsEvent( |
||
| 664 | $registration, |
||
| 665 | ($registration->getAmountOfRegistrations() > 1), |
||
| 666 | $this |
||
| 667 | ); |
||
| 668 | $this->eventDispatcher->dispatch($modifyCreateDependingRegistrationsEvent); |
||
| 669 | $createDependingRegistrations = $modifyCreateDependingRegistrationsEvent->getCreateDependingRegistrations(); |
||
| 670 | if ($createDependingRegistrations) { |
||
| 671 | $this->registrationService->createDependingRegistrations($registration); |
||
| 672 | } |
||
| 673 | |||
| 674 | // Flush page cache for event, since new registration has been added |
||
| 675 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
||
| 676 | } |
||
| 677 | |||
| 678 | if ($autoConfirmation && $success) { |
||
| 679 | $this->redirect( |
||
| 680 | 'confirmRegistration', |
||
| 681 | null, |
||
| 682 | null, |
||
| 683 | [ |
||
| 684 | 'reguid' => $registration->getUid(), |
||
| 685 | 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()) |
||
| 686 | ] |
||
| 687 | ); |
||
| 688 | } else { |
||
| 689 | $this->redirect( |
||
| 690 | 'saveRegistrationResult', |
||
| 691 | null, |
||
| 692 | null, |
||
| 693 | [ |
||
| 694 | 'result' => $result, |
||
| 695 | 'eventuid' => $event->getUid(), |
||
| 696 | 'hmac' => $this->hashService->generateHmac('event-' . $event->getUid()) |
||
| 697 | ] |
||
| 698 | ); |
||
| 699 | } |
||
| 700 | } |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Shows the result of the saveRegistrationAction |
||
| 704 | * |
||
| 705 | * @param int $result Result |
||
| 706 | * @param int $eventuid |
||
| 707 | * @param string $hmac |
||
| 708 | */ |
||
| 709 | public function saveRegistrationResultAction($result, $eventuid, $hmac) |
||
| 710 | { |
||
| 711 | $event = null; |
||
| 712 | |||
| 713 | switch ($result) { |
||
| 714 | case RegistrationResult::REGISTRATION_SUCCESSFUL: |
||
| 715 | $messageKey = 'event.message.registrationsuccessful'; |
||
| 716 | $titleKey = 'registrationResult.title.successful'; |
||
| 717 | break; |
||
| 718 | case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST: |
||
| 719 | $messageKey = 'event.message.registrationwaitlistsuccessful'; |
||
| 720 | $titleKey = 'registrationWaitlistResult.title.successful'; |
||
| 721 | break; |
||
| 722 | case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED: |
||
| 723 | $messageKey = 'event.message.registrationfailedeventexpired'; |
||
| 724 | $titleKey = 'registrationResult.title.failed'; |
||
| 725 | break; |
||
| 726 | case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS: |
||
| 727 | $messageKey = 'event.message.registrationfailedmaxparticipants'; |
||
| 728 | $titleKey = 'registrationResult.title.failed'; |
||
| 729 | break; |
||
| 730 | case RegistrationResult::REGISTRATION_NOT_ENABLED: |
||
| 731 | $messageKey = 'event.message.registrationfailednotenabled'; |
||
| 732 | $titleKey = 'registrationResult.title.failed'; |
||
| 733 | break; |
||
| 734 | case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED: |
||
| 735 | $messageKey = 'event.message.registrationfaileddeadlineexpired'; |
||
| 736 | $titleKey = 'registrationResult.title.failed'; |
||
| 737 | break; |
||
| 738 | case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES: |
||
| 739 | $messageKey = 'event.message.registrationfailednotenoughfreeplaces'; |
||
| 740 | $titleKey = 'registrationResult.title.failed'; |
||
| 741 | break; |
||
| 742 | case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED: |
||
| 743 | $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded'; |
||
| 744 | $titleKey = 'registrationResult.title.failed'; |
||
| 745 | break; |
||
| 746 | case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE: |
||
| 747 | $messageKey = 'event.message.registrationfailedemailnotunique'; |
||
| 748 | $titleKey = 'registrationResult.title.failed'; |
||
| 749 | break; |
||
| 750 | default: |
||
| 751 | $messageKey = ''; |
||
| 752 | $titleKey = ''; |
||
| 753 | } |
||
| 754 | |||
| 755 | if (!$this->hashService->validateHmac('event-' . $eventuid, $hmac)) { |
||
| 756 | $messageKey = 'event.message.registrationsuccessfulwrongeventhmac'; |
||
| 757 | $titleKey = 'registrationResult.title.failed'; |
||
| 758 | } else { |
||
| 759 | $event = $this->eventRepository->findByUid((int)$eventuid); |
||
| 760 | } |
||
| 761 | |||
| 762 | $this->view->assignMultiple([ |
||
| 763 | 'messageKey' => $messageKey, |
||
| 764 | 'titleKey' => $titleKey, |
||
| 765 | 'event' => $event, |
||
| 766 | ]); |
||
| 767 | } |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Confirms the registration if possible and sends emails to admin and user |
||
| 771 | * |
||
| 772 | * @param int $reguid UID of registration |
||
| 773 | * @param string $hmac HMAC for parameters |
||
| 774 | */ |
||
| 775 | public function confirmRegistrationAction($reguid, $hmac) |
||
| 776 | { |
||
| 777 | $event = null; |
||
| 778 | |||
| 779 | /* @var $registration Registration */ |
||
| 780 | list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration( |
||
| 781 | $reguid, |
||
| 782 | $hmac |
||
| 783 | ); |
||
| 784 | |||
| 785 | if ($failed === false) { |
||
| 786 | $registration->setConfirmed(true); |
||
| 787 | $event = $registration->getEvent(); |
||
| 788 | $this->registrationRepository->update($registration); |
||
| 789 | |||
| 790 | $this->eventDispatcher->dispatch(new AfterRegistrationConfirmedEvent($registration, $this)); |
||
| 791 | |||
| 792 | $messageType = MessageType::REGISTRATION_CONFIRMED; |
||
| 793 | if ($registration->getWaitlist()) { |
||
| 794 | $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED; |
||
| 795 | } |
||
| 796 | |||
| 797 | // Send notifications to user and admin |
||
| 798 | $this->notificationService->sendUserMessage( |
||
| 799 | $registration->getEvent(), |
||
| 800 | $registration, |
||
| 801 | $this->settings, |
||
| 802 | $messageType |
||
| 803 | ); |
||
| 804 | $this->notificationService->sendAdminMessage( |
||
| 805 | $registration->getEvent(), |
||
| 806 | $registration, |
||
| 807 | $this->settings, |
||
| 808 | $messageType |
||
| 809 | ); |
||
| 810 | |||
| 811 | // Confirm registrations depending on main registration if necessary |
||
| 812 | if ($registration->getAmountOfRegistrations() > 1) { |
||
| 813 | $this->registrationService->confirmDependingRegistrations($registration); |
||
| 814 | } |
||
| 815 | } |
||
| 816 | |||
| 817 | // Redirect to payment provider if payment/redirect is enabled |
||
| 818 | $paymentPid = (int)$this->settings['paymentPid']; |
||
| 819 | if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) { |
||
| 820 | $this->uriBuilder->reset() |
||
| 821 | ->setTargetPageUid($paymentPid); |
||
| 822 | $uri = $this->uriBuilder->uriFor( |
||
| 823 | 'redirect', |
||
| 824 | [ |
||
| 825 | 'registration' => $registration, |
||
| 826 | 'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid()) |
||
| 827 | ], |
||
| 828 | 'Payment', |
||
| 829 | 'sfeventmgt', |
||
| 830 | 'Pipayment' |
||
| 831 | ); |
||
| 832 | $this->redirectToUri($uri); |
||
| 833 | } |
||
| 834 | |||
| 835 | $modifyConfirmRegistrationViewVariablesEvent = new ModifyConfirmRegistrationViewVariablesEvent( |
||
| 836 | [ |
||
| 837 | 'failed' => $failed, |
||
| 838 | 'messageKey' => $messageKey, |
||
| 839 | 'titleKey' => $titleKey, |
||
| 840 | 'event' => $event, |
||
| 841 | 'registration' => $registration, |
||
| 842 | ], |
||
| 843 | $this |
||
| 844 | ); |
||
| 845 | $this->eventDispatcher->dispatch($modifyConfirmRegistrationViewVariablesEvent); |
||
| 846 | $variables = $modifyConfirmRegistrationViewVariablesEvent->getVariables(); |
||
| 847 | $this->view->assignMultiple($variables); |
||
| 848 | } |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Cancels the registration if possible and sends emails to admin and user |
||
| 852 | * |
||
| 853 | * @param int $reguid UID of registration |
||
| 854 | * @param string $hmac HMAC for parameters |
||
| 855 | */ |
||
| 856 | public function cancelRegistrationAction($reguid, $hmac) |
||
| 857 | { |
||
| 858 | $event = null; |
||
| 859 | |||
| 860 | /* @var $registration Registration */ |
||
| 861 | list($failed, $registration, $messageKey, $titleKey) = |
||
| 862 | $this->registrationService->checkCancelRegistration($reguid, $hmac); |
||
| 863 | |||
| 864 | if ($failed === false) { |
||
| 865 | $event = $registration->getEvent(); |
||
| 866 | |||
| 867 | // Send notifications (must run before cancelling the registration) |
||
| 868 | $this->notificationService->sendUserMessage( |
||
| 869 | $registration->getEvent(), |
||
| 870 | $registration, |
||
| 871 | $this->settings, |
||
| 872 | MessageType::REGISTRATION_CANCELLED |
||
| 873 | ); |
||
| 874 | $this->notificationService->sendAdminMessage( |
||
| 875 | $registration->getEvent(), |
||
| 876 | $registration, |
||
| 877 | $this->settings, |
||
| 878 | MessageType::REGISTRATION_CANCELLED |
||
| 879 | ); |
||
| 880 | |||
| 881 | // First cancel depending registrations |
||
| 882 | if ($registration->getAmountOfRegistrations() > 1) { |
||
| 883 | $this->registrationService->cancelDependingRegistrations($registration); |
||
| 884 | } |
||
| 885 | |||
| 886 | // Finally cancel registration |
||
| 887 | $this->registrationRepository->remove($registration); |
||
| 888 | |||
| 889 | // Persist changes, so following functions can work with $event properties (e.g. amount of registrations) |
||
| 890 | $this->persistAll(); |
||
| 891 | |||
| 892 | // Dispatch event, so waitlist registrations can be moved up |
||
| 893 | $this->eventDispatcher->dispatch(new WaitlistMoveUpEvent($event, $this)); |
||
| 894 | |||
| 895 | // Move up waitlist registrations if configured on event basis |
||
| 896 | $this->registrationService->moveUpWaitlistRegistrations($event, $this->settings); |
||
| 897 | |||
| 898 | // Flush page cache for event, since amount of registrations has changed |
||
| 899 | $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid()); |
||
| 900 | } |
||
| 901 | |||
| 902 | $modifyCancelRegistrationViewVariablesEvent = new ModifyCancelRegistrationViewVariablesEvent( |
||
| 903 | [ |
||
| 904 | 'failed' => $failed, |
||
| 905 | 'messageKey' => $messageKey, |
||
| 906 | 'titleKey' => $titleKey, |
||
| 907 | 'event' => $event, |
||
| 908 | ], |
||
| 909 | $this |
||
| 910 | ); |
||
| 911 | $this->eventDispatcher->dispatch($modifyCancelRegistrationViewVariablesEvent); |
||
| 912 | $variables = $modifyCancelRegistrationViewVariablesEvent->getVariables(); |
||
| 913 | $this->view->assignMultiple($variables); |
||
| 914 | } |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Set date format for field startDate and endDate |
||
| 918 | */ |
||
| 919 | public function initializeSearchAction() |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Search view |
||
| 951 | * |
||
| 952 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
| 953 | * @param array $overwriteDemand OverwriteDemand |
||
| 954 | */ |
||
| 955 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
| 1003 | * |
||
| 1004 | * @param array $overwriteDemand |
||
| 1005 | * @return bool |
||
| 1006 | */ |
||
| 1007 | protected function isOverwriteDemand($overwriteDemand) |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * If no event is given and the singleEvent setting is set, the configured single event is returned |
||
| 1014 | * |
||
| 1015 | * @param Event|null $event |
||
| 1016 | * @return Event|null |
||
| 1017 | */ |
||
| 1018 | protected function evaluateSingleEventSetting($event) |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * If no event is given and the isShortcut setting is set, the event is displayed using the "Insert Record" |
||
| 1029 | * content element and should be loaded from contect object data |
||
| 1030 | * |
||
| 1031 | * @param Event|null $event |
||
| 1032 | * @return Event|null |
||
| 1033 | */ |
||
| 1034 | protected function evaluateIsShortcutSetting($event) |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Checks if the event pid could be found in the storagePage settings of the detail plugin and |
||
| 1046 | * if the pid could not be found it return null instead of the event object. |
||
| 1047 | * |
||
| 1048 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
| 1049 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Event|null |
||
| 1050 | */ |
||
| 1051 | protected function checkPidOfEventRecord(Event $event) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Calls persistAll() of the persistenceManager |
||
| 1071 | */ |
||
| 1072 | protected function persistAll() |
||
| 1073 | { |
||
| 1074 | $this->objectManager->get(PersistenceManager::class)->persistAll(); |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * Returns the current sys_language_uid |
||
| 1079 | * |
||
| 1080 | * @return int |
||
| 1081 | */ |
||
| 1082 | protected function getSysLanguageUid() |
||
| 1088 | } |
||
| 1089 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.