1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Controller; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand; |
18
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand; |
19
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand; |
20
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand; |
21
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
22
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Registration; |
23
|
|
|
use DERHANSEN\SfEventMgt\Utility\RegistrationResult; |
24
|
|
|
use DERHANSEN\SfEventMgt\Utility\MessageType; |
25
|
|
|
use DERHANSEN\SfEventMgt\Utility\Page; |
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
27
|
|
|
use TYPO3\CMS\Core\Utility\HttpUtility; |
28
|
|
|
use TYPO3\CMS\Extbase\Mvc\RequestInterface; |
29
|
|
|
use TYPO3\CMS\Extbase\Mvc\ResponseInterface; |
30
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
31
|
|
|
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; |
32
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* EventController |
36
|
|
|
* |
37
|
|
|
* @author Torben Hansen <[email protected]> |
38
|
|
|
*/ |
39
|
|
|
class EventController extends AbstractController |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* Properties in this array will be ignored by overwriteDemandObject() |
43
|
|
|
* |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $ignoredSettingsForOverwriteDemand = ['storagepage', 'orderfieldallowed']; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Creates an event demand object with the given settings |
50
|
|
|
* |
51
|
|
|
* @param array $settings The settings |
52
|
|
|
* |
53
|
|
|
* @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
54
|
|
|
*/ |
55
|
|
|
public function createEventDemandObjectFromSettings(array $settings) |
56
|
|
|
{ |
57
|
|
|
/** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */ |
58
|
|
|
$demand = $this->objectManager->get(EventDemand::class); |
59
|
|
|
$demand->setDisplayMode($settings['displayMode']); |
60
|
|
|
$demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
61
|
|
|
$demand->setCategoryConjunction($settings['categoryConjunction']); |
62
|
|
|
$demand->setCategory($settings['category']); |
63
|
|
|
$demand->setIncludeSubcategories($settings['includeSubcategories']); |
64
|
|
|
$demand->setTopEventRestriction((int)$settings['topEventRestriction']); |
65
|
|
|
$demand->setOrderField($settings['orderField']); |
66
|
|
|
$demand->setOrderFieldAllowed($settings['orderFieldAllowed']); |
67
|
|
|
$demand->setOrderDirection($settings['orderDirection']); |
68
|
|
|
$demand->setQueryLimit($settings['queryLimit']); |
69
|
|
|
$demand->setLocation($settings['location']); |
70
|
|
|
$demand->setOrganisator($settings['organisator']); |
71
|
|
|
return $demand; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Creates a foreign record demand object with the given settings |
76
|
|
|
* |
77
|
|
|
* @param array $settings The settings |
78
|
|
|
* |
79
|
|
|
* @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
80
|
|
|
*/ |
81
|
|
|
public function createForeignRecordDemandObjectFromSettings(array $settings) |
82
|
|
|
{ |
83
|
|
|
/** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */ |
84
|
|
|
$demand = $this->objectManager->get(ForeignRecordDemand::class); |
85
|
|
|
$demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
86
|
|
|
$demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']); |
87
|
|
|
return $demand; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Creates a category demand object with the given settings |
92
|
|
|
* |
93
|
|
|
* @param array $settings The settings |
94
|
|
|
* |
95
|
|
|
* @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
96
|
|
|
*/ |
97
|
|
|
public function createCategoryDemandObjectFromSettings(array $settings) |
98
|
|
|
{ |
99
|
|
|
/** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */ |
100
|
|
|
$demand = $this->objectManager->get(CategoryDemand::class); |
101
|
|
|
$demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive'])); |
102
|
|
|
$demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']); |
103
|
|
|
$demand->setCategories($settings['categoryMenu']['categories']); |
104
|
|
|
$demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']); |
105
|
|
|
return $demand; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Overwrites a given demand object by an propertyName => $propertyValue array |
110
|
|
|
* |
111
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand |
112
|
|
|
* @param array $overwriteDemand OwerwriteDemand |
113
|
|
|
* |
114
|
|
|
* @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
115
|
|
|
*/ |
116
|
|
|
protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand) |
117
|
|
|
{ |
118
|
|
|
foreach ($this->ignoredSettingsForOverwriteDemand as $property) { |
119
|
|
|
unset($overwriteDemand[$property]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
foreach ($overwriteDemand as $propertyName => $propertyValue) { |
123
|
|
|
if (in_array(strtolower($propertyName), $this->ignoredSettingsForOverwriteDemand, true)) { |
124
|
|
|
continue; |
125
|
|
|
} |
126
|
|
|
\TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue); |
127
|
|
|
} |
128
|
|
|
return $demand; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Hook into request processing and catch exceptions |
133
|
|
|
* |
134
|
|
|
* @param RequestInterface $request |
135
|
|
|
* @param ResponseInterface $response |
136
|
|
|
* @throws \Exception |
137
|
1 |
|
*/ |
138
|
|
|
public function processRequest(RequestInterface $request, ResponseInterface $response) |
139
|
|
|
{ |
140
|
1 |
|
try { |
141
|
1 |
|
parent::processRequest($request, $response); |
142
|
1 |
|
} catch (\Exception $exception) { |
143
|
1 |
|
$this->handleKnownExceptionsElseThrowAgain($exception); |
144
|
1 |
|
} |
145
|
1 |
|
} |
146
|
1 |
|
|
147
|
1 |
|
/** |
148
|
1 |
|
* Handle known exceptions |
149
|
1 |
|
* |
150
|
1 |
|
* @param \Exception $exception |
151
|
|
|
* @throws \Exception |
152
|
|
|
*/ |
153
|
|
|
private function handleKnownExceptionsElseThrowAgain(\Exception $exception) |
154
|
|
|
{ |
155
|
|
|
$previousException = $exception->getPrevious(); |
156
|
|
|
if (($this->actionMethodName === 'detailAction' || $this->actionMethodName === 'registrationAction') |
157
|
|
|
&& $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception |
158
|
|
|
) { |
159
|
|
|
$this->handleEventNotFoundError($this->settings); |
160
|
|
|
} else { |
161
|
|
|
throw $exception; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Initialize list action and set format |
167
|
|
|
* |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
public function initializeListAction() |
171
|
|
|
{ |
172
|
|
|
if (isset($this->settings['list']['format'])) { |
173
|
|
|
$this->request->setFormat($this->settings['list']['format']); |
174
|
|
|
} |
175
|
|
|
} |
176
|
1 |
|
|
177
|
|
|
/** |
178
|
|
|
* List view |
179
|
1 |
|
* |
180
|
1 |
|
* @param array $overwriteDemand OverwriteDemand |
181
|
1 |
|
* |
182
|
1 |
|
* @return void |
183
|
1 |
|
*/ |
184
|
1 |
|
public function listAction(array $overwriteDemand = []) |
185
|
|
|
{ |
186
|
|
|
$eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
187
|
|
|
$foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
188
|
|
|
$categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
189
|
|
|
if ($this->isOverwriteDemand($overwriteDemand)) { |
190
|
|
|
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
191
|
|
|
} |
192
|
|
|
$events = $this->eventRepository->findDemanded($eventDemand); |
193
|
|
|
$categories = $this->categoryRepository->findDemanded($categoryDemand); |
194
|
|
|
$locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
195
|
2 |
|
$organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
196
|
|
|
$this->view->assignMultiple([ |
197
|
2 |
|
'events' => $events, |
198
|
2 |
|
'categories' => $categories, |
199
|
2 |
|
'locations' => $locations, |
200
|
|
|
'organisators' => $organisators, |
201
|
2 |
|
'overwriteDemand' => $overwriteDemand, |
202
|
2 |
|
'eventDemand' => $eventDemand |
203
|
2 |
|
]); |
204
|
2 |
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Calendar view |
208
|
|
|
* |
209
|
|
|
* @param array $overwriteDemand OverwriteDemand |
210
|
|
|
* |
211
|
|
|
* @return void |
212
|
|
|
*/ |
213
|
|
|
public function calendarAction(array $overwriteDemand = []) |
214
|
|
|
{ |
215
|
|
|
$eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
216
|
|
|
$foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
217
|
|
|
$categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
218
|
|
|
if ($this->isOverwriteDemand($overwriteDemand)) { |
219
|
|
|
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
// Set month/year to demand if not given |
223
|
|
|
if (!$eventDemand->getMonth()) { |
224
|
|
|
$currentMonth = date('n'); |
225
|
|
|
$eventDemand->setMonth($currentMonth); |
226
|
3 |
|
} else { |
227
|
|
|
$currentMonth = $eventDemand->getMonth(); |
228
|
3 |
|
} |
229
|
3 |
|
if (!$eventDemand->getYear()) { |
230
|
3 |
|
$currentYear = date('Y'); |
231
|
3 |
|
$eventDemand->setYear($currentYear); |
232
|
1 |
|
} else { |
233
|
1 |
|
$currentYear = $eventDemand->getYear(); |
234
|
3 |
|
} |
235
|
3 |
|
|
236
|
3 |
|
// Set demand from calendar date range instead of month / year |
237
|
3 |
|
if ((bool)$this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks']) { |
238
|
3 |
|
$eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand); |
239
|
3 |
|
} |
240
|
3 |
|
|
241
|
3 |
|
$events = $this->eventRepository->findDemanded($eventDemand); |
242
|
|
|
$weeks = $this->calendarService->getCalendarArray( |
243
|
|
|
$currentMonth, |
244
|
|
|
$currentYear, |
245
|
|
|
strtotime('today midnight'), |
246
|
|
|
(int)$this->settings['calendar']['firstDayOfWeek'], |
247
|
|
|
$events |
248
|
|
|
); |
249
|
|
|
|
250
|
1 |
|
$values = [ |
251
|
|
|
'weeks' => $weeks, |
252
|
1 |
|
'categories' => $this->categoryRepository->findDemanded($categoryDemand), |
253
|
1 |
|
'locations' => $this->locationRepository->findDemanded($foreignRecordDemand), |
254
|
|
|
'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand), |
255
|
|
|
'eventDemand' => $eventDemand, |
256
|
|
|
'overwriteDemand' => $overwriteDemand, |
257
|
|
|
'currentPageId' => $GLOBALS['TSFE']->id, |
258
|
|
|
'firstDayOfMonth' => \DateTime::createFromFormat('d.m.Y', sprintf('1.%s.%s', $currentMonth, $currentMonth)), |
259
|
|
|
'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'), |
260
|
|
|
'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month') |
261
|
|
|
]; |
262
|
1 |
|
|
263
|
|
|
$this->view->assignMultiple($values); |
264
|
1 |
|
} |
265
|
1 |
|
|
266
|
|
|
/** |
267
|
|
|
* Changes the given event demand object to select a date range for a calendar month including days of the previous |
268
|
|
|
* month for the first week and they days for the next month for the last week |
269
|
|
|
* |
270
|
|
|
* @param EventDemand $eventDemand |
271
|
|
|
* @return EventDemand |
272
|
|
|
*/ |
273
|
|
|
protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
274
|
|
|
{ |
275
|
1 |
|
$calendarDateRange = $this->calendarService->getCalendarDateRange( |
276
|
|
|
$eventDemand->getMonth(), |
277
|
1 |
|
$eventDemand->getYear(), |
278
|
|
|
$this->settings['calendar']['firstDayOfWeek'] |
279
|
|
|
); |
280
|
1 |
|
|
281
|
|
|
$eventDemand->setMonth(0); |
282
|
1 |
|
$eventDemand->setYear(0); |
283
|
1 |
|
|
284
|
1 |
|
$startDate = new \DateTime(); |
285
|
|
|
$startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']); |
286
|
|
|
$endDate = new \DateTime(); |
287
|
|
|
$endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']); |
288
|
|
|
$endDate->setTime(23, 59, 59); |
289
|
|
|
|
290
|
|
|
$searchDemand = new SearchDemand(); |
291
|
1 |
|
$searchDemand->setStartDate($startDate); |
292
|
|
|
$searchDemand->setEndDate($endDate); |
293
|
1 |
|
$eventDemand->setSearchDemand($searchDemand); |
294
|
1 |
|
return $eventDemand; |
295
|
1 |
|
} |
296
|
1 |
|
|
297
|
1 |
|
/** |
298
|
1 |
|
* Detail view for an event |
299
|
1 |
|
* |
300
|
1 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
301
|
|
|
* @return string |
302
|
|
|
*/ |
303
|
|
|
public function detailAction(Event $event = null) |
304
|
|
|
{ |
305
|
|
|
if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
306
|
|
|
return $this->handleEventNotFoundError($this->settings); |
307
|
|
|
} |
308
|
|
|
$this->view->assign('event', $event); |
309
|
|
|
} |
310
|
|
|
|
311
|
11 |
|
/** |
312
|
|
|
* Error handling if event is not found |
313
|
11 |
|
* |
314
|
11 |
|
* @param array $settings |
315
|
11 |
|
* @return string |
316
|
|
|
*/ |
317
|
|
|
protected function handleEventNotFoundError($settings) |
318
|
11 |
|
{ |
319
|
4 |
|
if (empty($settings['event']['errorHandling'])) { |
320
|
4 |
|
return null; |
321
|
4 |
|
} |
322
|
4 |
|
|
323
|
4 |
|
$configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true); |
324
|
4 |
|
|
325
|
|
|
switch ($configuration[0]) { |
326
|
4 |
|
case 'redirectToListView': |
327
|
4 |
|
$listPid = (int)$settings['listPid'] > 0 ? (int)$settings['listPid'] : 1; |
328
|
4 |
|
$this->redirect('list', null, null, null, $listPid); |
329
|
4 |
|
break; |
330
|
|
|
case 'pageNotFoundHandler': |
331
|
4 |
|
$GLOBALS['TSFE']->pageNotFoundAndExit('Event not found.'); |
332
|
4 |
|
break; |
333
|
4 |
|
case 'showStandaloneTemplate': |
334
|
4 |
|
if (isset($configuration[2])) { |
335
|
4 |
|
$statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $configuration[2]); |
336
|
4 |
|
HttpUtility::setResponseCode($statusCode); |
337
|
4 |
|
} |
338
|
4 |
|
$standaloneTemplate = $this->objectManager->get(StandaloneView::class); |
339
|
|
|
$standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1])); |
340
|
|
|
return $standaloneTemplate->render(); |
341
|
4 |
|
break; |
|
|
|
|
342
|
|
|
default: |
343
|
|
|
} |
344
|
4 |
|
} |
345
|
1 |
|
|
346
|
1 |
|
/** |
347
|
1 |
|
* Initiates the iCalendar download for the given event |
348
|
3 |
|
* |
349
|
3 |
|
* @param Event $event The event |
350
|
|
|
* |
351
|
4 |
|
* @return bool |
352
|
|
|
*/ |
353
|
|
|
public function icalDownloadAction(Event $event) |
354
|
4 |
|
{ |
355
|
3 |
|
$this->icalendarService->downloadiCalendarFile($event); |
356
|
3 |
|
return false; |
357
|
3 |
|
} |
358
|
3 |
|
|
359
|
|
|
/** |
360
|
3 |
|
* Registration view for an event |
361
|
3 |
|
* |
362
|
3 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
363
|
3 |
|
* |
364
|
3 |
|
* @return string |
365
|
|
|
*/ |
366
|
3 |
|
public function registrationAction(Event $event = null) |
367
|
3 |
|
{ |
368
|
|
|
if (is_null($event) && isset($this->settings['event']['errorHandling'])) { |
369
|
|
|
return $this->handleEventNotFoundError($this->settings); |
370
|
4 |
|
} |
371
|
1 |
|
if ($event->getRestrictPaymentMethods()) { |
|
|
|
|
372
|
1 |
|
$paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event); |
|
|
|
|
373
|
|
|
} else { |
374
|
|
|
$paymentMethods = $this->paymentService->getPaymentMethods(); |
375
|
4 |
|
} |
376
|
4 |
|
|
377
|
|
|
$this->view->assignMultiple([ |
378
|
11 |
|
'event' => $event, |
379
|
1 |
|
'paymentMethods' => $paymentMethods, |
380
|
1 |
|
]); |
381
|
1 |
|
} |
382
|
1 |
|
|
383
|
|
|
/** |
384
|
1 |
|
* Set date format for field dateOfBirth |
385
|
1 |
|
* |
386
|
1 |
|
* @return void |
387
|
1 |
|
*/ |
388
|
1 |
|
public function initializeSaveRegistrationAction() |
389
|
10 |
|
{ |
390
|
10 |
|
$this->arguments->getArgument('registration') |
391
|
10 |
|
->getPropertyMappingConfiguration()->forProperty('dateOfBirth') |
392
|
10 |
|
->setTypeConverterOption( |
393
|
10 |
|
DateTimeConverter::class, |
394
|
10 |
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
395
|
|
|
$this->settings['registration']['formatDateOfBirth'] |
396
|
11 |
|
); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Saves the registration |
401
|
|
|
* |
402
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
403
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
404
|
|
|
* @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
405
|
9 |
|
* |
406
|
|
|
* @return void |
407
|
|
|
*/ |
408
|
9 |
|
public function saveRegistrationAction(Registration $registration, Event $event) |
409
|
1 |
|
{ |
410
|
1 |
|
$autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm(); |
411
|
1 |
|
$result = RegistrationResult::REGISTRATION_SUCCESSFUL; |
412
|
8 |
|
$success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); |
413
|
|
|
|
414
|
|
|
// Save registration if no errors |
415
|
|
|
if ($success) { |
416
|
8 |
|
$isWaitlistRegistration = $this->registrationService->isWaitlistRegistration( |
417
|
1 |
|
$event, |
418
|
1 |
|
$registration->getAmountOfRegistrations() |
419
|
1 |
|
); |
420
|
7 |
|
$linkValidity = (int)$this->settings['confirmation']['linkValidity']; |
421
|
1 |
|
if ($linkValidity === 0) { |
422
|
1 |
|
// Use 3600 seconds as default value if not set |
423
|
1 |
|
$linkValidity = 3600; |
424
|
6 |
|
} |
425
|
1 |
|
$confirmationUntil = new \DateTime(); |
426
|
1 |
|
$confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); |
427
|
1 |
|
|
428
|
5 |
|
$registration->setEvent($event); |
429
|
1 |
|
$registration->setPid($event->getPid()); |
430
|
1 |
|
$registration->setConfirmationUntil($confirmationUntil); |
431
|
1 |
|
$registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); |
432
|
4 |
|
$registration->setFeUser($this->registrationService->getCurrentFeUserObject()); |
|
|
|
|
433
|
1 |
|
$registration->setWaitlist($isWaitlistRegistration); |
434
|
1 |
|
$registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid); |
435
|
1 |
|
$this->registrationRepository->add($registration); |
436
|
3 |
|
|
437
|
1 |
|
// Persist registration, so we have an UID |
438
|
1 |
|
$this->objectManager->get(PersistenceManager::class)->persistAll(); |
439
|
1 |
|
|
440
|
2 |
|
// Add new registration (or waitlist registration) to event |
441
|
1 |
|
if ($isWaitlistRegistration) { |
442
|
1 |
|
$event->addRegistrationWaitlist($registration); |
443
|
1 |
|
$messageType = MessageType::REGISTRATION_WAITLIST_NEW; |
444
|
1 |
|
} else { |
445
|
1 |
|
$event->addRegistration($registration); |
446
|
1 |
|
$messageType = MessageType::REGISTRATION_NEW; |
447
|
1 |
|
} |
448
|
|
|
$this->eventRepository->update($event); |
449
|
9 |
|
|
450
|
9 |
|
// Send notifications to user and admin if confirmation link should be sent |
451
|
9 |
|
if (!$autoConfirmation) { |
452
|
|
|
$this->notificationService->sendUserMessage( |
453
|
|
|
$event, |
454
|
|
|
$registration, |
455
|
|
|
$this->settings, |
456
|
|
|
$messageType |
457
|
|
|
); |
458
|
|
|
$this->notificationService->sendAdminMessage( |
459
|
|
|
$event, |
460
|
|
|
$registration, |
461
|
3 |
|
$this->settings, |
462
|
|
|
$messageType |
463
|
|
|
); |
464
|
3 |
|
} |
465
|
|
|
|
466
|
3 |
|
// Create given amount of registrations if necessary |
467
|
2 |
|
if ($registration->getAmountOfRegistrations() > 1) { |
468
|
2 |
|
$this->registrationService->createDependingRegistrations($registration); |
469
|
|
|
} |
470
|
2 |
|
|
471
|
2 |
|
// Clear cache for configured pages |
472
|
1 |
|
$this->utilityService->clearCacheForConfiguredUids($this->settings); |
473
|
1 |
|
} |
474
|
|
|
|
475
|
|
|
if ($autoConfirmation && $success) { |
476
|
2 |
|
$this->redirect( |
477
|
2 |
|
'confirmRegistration', |
478
|
2 |
|
null, |
479
|
2 |
|
null, |
480
|
|
|
[ |
481
|
2 |
|
'reguid' => $registration->getUid(), |
482
|
2 |
|
'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()) |
483
|
2 |
|
] |
484
|
2 |
|
); |
485
|
2 |
|
} else { |
486
|
|
|
$this->redirect( |
487
|
2 |
|
'saveRegistrationResult', |
488
|
|
|
null, |
489
|
|
|
null, |
490
|
2 |
|
[ |
491
|
2 |
|
'result' => $result, |
492
|
2 |
|
'eventuid' => $event->getUid(), |
493
|
2 |
|
'hmac' => $this->hashService->generateHmac('event-' . $event->getUid()) |
494
|
|
|
] |
495
|
|
|
); |
496
|
3 |
|
} |
497
|
3 |
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* Shows the result of the saveRegistrationAction |
501
|
|
|
* |
502
|
|
|
* @param int $result Result |
503
|
|
|
* @param int $eventuid |
504
|
|
|
* @param string $hmac |
505
|
|
|
* |
506
|
|
|
* @return void |
507
|
|
|
*/ |
508
|
|
|
public function saveRegistrationResultAction($result, $eventuid, $hmac) |
509
|
|
|
{ |
510
|
|
|
$event = null; |
511
|
|
|
|
512
|
|
|
switch ($result) { |
513
|
|
|
case RegistrationResult::REGISTRATION_SUCCESSFUL: |
514
|
3 |
|
$messageKey = 'event.message.registrationsuccessful'; |
515
|
3 |
|
$titleKey = 'registrationResult.title.successful'; |
516
|
3 |
|
break; |
517
|
|
|
case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST: |
518
|
|
|
$messageKey = 'event.message.registrationwaitlistsuccessful'; |
519
|
|
|
$titleKey = 'registrationWaitlistResult.title.successful'; |
520
|
|
|
break; |
521
|
|
|
case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED: |
522
|
|
|
$messageKey = 'event.message.registrationfailedeventexpired'; |
523
|
|
|
$titleKey = 'registrationResult.title.failed'; |
524
|
|
|
break; |
525
|
|
|
case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS: |
526
|
2 |
|
$messageKey = 'event.message.registrationfailedmaxparticipants'; |
527
|
|
|
$titleKey = 'registrationResult.title.failed'; |
528
|
|
|
break; |
529
|
2 |
|
case RegistrationResult::REGISTRATION_NOT_ENABLED: |
530
|
|
|
$messageKey = 'event.message.registrationfailednotenabled'; |
531
|
2 |
|
$titleKey = 'registrationResult.title.failed'; |
532
|
|
|
break; |
533
|
1 |
|
case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED: |
534
|
1 |
|
$messageKey = 'event.message.registrationfaileddeadlineexpired'; |
535
|
1 |
|
$titleKey = 'registrationResult.title.failed'; |
536
|
1 |
|
break; |
537
|
|
|
case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES: |
538
|
1 |
|
$messageKey = 'event.message.registrationfailednotenoughfreeplaces'; |
539
|
1 |
|
$titleKey = 'registrationResult.title.failed'; |
540
|
1 |
|
break; |
541
|
1 |
|
case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED: |
542
|
1 |
|
$messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded'; |
543
|
|
|
$titleKey = 'registrationResult.title.failed'; |
544
|
1 |
|
break; |
545
|
|
|
case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE: |
546
|
|
|
$messageKey = 'event.message.registrationfailedemailnotunique'; |
547
|
1 |
|
$titleKey = 'registrationResult.title.failed'; |
548
|
1 |
|
break; |
549
|
1 |
|
default: |
550
|
|
|
$messageKey = ''; |
551
|
|
|
$titleKey = ''; |
552
|
1 |
|
} |
553
|
|
|
|
554
|
|
|
if (!$this->hashService->validateHmac('event-' . $eventuid, $hmac)) { |
555
|
1 |
|
$messageKey = 'event.message.registrationsuccessfulwrongeventhmac'; |
556
|
1 |
|
$titleKey = 'registrationResult.title.failed'; |
557
|
2 |
|
} else { |
558
|
2 |
|
$event = $this->eventRepository->findByUid((int)$eventuid); |
559
|
2 |
|
} |
560
|
|
|
|
561
|
|
|
$this->view->assignMultiple([ |
562
|
|
|
'messageKey' => $messageKey, |
563
|
|
|
'titleKey' => $titleKey, |
564
|
|
|
'event' => $event, |
565
|
|
|
]); |
566
|
1 |
|
} |
567
|
|
|
|
568
|
1 |
|
/** |
569
|
1 |
|
* Confirms the registration if possible and sends e-mails to admin and user |
570
|
1 |
|
* |
571
|
1 |
|
* @param int $reguid UID of registration |
572
|
1 |
|
* @param string $hmac HMAC for parameters |
573
|
1 |
|
* |
574
|
1 |
|
* @return void |
575
|
1 |
|
*/ |
576
|
1 |
|
public function confirmRegistrationAction($reguid, $hmac) |
577
|
1 |
|
{ |
578
|
1 |
|
$event = null; |
579
|
1 |
|
|
580
|
1 |
|
/* @var $registration Registration */ |
581
|
1 |
|
list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration( |
582
|
1 |
|
$reguid, |
583
|
1 |
|
$hmac |
584
|
1 |
|
); |
585
|
|
|
|
586
|
|
|
if ($failed === false) { |
587
|
|
|
$registration->setConfirmed(true); |
588
|
|
|
$event = $registration->getEvent(); |
589
|
|
|
$this->registrationRepository->update($registration); |
590
|
|
|
|
591
|
|
|
$messageType = MessageType::REGISTRATION_CONFIRMED; |
592
|
|
|
if ($registration->getWaitlist()) { |
593
|
|
|
$messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED; |
594
|
6 |
|
} |
595
|
|
|
|
596
|
6 |
|
// Send notifications to user and admin |
597
|
6 |
|
$this->notificationService->sendUserMessage( |
598
|
6 |
|
$registration->getEvent(), |
599
|
6 |
|
$registration, |
600
|
|
|
$this->settings, |
601
|
6 |
|
$messageType |
602
|
5 |
|
); |
603
|
|
|
$this->notificationService->sendAdminMessage( |
604
|
5 |
|
$registration->getEvent(), |
605
|
1 |
|
$registration, |
606
|
1 |
|
$this->settings, |
607
|
|
|
$messageType |
608
|
5 |
|
); |
609
|
1 |
|
|
610
|
1 |
|
// Confirm registrations depending on main registration if necessary |
611
|
5 |
|
if ($registration->getAmountOfRegistrations() > 1) { |
612
|
|
|
$this->registrationService->confirmDependingRegistrations($registration); |
613
|
6 |
|
} |
614
|
1 |
|
} |
615
|
1 |
|
|
616
|
|
|
// Redirect to payment provider if payment/redirect is enabled |
617
|
6 |
|
$paymentPid = (int)$this->settings['paymentPid']; |
618
|
6 |
|
if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) { |
619
|
|
|
$this->uriBuilder->reset() |
620
|
6 |
|
->setTargetPageUid($paymentPid) |
621
|
|
|
->setUseCacheHash(false); |
622
|
6 |
|
$uri = $this->uriBuilder->uriFor( |
623
|
6 |
|
'redirect', |
624
|
6 |
|
[ |
625
|
6 |
|
'registration' => $registration, |
626
|
6 |
|
'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid()) |
627
|
6 |
|
], |
628
|
|
|
'Payment', |
629
|
|
|
'sfeventmgt', |
630
|
|
|
'Pipayment' |
631
|
|
|
); |
632
|
|
|
$this->redirectToUri($uri); |
633
|
|
|
} |
634
|
|
|
|
635
|
9 |
|
$this->view->assignMultiple([ |
636
|
|
|
'messageKey' => $messageKey, |
637
|
9 |
|
'titleKey' => $titleKey, |
638
|
|
|
'event' => $event, |
639
|
|
|
]); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* Cancels the registration if possible and sends e-mails to admin and user |
644
|
|
|
* |
645
|
|
|
* @param int $reguid UID of registration |
646
|
|
|
* @param string $hmac HMAC for parameters |
647
|
|
|
* |
648
|
|
|
* @return void |
649
|
|
|
*/ |
650
|
|
|
public function cancelRegistrationAction($reguid, $hmac) |
651
|
|
|
{ |
652
|
|
|
$event = null; |
653
|
|
|
|
654
|
|
|
/* @var $registration Registration */ |
655
|
|
|
list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkCancelRegistration($reguid, $hmac); |
656
|
|
|
|
657
|
|
|
if ($failed === false) { |
658
|
|
|
$event = $registration->getEvent(); |
659
|
|
|
|
660
|
|
|
// Send notifications (must run before cancelling the registration) |
661
|
|
|
$this->notificationService->sendUserMessage( |
662
|
|
|
$registration->getEvent(), |
663
|
|
|
$registration, |
664
|
|
|
$this->settings, |
665
|
|
|
MessageType::REGISTRATION_CANCELLED |
666
|
|
|
); |
667
|
|
|
$this->notificationService->sendAdminMessage( |
668
|
|
|
$registration->getEvent(), |
669
|
|
|
$registration, |
670
|
|
|
$this->settings, |
671
|
|
|
MessageType::REGISTRATION_CANCELLED |
672
|
|
|
); |
673
|
|
|
|
674
|
|
|
// First cancel depending registrations |
675
|
|
|
if ($registration->getAmountOfRegistrations() > 1) { |
676
|
|
|
$this->registrationService->cancelDependingRegistrations($registration); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
// Finally cancel registration |
680
|
|
|
$this->registrationRepository->remove($registration); |
681
|
|
|
|
682
|
|
|
// Clear cache for configured pages |
683
|
|
|
$this->utilityService->clearCacheForConfiguredUids($this->settings); |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
$this->view->assignMultiple([ |
687
|
|
|
'messageKey' => $messageKey, |
688
|
|
|
'titleKey' => $titleKey, |
689
|
|
|
'event' => $event, |
690
|
|
|
]); |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* Set date format for field startDate and endDate |
695
|
|
|
* |
696
|
|
|
* @return void |
697
|
|
|
*/ |
698
|
|
|
public function initializeSearchAction() |
699
|
|
|
{ |
700
|
|
|
if ($this->settings !== null && $this->settings['search']['dateFormat']) { |
701
|
|
|
$this->arguments->getArgument('searchDemand') |
702
|
|
|
->getPropertyMappingConfiguration()->forProperty('startDate') |
703
|
|
|
->setTypeConverterOption( |
704
|
|
|
DateTimeConverter::class, |
705
|
|
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
706
|
|
|
$this->settings['search']['dateFormat'] |
707
|
|
|
); |
708
|
|
|
$this->arguments->getArgument('searchDemand') |
709
|
|
|
->getPropertyMappingConfiguration()->forProperty('endDate') |
710
|
|
|
->setTypeConverterOption( |
711
|
|
|
DateTimeConverter::class, |
712
|
|
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
713
|
|
|
$this->settings['search']['dateFormat'] |
714
|
|
|
); |
715
|
|
|
} |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
/** |
719
|
|
|
* Search view |
720
|
|
|
* |
721
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
722
|
|
|
* @param array $overwriteDemand OverwriteDemand |
723
|
|
|
* |
724
|
|
|
* @return void |
725
|
|
|
*/ |
726
|
|
|
public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
727
|
|
|
{ |
728
|
|
|
$eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
729
|
|
|
$eventDemand->setSearchDemand($searchDemand); |
|
|
|
|
730
|
|
|
$foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
731
|
|
|
$categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
732
|
|
|
|
733
|
|
|
if ($searchDemand !== null) { |
734
|
|
|
$searchDemand->setFields($this->settings['search']['fields']); |
735
|
|
|
|
736
|
|
|
if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) { |
737
|
|
|
$searchDemand->getStartDate()->setTime(0, 0, 0); |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) { |
741
|
|
|
$searchDemand->getEndDate()->setTime(23, 59, 59); |
742
|
|
|
} |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
if ($this->isOverwriteDemand($overwriteDemand)) { |
746
|
|
|
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
$categories = $this->categoryRepository->findDemanded($categoryDemand); |
750
|
|
|
$locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
751
|
|
|
$organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand); |
752
|
|
|
|
753
|
|
|
$events = $this->eventRepository->findDemanded($eventDemand); |
754
|
|
|
|
755
|
|
|
$this->view->assignMultiple([ |
756
|
|
|
'events' => $events, |
757
|
|
|
'categories' => $categories, |
758
|
|
|
'locations' => $locations, |
759
|
|
|
'organisators' => $organisators, |
760
|
|
|
'searchDemand' => $searchDemand, |
761
|
|
|
'overwriteDemand' => $overwriteDemand, |
762
|
|
|
]); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
/** |
766
|
|
|
* Returns if a demand object can be overwritten with the given overwriteDemand array |
767
|
|
|
* |
768
|
|
|
* @param array $overwriteDemand |
769
|
|
|
* @return bool |
770
|
|
|
*/ |
771
|
|
|
protected function isOverwriteDemand($overwriteDemand) |
772
|
|
|
{ |
773
|
|
|
return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== []; |
774
|
|
|
} |
775
|
|
|
} |
776
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.