@@ -83,6 +83,14 @@ class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
8383 */
8484 protected $ notificationService = NULL ;
8585
86+ /**
87+ * ICalendar Service
88+ *
89+ * @var \DERHANSEN\SfEventMgt\Service\ICalendarService
90+ * @inject
91+ */
92+ protected $ icalendarService = NULL ;
93+
8694 /**
8795 * Settings Service
8896 *
@@ -99,6 +107,14 @@ class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
99107 */
100108 protected $ hashService ;
101109
110+ /**
111+ * registrationService
112+ *
113+ * @var \DERHANSEN\SfEventMgt\Service\RegistrationService
114+ * @inject
115+ */
116+ protected $ registrationService = NULL ;
117+
102118 /**
103119 * Create a demand object with the given settings
104120 *
@@ -147,6 +163,18 @@ public function detailAction(Event $event) {
147163 $ this ->view ->assign ('event ' , $ event );
148164 }
149165
166+ /**
167+ * Initiates the iCalendar download for the given event
168+ *
169+ * @param Event $event The event
170+ *
171+ * @return bool
172+ */
173+ public function icalDownloadAction (Event $ event ) {
174+ $ this ->icalendarService ->downloadiCalendarFile ($ event );
175+ return FALSE ;
176+ }
177+
150178 /**
151179 * Registration view for an event
152180 *
@@ -182,22 +210,8 @@ public function initializeSaveRegistrationAction() {
182210 */
183211 public function saveRegistrationAction (Registration $ registration , Event $ event ) {
184212 $ autoConfirmation = (bool )$ this ->settings ['registration ' ]['autoConfirmation ' ];
185- $ success = TRUE ;
186213 $ result = RegistrationResult::REGISTRATION_SUCCESSFUL ;
187- if ($ event ->getEnableRegistration () === FALSE ) {
188- $ success = FALSE ;
189- $ result = RegistrationResult::REGISTRATION_NOT_ENABLED ;
190- } elseif ($ event ->getRegistrationDeadline () != NULL && $ event ->getRegistrationDeadline () < new \DateTime ()) {
191- $ success = FALSE ;
192- $ result = RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED ;
193- } elseif ($ event ->getStartdate () < new \DateTime ()) {
194- $ success = FALSE ;
195- $ result = RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED ;
196- } elseif ($ event ->getRegistration ()->count () >= $ event ->getMaxParticipants ()
197- && $ event ->getMaxParticipants () > 0 ) {
198- $ success = FALSE ;
199- $ result = RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS ;
200- }
214+ $ success = $ this ->checkRegistrationSuccess ($ event , $ registration , $ result );
201215
202216 // Save registration if no errors
203217 if ($ success ) {
@@ -225,6 +239,11 @@ public function saveRegistrationAction(Registration $registration, Event $event)
225239 MessageType::REGISTRATION_NEW );
226240 }
227241
242+ // Create given amount of registrations if necessary
243+ if ($ registration ->getAmountOfRegistrations () > 1 ) {
244+ $ this ->registrationService ->createDependingRegistrations ($ registration );
245+ }
246+
228247 // Clear cache for configured pages
229248 $ pidList = $ this ->settingsService ->getClearCacheUids ($ this ->settings );
230249 if (count ($ pidList ) > 0 ) {
@@ -242,6 +261,41 @@ public function saveRegistrationAction(Registration $registration, Event $event)
242261 }
243262 }
244263
264+ /**
265+ * Checks, if the registration can successfully be created. Note, that
266+ * $result is passed by reference!
267+ *
268+ * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event
269+ * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration
270+ * @param RegistrationResult $result
271+ *
272+ * @return bool
273+ */
274+ protected function checkRegistrationSuccess ($ event , $ registration , &$ result ) {
275+ $ success = TRUE ;
276+ if ($ event ->getEnableRegistration () === FALSE ) {
277+ $ success = FALSE ;
278+ $ result = RegistrationResult::REGISTRATION_NOT_ENABLED ;
279+ } elseif ($ event ->getRegistrationDeadline () != NULL && $ event ->getRegistrationDeadline () < new \DateTime ()) {
280+ $ success = FALSE ;
281+ $ result = RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED ;
282+ } elseif ($ event ->getStartdate () < new \DateTime ()) {
283+ $ success = FALSE ;
284+ $ result = RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED ;
285+ } elseif ($ event ->getRegistration ()->count () >= $ event ->getMaxParticipants ()
286+ && $ event ->getMaxParticipants () > 0 ) {
287+ $ success = FALSE ;
288+ $ result = RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS ;
289+ } elseif ($ event ->getFreePlaces () < $ registration ->getAmountOfRegistrations ()) {
290+ $ success = FALSE ;
291+ $ result = RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES ;
292+ } elseif ($ event ->getMaxRegistrationsPerUser () < $ registration ->getAmountOfRegistrations ()) {
293+ $ success = FALSE ;
294+ $ result = RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED ;
295+ }
296+ return $ success ;
297+ }
298+
245299 /**
246300 * Shows the result of the saveRegistrationAction
247301 *
@@ -270,6 +324,14 @@ public function saveRegistrationResultAction($result) {
270324 $ messageKey = 'event.message.registrationfaileddeadlineexpired ' ;
271325 $ titleKey = 'registrationResult.title.failed ' ;
272326 break ;
327+ case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES :
328+ $ messageKey = 'event.message.registrationfailednotenoughfreeplaces ' ;
329+ $ titleKey = 'registrationResult.title.failed ' ;
330+ break ;
331+ case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED :
332+ $ messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded ' ;
333+ $ titleKey = 'registrationResult.title.failed ' ;
334+ break ;
273335 default :
274336 $ messageKey = '' ;
275337 $ titleKey = '' ;
@@ -329,6 +391,11 @@ public function confirmRegistrationAction($reguid, $hmac) {
329391 MessageType::REGISTRATION_CONFIRMED );
330392 $ this ->notificationService ->sendAdminMessage ($ registration ->getEvent (), $ registration , $ this ->settings ,
331393 MessageType::REGISTRATION_CONFIRMED );
394+
395+ // Confirm registrations depending on main registration if necessary
396+ if ($ registration ->getAmountOfRegistrations () > 1 ) {
397+ $ this ->registrationService ->confirmDependingRegistrations ($ registration );
398+ }
332399 }
333400 $ this ->view ->assign ('messageKey ' , $ messageKey );
334401 $ this ->view ->assign ('titleKey ' , $ titleKey );
0 commit comments