|
1
|
|
|
<?php |
|
2
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
|
12
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Registration; |
|
13
|
|
|
use DERHANSEN\SfEventMgt\Payment\AbstractPayment; |
|
14
|
|
|
use DERHANSEN\SfEventMgt\Utility\RegistrationResult; |
|
15
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
17
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; |
|
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
19
|
|
|
use TYPO3\CMS\Extbase\Reflection\ObjectAccess; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* RegistrationService |
|
23
|
|
|
* |
|
24
|
|
|
* @author Torben Hansen <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class RegistrationService |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* The object manager |
|
30
|
|
|
* |
|
31
|
|
|
* @var \TYPO3\CMS\Extbase\Object\ObjectManager |
|
32
|
|
|
* */ |
|
33
|
|
|
protected $objectManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* RegistrationRepository |
|
37
|
|
|
* |
|
38
|
|
|
* @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
|
39
|
|
|
* */ |
|
40
|
|
|
protected $registrationRepository; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* FrontendUserRepository |
|
44
|
|
|
* |
|
45
|
|
|
* @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository |
|
46
|
|
|
* */ |
|
47
|
|
|
protected $frontendUserRepository; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Hash Service |
|
51
|
|
|
* |
|
52
|
|
|
* @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService |
|
53
|
|
|
* */ |
|
54
|
|
|
protected $hashService; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Payment Service |
|
58
|
|
|
* |
|
59
|
|
|
* @var \DERHANSEN\SfEventMgt\Service\PaymentService |
|
60
|
|
|
* */ |
|
61
|
|
|
protected $paymentService; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* DI for $frontendUserRepository |
|
65
|
|
|
* |
|
66
|
|
|
* @param \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $frontendUserRepository |
|
67
|
|
|
*/ |
|
68
|
|
|
public function injectFrontendUserRepository( |
|
69
|
|
|
\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $frontendUserRepository |
|
70
|
|
|
) { |
|
71
|
|
|
$this->frontendUserRepository = $frontendUserRepository; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* DI for $hashService |
|
76
|
|
|
* |
|
77
|
|
|
* @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService |
|
78
|
2 |
|
*/ |
|
79
|
|
|
public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService) |
|
80
|
2 |
|
{ |
|
81
|
2 |
|
$this->hashService = $hashService; |
|
82
|
2 |
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
/** |
|
85
|
1 |
|
* DI for $objectManager |
|
86
|
1 |
|
* |
|
87
|
1 |
|
* @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager |
|
88
|
1 |
|
*/ |
|
89
|
|
|
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) |
|
90
|
2 |
|
{ |
|
91
|
2 |
|
$this->objectManager = $objectManager; |
|
92
|
2 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* DI for $paymentService |
|
96
|
|
|
* |
|
97
|
|
|
* @param \DERHANSEN\SfEventMgt\Service\PaymentService $paymentService |
|
98
|
|
|
*/ |
|
99
|
|
|
public function injectPaymentService(\DERHANSEN\SfEventMgt\Service\PaymentService $paymentService) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->paymentService = $paymentService; |
|
102
|
1 |
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
/** |
|
105
|
1 |
|
* DI for $registrationRepository |
|
106
|
|
|
* |
|
107
|
1 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository |
|
108
|
1 |
|
*/ |
|
109
|
1 |
|
public function injectRegistrationRepository( |
|
110
|
1 |
|
\DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository |
|
111
|
1 |
|
) { |
|
112
|
1 |
|
$this->registrationRepository = $registrationRepository; |
|
113
|
1 |
|
} |
|
114
|
1 |
|
|
|
115
|
1 |
|
/** |
|
116
|
1 |
|
* Duplicates (all public accessable properties) the given registration the |
|
117
|
1 |
|
* amount of times configured in amountOfRegistrations |
|
118
|
|
|
* |
|
119
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
120
|
|
|
* |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
public function createDependingRegistrations($registration) |
|
124
|
|
|
{ |
|
125
|
|
|
$registrations = $registration->getAmountOfRegistrations(); |
|
126
|
1 |
|
for ($i = 1; $i <= $registrations - 1; $i++) { |
|
127
|
|
|
/** @var \DERHANSEN\SfEventMgt\Domain\Model\Registration $newReg */ |
|
128
|
1 |
|
$newReg = $this->objectManager->get(Registration::class); |
|
129
|
1 |
|
$properties = ObjectAccess::getGettableProperties($registration); |
|
130
|
|
|
foreach ($properties as $propertyName => $propertyValue) { |
|
131
|
1 |
|
ObjectAccess::setProperty($newReg, $propertyName, $propertyValue); |
|
132
|
1 |
|
} |
|
133
|
1 |
|
$newReg->setMainRegistration($registration); |
|
134
|
1 |
|
$newReg->setAmountOfRegistrations(1); |
|
135
|
|
|
$newReg->setIgnoreNotifications(true); |
|
136
|
|
|
$newReg->_setProperty('_languageUid', $registration->_getProperty('_languageUid')); |
|
137
|
|
|
$this->registrationRepository->add($newReg); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Confirms all depending registrations based on the given main registration |
|
143
|
|
|
* |
|
144
|
4 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
145
|
|
|
* |
|
146
|
|
|
* @return void |
|
147
|
4 |
|
*/ |
|
148
|
4 |
|
public function confirmDependingRegistrations($registration) |
|
149
|
4 |
|
{ |
|
150
|
4 |
|
$registrations = $this->registrationRepository->findByMainRegistration($registration); |
|
|
|
|
|
|
151
|
|
|
foreach ($registrations as $foundRegistration) { |
|
152
|
4 |
|
/** @var \DERHANSEN\SfEventMgt\Domain\Model\Registration $foundRegistration */ |
|
153
|
1 |
|
$foundRegistration->setConfirmed(true); |
|
154
|
1 |
|
$this->registrationRepository->update($foundRegistration); |
|
155
|
1 |
|
} |
|
156
|
1 |
|
} |
|
157
|
3 |
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Checks if the registration can be confirmed and returns an array of variables |
|
160
|
4 |
|
* |
|
161
|
1 |
|
* @param int $reguid UID of registration |
|
162
|
1 |
|
* @param string $hmac HMAC for parameters |
|
163
|
1 |
|
* |
|
164
|
1 |
|
* @return array |
|
165
|
|
|
*/ |
|
166
|
4 |
|
public function checkConfirmRegistration($reguid, $hmac) |
|
167
|
1 |
|
{ |
|
168
|
1 |
|
/* @var $registration Registration */ |
|
169
|
1 |
|
$registration = null; |
|
170
|
1 |
|
$failed = false; |
|
171
|
|
|
$messageKey = 'event.message.confirmation_successful'; |
|
172
|
4 |
|
$titleKey = 'confirmRegistration.title.successful'; |
|
173
|
1 |
|
|
|
174
|
1 |
|
if (!$this->hashService->validateHmac('reg-' . $reguid, $hmac)) { |
|
175
|
1 |
|
$failed = true; |
|
176
|
1 |
|
$messageKey = 'event.message.confirmation_failed_wrong_hmac'; |
|
177
|
|
|
$titleKey = 'confirmRegistration.title.failed'; |
|
178
|
4 |
|
} else { |
|
179
|
|
|
$registration = $this->registrationRepository->findByUid($reguid); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
if (!$failed && is_null($registration)) { |
|
183
|
|
|
$failed = true; |
|
184
|
4 |
|
$messageKey = 'event.message.confirmation_failed_registration_not_found'; |
|
185
|
4 |
|
$titleKey = 'confirmRegistration.title.failed'; |
|
186
|
4 |
|
} |
|
187
|
|
|
|
|
188
|
4 |
|
if (!$failed && $registration->getConfirmationUntil() < new \DateTime()) { |
|
189
|
|
|
$failed = true; |
|
190
|
|
|
$messageKey = 'event.message.confirmation_failed_confirmation_until_expired'; |
|
191
|
|
|
$titleKey = 'confirmRegistration.title.failed'; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if (!$failed && $registration->getConfirmed() === true) { |
|
195
|
|
|
$failed = true; |
|
196
|
|
|
$messageKey = 'event.message.confirmation_failed_already_confirmed'; |
|
197
|
|
|
$titleKey = 'confirmRegistration.title.failed'; |
|
198
|
1 |
|
} |
|
199
|
|
|
|
|
200
|
1 |
|
if (!$failed && $registration->getWaitlist()) { |
|
201
|
1 |
|
$messageKey = 'event.message.confirmation_waitlist_successful'; |
|
202
|
1 |
|
$titleKey = 'confirmRegistrationWaitlist.title.successful'; |
|
203
|
1 |
|
} |
|
204
|
1 |
|
|
|
205
|
|
|
return [ |
|
206
|
|
|
$failed, |
|
207
|
|
|
$registration, |
|
208
|
|
|
$messageKey, |
|
209
|
|
|
$titleKey |
|
210
|
|
|
]; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
4 |
|
* Cancels all depending registrations based on the given main registration |
|
215
|
|
|
* |
|
216
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
217
|
4 |
|
* |
|
218
|
4 |
|
* @return void |
|
219
|
4 |
|
*/ |
|
220
|
4 |
|
public function cancelDependingRegistrations($registration) |
|
221
|
|
|
{ |
|
222
|
4 |
|
$registrations = $this->registrationRepository->findByMainRegistration($registration); |
|
|
|
|
|
|
223
|
1 |
|
foreach ($registrations as $foundRegistration) { |
|
224
|
1 |
|
$this->registrationRepository->remove($foundRegistration); |
|
225
|
1 |
|
} |
|
226
|
1 |
|
} |
|
227
|
3 |
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Checks if the registration can be cancelled and returns an array of variables |
|
230
|
4 |
|
* |
|
231
|
1 |
|
* @param int $reguid UID of registration |
|
232
|
1 |
|
* @param string $hmac HMAC for parameters |
|
233
|
1 |
|
* |
|
234
|
1 |
|
* @return array |
|
235
|
|
|
*/ |
|
236
|
4 |
|
public function checkCancelRegistration($reguid, $hmac) |
|
237
|
1 |
|
{ |
|
238
|
1 |
|
/* @var $registration Registration */ |
|
239
|
1 |
|
$registration = null; |
|
240
|
1 |
|
$failed = false; |
|
241
|
|
|
$messageKey = 'event.message.cancel_successful'; |
|
242
|
4 |
|
$titleKey = 'cancelRegistration.title.successful'; |
|
243
|
4 |
|
|
|
244
|
4 |
|
if (!$this->hashService->validateHmac('reg-' . $reguid, $hmac)) { |
|
245
|
1 |
|
$failed = true; |
|
246
|
1 |
|
$messageKey = 'event.message.cancel_failed_wrong_hmac'; |
|
247
|
1 |
|
$titleKey = 'cancelRegistration.title.failed'; |
|
248
|
1 |
|
} else { |
|
249
|
|
|
$registration = $this->registrationRepository->findByUid($reguid); |
|
250
|
|
|
} |
|
251
|
4 |
|
|
|
252
|
4 |
|
if (!$failed && is_null($registration)) { |
|
253
|
4 |
|
$failed = true; |
|
254
|
|
|
$messageKey = 'event.message.cancel_failed_registration_not_found_or_cancelled'; |
|
255
|
4 |
|
$titleKey = 'cancelRegistration.title.failed'; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
if (!$failed && $registration->getEvent()->getEnableCancel() === false) { |
|
259
|
|
|
$failed = true; |
|
260
|
|
|
$messageKey = 'event.message.confirmation_failed_cancel_disabled'; |
|
261
|
|
|
$titleKey = 'cancelRegistration.title.failed'; |
|
262
|
|
|
} |
|
263
|
5 |
|
|
|
264
|
|
|
if (!$failed && $registration->getEvent()->getCancelDeadline() > 0 |
|
265
|
5 |
|
&& $registration->getEvent()->getCancelDeadline() < new \DateTime() |
|
266
|
1 |
|
) { |
|
267
|
|
|
$failed = true; |
|
268
|
4 |
|
$messageKey = 'event.message.cancel_failed_deadline_expired'; |
|
269
|
|
|
$titleKey = 'cancelRegistration.title.failed'; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
if (!$failed && $registration->getEvent()->getStartdate() < new \DateTime()) { |
|
273
|
|
|
$failed = true; |
|
274
|
|
|
$messageKey = 'event.message.cancel_failed_event_started'; |
|
275
|
|
|
$titleKey = 'cancelRegistration.title.failed'; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
return [ |
|
279
|
|
|
$failed, |
|
280
|
|
|
$registration, |
|
281
|
|
|
$messageKey, |
|
282
|
19 |
|
$titleKey |
|
283
|
|
|
]; |
|
284
|
19 |
|
} |
|
285
|
19 |
|
|
|
286
|
2 |
|
/** |
|
287
|
2 |
|
* Returns the current frontend user object if available |
|
288
|
19 |
|
* |
|
289
|
2 |
|
* @return mixed \TYPO3\CMS\Extbase\Domain\Model\FrontendUser|null |
|
290
|
2 |
|
*/ |
|
291
|
17 |
|
public function getCurrentFeUserObject() |
|
292
|
2 |
|
{ |
|
293
|
2 |
|
if (isset($GLOBALS['TSFE']->fe_user->user['uid'])) { |
|
294
|
15 |
|
return $this->frontendUserRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']); |
|
295
|
13 |
|
} |
|
296
|
13 |
|
|
|
297
|
2 |
|
return null; |
|
298
|
2 |
|
} |
|
299
|
13 |
|
|
|
300
|
11 |
|
/** |
|
301
|
11 |
|
* Checks, if the registration can successfully be created. Note, that |
|
302
|
2 |
|
* $result is passed by reference! |
|
303
|
2 |
|
* |
|
304
|
11 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
305
|
2 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
306
|
2 |
|
* @param int $result Result |
|
307
|
9 |
|
* |
|
308
|
2 |
|
* @return array |
|
309
|
7 |
|
*/ |
|
310
|
2 |
|
public function checkRegistrationSuccess($event, $registration, $result) |
|
311
|
2 |
|
{ |
|
312
|
7 |
|
$success = true; |
|
313
|
5 |
|
if ($event->getEnableRegistration() === false) { |
|
314
|
5 |
|
$success = false; |
|
315
|
1 |
|
$result = RegistrationResult::REGISTRATION_NOT_ENABLED; |
|
316
|
1 |
|
} elseif ($event->getRegistrationDeadline() != null && $event->getRegistrationDeadline() < new \DateTime()) { |
|
317
|
19 |
|
$success = false; |
|
318
|
|
|
$result = RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED; |
|
319
|
|
|
} elseif ($event->getStartdate() < new \DateTime()) { |
|
320
|
|
|
$success = false; |
|
321
|
|
|
$result = RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED; |
|
322
|
|
|
} elseif ($event->getRegistrations()->count() >= $event->getMaxParticipants() |
|
323
|
|
|
&& $event->getMaxParticipants() > 0 && !$event->getEnableWaitlist() |
|
324
|
|
|
) { |
|
325
|
|
|
$success = false; |
|
326
|
|
|
$result = RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS; |
|
327
|
2 |
|
} elseif ($event->getFreePlaces() < $registration->getAmountOfRegistrations() |
|
328
|
|
|
&& $event->getMaxParticipants() > 0 && !$event->getEnableWaitlist() |
|
329
|
2 |
|
) { |
|
330
|
2 |
|
$success = false; |
|
331
|
|
|
$result = RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES; |
|
332
|
|
|
} elseif ($event->getMaxRegistrationsPerUser() < $registration->getAmountOfRegistrations()) { |
|
333
|
|
|
$success = false; |
|
334
|
|
|
$result = RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED; |
|
335
|
|
|
} elseif ($event->getUniqueEmailCheck() && |
|
336
|
|
|
$this->emailNotUnique($event, $registration->getEmail()) |
|
337
|
|
|
) { |
|
338
|
|
|
$success = false; |
|
339
|
2 |
|
$result = RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE; |
|
340
|
|
|
} elseif ($event->getRegistrations()->count() >= $event->getMaxParticipants() |
|
341
|
2 |
|
&& $event->getMaxParticipants() > 0 && $event->getEnableWaitlist() |
|
342
|
1 |
|
) { |
|
343
|
|
|
$result = RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
1 |
|
return [$success, $result]; |
|
347
|
1 |
|
} |
|
348
|
1 |
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* Returns if the given e-mail is registered to the given event |
|
351
|
|
|
* |
|
352
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
|
353
|
|
|
* @param string $email |
|
354
|
|
|
* @return bool |
|
355
|
|
|
*/ |
|
356
|
|
|
protected function emailNotUnique($event, $email) |
|
357
|
|
|
{ |
|
358
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
359
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
|
360
|
|
|
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class); |
|
361
|
|
|
$registrations = $queryBuilder->count('email') |
|
362
|
7 |
|
->from('tx_sfeventmgt_domain_model_registration') |
|
363
|
|
|
->where( |
|
364
|
7 |
|
$queryBuilder->expr()->eq( |
|
365
|
3 |
|
'event', |
|
366
|
|
|
$queryBuilder->createNamedParameter($event->getUid(), Connection::PARAM_INT) |
|
367
|
|
|
), |
|
368
|
4 |
|
$queryBuilder->expr()->eq( |
|
369
|
4 |
|
'email', |
|
370
|
1 |
|
$queryBuilder->createNamedParameter($email, Connection::PARAM_STR) |
|
371
|
4 |
|
) |
|
372
|
2 |
|
) |
|
373
|
2 |
|
->execute() |
|
374
|
4 |
|
->fetchColumn(); |
|
375
|
|
|
|
|
376
|
|
|
return $registrations >= 1; |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Returns, if payment redirect for the payment method is enabled |
|
381
|
|
|
* |
|
382
|
|
|
* @param Registration $registration |
|
383
|
|
|
* @return bool |
|
384
|
|
|
*/ |
|
385
|
|
|
public function redirectPaymentEnabled($registration) |
|
386
|
|
|
{ |
|
387
|
|
|
if ($registration->getEvent()->getEnablePayment() === false) { |
|
388
|
|
|
return false; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** @var AbstractPayment $paymentInstance */ |
|
392
|
|
|
$paymentInstance = $this->paymentService->getPaymentInstance($registration->getPaymentmethod()); |
|
393
|
|
|
if ($paymentInstance !== null && $paymentInstance->isRedirectEnabled()) { |
|
394
|
|
|
return true; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
return false; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Returns if the given amount of registrations for the event will be registrations for the waitlist |
|
402
|
|
|
* (depending on the total amount of registrations and free places) |
|
403
|
|
|
* |
|
404
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
|
405
|
|
|
* @param int $amountOfRegistrations |
|
406
|
|
|
* @return bool |
|
407
|
|
|
*/ |
|
408
|
|
|
public function isWaitlistRegistration($event, $amountOfRegistrations) |
|
409
|
|
|
{ |
|
410
|
|
|
if ($event->getMaxParticipants() === 0 || !$event->getEnableWaitlist()) { |
|
411
|
|
|
return false; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
$result = false; |
|
415
|
|
|
if (($event->getFreePlaces() > 0 && $event->getFreePlaces() < $amountOfRegistrations) |
|
416
|
|
|
|| $event->getFreePlaces() <= 0) { |
|
417
|
|
|
$result = true; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
return $result; |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
/** |
|
424
|
|
|
* Fixes the event uid of a registration if the event has been saved as a child of a translated event. |
|
425
|
|
|
* |
|
426
|
|
|
* Since TYPO3 9.5 (#82363), registrations for events are saved to the translated event record |
|
427
|
|
|
* |
|
428
|
|
|
* Example: |
|
429
|
|
|
* |
|
430
|
|
|
* When a registration is saved for a translated event, the registration $registration->setEvent($event) will |
|
431
|
|
|
* now save the UID of the translated event instead of the uid of the event in default language. |
|
432
|
|
|
* |
|
433
|
|
|
* This behavior breaks limitations on events (e.g. max participants). Therefore, the registration must always |
|
434
|
|
|
* be related to the default event language (Extbase behavior before TYPO3 9.5) |
|
435
|
|
|
* |
|
436
|
|
|
* @param Registration $registration |
|
437
|
|
|
* @param Event $event |
|
438
|
|
|
* @return void |
|
439
|
|
|
*/ |
|
440
|
|
|
public function fixRegistrationEvent(Registration $registration, Event $event) |
|
441
|
|
|
{ |
|
442
|
|
|
// Early return when event is in default language |
|
443
|
|
|
if ((int)$event->_getProperty('_languageUid') === 0) { |
|
444
|
|
|
return; |
|
445
|
|
|
} |
|
446
|
|
|
$this->updateRegistrationEventUid($registration, $event); |
|
447
|
|
|
$this->updateEventRegistrationCounters($event); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Ensures, that the field "sys_language_uid" for registration fields values has the same value as the |
|
452
|
|
|
* language of the registration and event. This is required, so emails include registration field values |
|
453
|
|
|
* and correct registration field labels in their translated state. |
|
454
|
|
|
* |
|
455
|
|
|
* @param Registration $registration |
|
456
|
|
|
* @param Event $event |
|
457
|
|
|
* @return void |
|
458
|
|
|
*/ |
|
459
|
|
|
public function fixRegistationFieldValueLanguage(Registration $registration, Event $event) |
|
460
|
|
|
{ |
|
461
|
|
|
// Early return when event is in default language or no registration fields |
|
462
|
|
|
if ((int)$event->_getProperty('_languageUid') === 0 || $event->getRegistrationFields()->count() === 0) { |
|
463
|
|
|
return; |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
$this->updateRegistrationFieldValueLanguage($registration, $event->_getProperty('_languageUid')); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* Updates the field "sys_language_uid" for all registration field values of the given registration |
|
471
|
|
|
* |
|
472
|
|
|
* @param Registration $registration |
|
473
|
|
|
* @param int $sysLanguageUid |
|
474
|
|
|
* @return void |
|
475
|
|
|
*/ |
|
476
|
|
|
protected function updateRegistrationFieldValueLanguage(Registration $registration, int $sysLanguageUid) |
|
477
|
|
|
{ |
|
478
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
479
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
|
480
|
|
|
$queryBuilder->update('tx_sfeventmgt_domain_model_registration_fieldvalue') |
|
481
|
|
|
->set('sys_language_uid', $sysLanguageUid) |
|
482
|
|
|
->where( |
|
483
|
|
|
$queryBuilder->expr()->eq( |
|
484
|
|
|
'registration', |
|
485
|
|
|
$queryBuilder->createNamedParameter($registration->getUid(), Connection::PARAM_INT) |
|
486
|
|
|
) |
|
487
|
|
|
) |
|
488
|
|
|
->execute(); |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* Sets the "event" field of the given registration to the uid of the given event |
|
493
|
|
|
* |
|
494
|
|
|
* @param Registration $registration |
|
495
|
|
|
* @param Event $event |
|
496
|
|
|
* @return void |
|
497
|
|
|
*/ |
|
498
|
|
|
protected function updateRegistrationEventUid(Registration $registration, Event $event) |
|
499
|
|
|
{ |
|
500
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
501
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
|
502
|
|
|
$queryBuilder->update('tx_sfeventmgt_domain_model_registration') |
|
503
|
|
|
->set('event', $event->getUid()) |
|
504
|
|
|
->where( |
|
505
|
|
|
$queryBuilder->expr()->eq( |
|
506
|
|
|
'uid', |
|
507
|
|
|
$queryBuilder->createNamedParameter($registration->getUid(), Connection::PARAM_INT) |
|
508
|
|
|
) |
|
509
|
|
|
) |
|
510
|
|
|
->execute(); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
/** |
|
514
|
|
|
* Updates registration/waitlist registration counters for the given event |
|
515
|
|
|
* |
|
516
|
|
|
* @param Event $event |
|
517
|
|
|
* @return void |
|
518
|
|
|
*/ |
|
519
|
|
|
protected function updateEventRegistrationCounters(Event $event) |
|
520
|
|
|
{ |
|
521
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
522
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_event'); |
|
523
|
|
|
|
|
524
|
|
|
$countRegistrations = $this->getEventRegistrationCount($event, 0); |
|
525
|
|
|
$countRegistrationsWaitlist = $this->getEventRegistrationCount($event, 1); |
|
526
|
|
|
|
|
527
|
|
|
$queryBuilder->update('tx_sfeventmgt_domain_model_event') |
|
528
|
|
|
->set('registration', $countRegistrations) |
|
529
|
|
|
->set('registration_waitlist', $countRegistrationsWaitlist) |
|
530
|
|
|
->where( |
|
531
|
|
|
$queryBuilder->expr()->eq( |
|
532
|
|
|
'uid', |
|
533
|
|
|
$queryBuilder->createNamedParameter($event->getUid(), Connection::PARAM_INT) |
|
534
|
|
|
) |
|
535
|
|
|
) |
|
536
|
|
|
->orWhere( |
|
537
|
|
|
$queryBuilder->expr()->eq( |
|
538
|
|
|
'l10n_parent', |
|
539
|
|
|
$queryBuilder->createNamedParameter($event->getUid(), Connection::PARAM_INT) |
|
540
|
|
|
) |
|
541
|
|
|
) |
|
542
|
|
|
->execute(); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* Returns the total amount of registrations/waitlist registrations for an event |
|
547
|
|
|
* |
|
548
|
|
|
* @param Event $event |
|
549
|
|
|
* @param int $waitlist |
|
550
|
|
|
* @return mixed |
|
551
|
|
|
*/ |
|
552
|
|
|
protected function getEventRegistrationCount(Event $event, int $waitlist = 0) |
|
553
|
|
|
{ |
|
554
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
555
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_registration'); |
|
556
|
|
|
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class); |
|
557
|
|
|
|
|
558
|
|
|
return $queryBuilder->count('uid') |
|
559
|
|
|
->from('tx_sfeventmgt_domain_model_registration') |
|
560
|
|
|
->where( |
|
561
|
|
|
$queryBuilder->expr()->eq( |
|
562
|
|
|
'event', |
|
563
|
|
|
$queryBuilder->createNamedParameter($event->getUid(), Connection::PARAM_INT) |
|
564
|
|
|
), |
|
565
|
|
|
$queryBuilder->expr()->eq( |
|
566
|
|
|
'waitlist', |
|
567
|
|
|
$queryBuilder->createNamedParameter($waitlist, Connection::PARAM_INT) |
|
568
|
|
|
) |
|
569
|
|
|
) |
|
570
|
|
|
->execute() |
|
571
|
|
|
->fetchColumn(); |
|
572
|
|
|
} |
|
573
|
|
|
} |
|
574
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: