1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Controller; |
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\Dto\EventDemand; |
12
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand; |
13
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
14
|
|
|
use DERHANSEN\SfEventMgt\Service; |
15
|
|
|
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; |
16
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* AdministrationController |
20
|
|
|
* |
21
|
|
|
* @author Torben Hansen <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class AdministrationController extends AbstractController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* CustomNotificationLogRepository |
27
|
|
|
* |
28
|
|
|
* @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository |
29
|
|
|
*/ |
30
|
|
|
protected $customNotificationLogRepository = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* ExportService |
34
|
|
|
* |
35
|
|
|
* @var \DERHANSEN\SfEventMgt\Service\ExportService |
36
|
|
|
*/ |
37
|
|
|
protected $exportService = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* SettingsService |
41
|
|
|
* |
42
|
|
|
* @var \DERHANSEN\SfEventMgt\Service\SettingsService |
43
|
|
|
*/ |
44
|
|
|
protected $settingsService = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Backend User Session Service |
48
|
|
|
* |
49
|
|
|
* @var \DERHANSEN\SfEventMgt\Service\BeUserSessionService |
50
|
|
|
*/ |
51
|
|
|
protected $beUserSessionService = null; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The current page uid |
55
|
|
|
* |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $pid = 0; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* DI for $customNotificationLogRepository |
62
|
|
|
* |
63
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository |
64
|
|
|
*/ |
65
|
|
|
public function injectCustomNotificationLogRepository( |
66
|
|
|
\DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository |
67
|
|
|
) { |
68
|
|
|
$this->customNotificationLogRepository = $customNotificationLogRepository; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* DI for $exportService |
73
|
|
|
* |
74
|
|
|
* @param Service\ExportService $exportService |
75
|
|
|
*/ |
76
|
|
|
public function injectExportService(\DERHANSEN\SfEventMgt\Service\ExportService $exportService) |
77
|
|
|
{ |
78
|
|
|
$this->exportService = $exportService; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* DI for $settingsService |
83
|
|
|
* |
84
|
|
|
* @param Service\SettingsService $settingsService |
85
|
|
|
*/ |
86
|
|
|
public function injectSettingsService(\DERHANSEN\SfEventMgt\Service\SettingsService $settingsService) |
87
|
|
|
{ |
88
|
|
|
$this->settingsService = $settingsService; |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
/** |
92
|
|
|
* DI for $beUserSessionService |
93
|
2 |
|
* |
94
|
2 |
|
* @param Service\BeUserSessionService $beUserSessionService |
95
|
|
|
*/ |
96
|
|
|
public function injectBeUserSessionService(\DERHANSEN\SfEventMgt\Service\BeUserSessionService $beUserSessionService) |
97
|
|
|
{ |
98
|
|
|
$this->beUserSessionService = $beUserSessionService; |
99
|
|
|
} |
100
|
|
|
|
101
|
4 |
|
/** |
102
|
|
|
* Initialize action |
103
|
4 |
|
* |
104
|
2 |
|
* @return void |
105
|
2 |
|
*/ |
106
|
4 |
|
public function initializeAction() |
107
|
4 |
|
{ |
108
|
4 |
|
$this->pid = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id'); |
109
|
4 |
|
} |
110
|
4 |
|
|
111
|
4 |
|
/** |
112
|
4 |
|
* Set date format for fields startDate and endDate |
113
|
4 |
|
* |
114
|
4 |
|
* @return void |
115
|
4 |
|
*/ |
116
|
4 |
|
public function initializeListAction() |
117
|
4 |
|
{ |
118
|
4 |
|
if ($this->settings === null) { |
119
|
4 |
|
$this->redirect('settingsError'); |
120
|
4 |
|
} |
121
|
|
|
$this->arguments->getArgument('searchDemand') |
122
|
|
|
->getPropertyMappingConfiguration()->forProperty('startDate') |
123
|
|
|
->setTypeConverterOption( |
124
|
|
|
DateTimeConverter::class, |
125
|
|
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
126
|
|
|
$this->settings['search']['dateFormat'] |
127
|
|
|
); |
128
|
|
|
$this->arguments->getArgument('searchDemand') |
129
|
|
|
->getPropertyMappingConfiguration()->forProperty('endDate') |
130
|
8 |
|
->setTypeConverterOption( |
131
|
|
|
DateTimeConverter::class, |
132
|
|
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT, |
133
|
8 |
|
$this->settings['search']['dateFormat'] |
134
|
|
|
); |
135
|
8 |
|
} |
136
|
6 |
|
|
137
|
6 |
|
/** |
138
|
8 |
|
* List action for backend module |
139
|
|
|
* |
140
|
8 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
141
|
4 |
|
* @param int $messageId MessageID |
142
|
4 |
|
* |
143
|
|
|
* @return void |
144
|
8 |
|
*/ |
145
|
2 |
|
public function listAction(SearchDemand $searchDemand = null, $messageId = null) |
146
|
2 |
|
{ |
147
|
2 |
|
/** @var EventDemand $demand */ |
148
|
2 |
|
$demand = $this->objectManager->get(EventDemand::class); |
149
|
|
|
|
150
|
8 |
|
if ($searchDemand !== null) { |
151
|
8 |
|
$searchDemand->setFields($this->settings['search']['fields']); |
152
|
8 |
|
|
153
|
8 |
|
$sessionData = []; |
154
|
|
|
$sessionData['searchDemand'] = $searchDemand; |
155
|
|
|
$this->beUserSessionService->saveSessionData($sessionData); |
156
|
|
|
} else { |
157
|
|
|
// Try to restore search demand from Session |
158
|
|
|
$searchDemand = $this->beUserSessionService->getSessionDataByKey('searchDemand'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$demand->setSearchDemand($searchDemand); |
162
|
2 |
|
|
163
|
|
|
if ($this->pid > 0) { |
164
|
2 |
|
$demand->setStoragePage($this->pid); |
165
|
2 |
|
} |
166
|
|
|
|
167
|
|
|
$variables = []; |
168
|
|
|
if ($messageId !== null && is_numeric($messageId)) { |
169
|
|
|
$variables['showMessage'] = true; |
170
|
|
|
$variables['messageTitleKey'] = 'administration.message-' . $messageId . '.title'; |
171
|
|
|
$variables['messageContentKey'] = 'administration.message-' . $messageId . '.content'; |
172
|
|
|
} |
173
|
2 |
|
|
174
|
|
|
$variables['events'] = $this->eventRepository->findDemanded($demand); |
175
|
2 |
|
$variables['searchDemand'] = $searchDemand; |
176
|
2 |
|
$variables['csvExportPossible'] = $this->hasWriteAccessToTempFolder(); |
177
|
2 |
|
$this->view->assignMultiple($variables); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns, if the user has write access to temp folder and if not, adds a flash message if configured |
182
|
|
|
* |
183
|
|
|
* @return bool |
184
|
|
|
*/ |
185
|
|
|
protected function hasWriteAccessToTempFolder() |
186
|
2 |
|
{ |
187
|
|
|
$hasAccess = $this->exportService->hasWriteAccessToTempFolder(); |
188
|
2 |
|
if (!$hasAccess && (bool)$this->settings['csvExport']['showFlashMessageForInsufficientAccessRights']) { |
189
|
2 |
|
$this->addFlashMessage( |
190
|
2 |
|
LocalizationUtility::translate('insufficientAccessToTemp', $this->extensionName), |
191
|
2 |
|
LocalizationUtility::translate('csvExportDisabled', $this->extensionName), |
192
|
2 |
|
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING |
193
|
2 |
|
); |
194
|
2 |
|
} |
195
|
2 |
|
|
196
|
|
|
return $hasAccess; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Export registrations for a given event |
201
|
|
|
* |
202
|
|
|
* @param int $eventUid Event UID |
203
|
|
|
* |
204
|
|
|
* @return bool Always FALSE, since no view should be rendered |
205
|
2 |
|
*/ |
206
|
|
|
public function exportAction($eventUid) |
207
|
2 |
|
{ |
208
|
2 |
|
$this->exportService->downloadRegistrationsCsv($eventUid, $this->settings['csvExport']); |
209
|
2 |
|
|
210
|
2 |
|
return false; |
211
|
2 |
|
} |
212
|
|
|
|
213
|
2 |
|
/** |
214
|
2 |
|
* Calls the handleExpiredRegistrations Service |
215
|
2 |
|
* |
216
|
|
|
* @return void |
217
|
|
|
*/ |
218
|
|
|
public function handleExpiredRegistrationsAction() |
219
|
|
|
{ |
220
|
|
|
$this->registrationService->handleExpiredRegistrations($this->settings['registration']['deleteExpiredRegistrations']); |
221
|
|
|
$this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 1]); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* The index notify action |
226
|
|
|
* |
227
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
228
|
|
|
* |
229
|
|
|
* @return void |
230
|
|
|
*/ |
231
|
|
|
public function indexNotifyAction(Event $event) |
232
|
|
|
{ |
233
|
|
|
$customNotifications = $this->settingsService->getCustomNotifications($this->settings); |
234
|
|
|
$logEntries = $this->customNotificationLogRepository->findByEvent($event); |
|
|
|
|
235
|
|
|
$this->view->assignMultiple([ |
236
|
|
|
'event' => $event, |
237
|
|
|
'customNotifications' => $customNotifications, |
238
|
|
|
'logEntries' => $logEntries, |
239
|
|
|
]); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Notify action |
244
|
|
|
* |
245
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
246
|
|
|
* @param string $customNotification CustomNotification |
247
|
|
|
* |
248
|
|
|
* @return void |
249
|
|
|
*/ |
250
|
|
|
public function notifyAction(Event $event, $customNotification) |
251
|
|
|
{ |
252
|
|
|
$customNotifications = $this->settingsService->getCustomNotifications($this->settings); |
253
|
|
|
$result = $this->notificationService->sendCustomNotification($event, $customNotification, $this->settings); |
254
|
|
|
$this->notificationService->createCustomNotificationLogentry( |
255
|
|
|
$event, |
256
|
|
|
$customNotifications[$customNotification], |
257
|
|
|
$result |
258
|
|
|
); |
259
|
|
|
$this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 2]); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Shows the settings error view |
264
|
|
|
* |
265
|
|
|
* @return void |
266
|
|
|
*/ |
267
|
|
|
public function settingsErrorAction() |
268
|
|
|
{ |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Suppress default validation messages |
273
|
|
|
* |
274
|
|
|
* @return bool |
275
|
|
|
*/ |
276
|
|
|
protected function getErrorFlashMessage() |
277
|
|
|
{ |
278
|
|
|
return false; |
|
|
|
|
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: