|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use App\Entities\VisitorEntity; |
|
7
|
|
|
use App\Models\MeetingModel; |
|
8
|
|
|
use App\Models\VisitorModel; |
|
9
|
|
|
use App\Models\ProgramModel; |
|
10
|
|
|
use App\Models\MealModel; |
|
11
|
|
|
use App\Services\UserService; |
|
12
|
|
|
use App\Services\Emailer; |
|
13
|
|
|
use App\Services\VisitorService; |
|
14
|
|
|
use App\Services\ProgramService; |
|
15
|
|
|
use Tracy\Debugger; |
|
16
|
|
|
use App\Components\Forms\RegistrationForm; |
|
17
|
|
|
use App\Components\Forms\Factories\IRegistrationFormFactory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Registration controller |
|
21
|
|
|
* |
|
22
|
|
|
* This file handles the registration of visitors |
|
23
|
|
|
* |
|
24
|
|
|
* @author Tomas Litera |
|
25
|
|
|
* @copyright 2013-06-12 <[email protected]> |
|
26
|
|
|
* @package srazvs |
|
27
|
|
|
*/ |
|
28
|
|
|
class RegistrationPresenter extends VisitorPresenter |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var VisitorModel |
|
33
|
|
|
*/ |
|
34
|
|
|
private $visitorModel; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var ProgramModel |
|
38
|
|
|
*/ |
|
39
|
|
|
private $programModel; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var UserService |
|
43
|
|
|
*/ |
|
44
|
|
|
private $userService; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var ProgramService |
|
48
|
|
|
*/ |
|
49
|
|
|
private $programService; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var boolean |
|
53
|
|
|
*/ |
|
54
|
|
|
private $disabled = false; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var IRegistrationFormFactory |
|
58
|
|
|
*/ |
|
59
|
|
|
private $registrationFormFactory; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param MeetingModel $meetingModel |
|
63
|
|
|
* @param UserService $userService |
|
64
|
|
|
* @param VisitorModel $visitorModel |
|
65
|
|
|
* @param MealModel $mealModel |
|
66
|
|
|
* @param ProgramModel $programModel |
|
67
|
|
|
* @param VisitorService $visitorService |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct( |
|
70
|
|
|
MeetingModel $meetingModel, |
|
71
|
|
|
UserService $userService, |
|
72
|
|
|
VisitorModel $visitorModel, |
|
73
|
|
|
MealModel $mealModel, |
|
74
|
|
|
ProgramModel $programModel, |
|
75
|
|
|
Emailer $emailer, |
|
76
|
|
|
VisitorService $visitorService, |
|
77
|
|
|
ProgramService $programService |
|
78
|
|
|
) { |
|
79
|
|
|
$this->setMeetingModel($meetingModel); |
|
80
|
|
|
$this->setUserService($userService); |
|
81
|
|
|
$this->setVisitorModel($visitorModel); |
|
82
|
|
|
$this->setMealModel($mealModel); |
|
83
|
|
|
$this->setProgramModel($programModel); |
|
84
|
|
|
$this->setEmailer($emailer); |
|
85
|
|
|
$this->setVisitorService($visitorService); |
|
86
|
|
|
$this->setProgramService($programService); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return IRegistrationFormFactory |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getRegistrationFormFactory(): IRegistrationFormFactory |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->registrationFormFactory; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Injector |
|
99
|
|
|
* |
|
100
|
|
|
* @param IRegistrationFormFactory $factory |
|
101
|
|
|
*/ |
|
102
|
|
|
public function injectRegistrationFormFactory(IRegistrationFormFactory $factory) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->registrationFormFactory = $factory; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
public function startup() |
|
111
|
|
|
{ |
|
112
|
|
|
parent::startup(); |
|
113
|
|
|
|
|
114
|
|
|
$this->getMeetingModel()->setMeetingId($this->getMeetingId()); |
|
115
|
|
|
|
|
116
|
|
|
if($this->getDebugMode()) { |
|
117
|
|
|
$this->getMeetingModel()->setRegistrationHandlers(1); |
|
118
|
|
|
$this->setMeetingId(1); |
|
119
|
|
|
} else { |
|
120
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$template = $this->getTemplate(); |
|
124
|
|
|
|
|
125
|
|
|
$template->page_title = "Registrace srazu VS"; |
|
|
|
|
|
|
126
|
|
|
$template->meeting_heading = $this->getMeetingModel()->getRegHeading(); |
|
|
|
|
|
|
127
|
|
|
$template->isRegistrationOpen = $this->getMeetingModel()->isRegOpen($this->getDebugMode()); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Process data from form |
|
132
|
|
|
* |
|
133
|
|
|
* @return void |
|
134
|
|
|
*/ |
|
135
|
|
View Code Duplication |
public function actionCreate() |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
try { |
|
138
|
|
|
$postData = $this->getHttpRequest()->getPost(); |
|
139
|
|
|
$postData['meeting'] = $this->getMeetingId(); |
|
140
|
|
|
|
|
141
|
|
|
$guid = $this->getVisitorService()->create($postData); |
|
142
|
|
|
$result = $this->sendRegistrationSummary($postData, $guid); |
|
143
|
|
|
|
|
144
|
|
|
Debugger::log('Creation of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO); |
|
145
|
|
|
$this->flashMessage('Registrace(' . $guid . ') byla úspěšně založena.', self::FLASH_TYPE_OK); |
|
146
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
147
|
|
|
Debugger::log('Creation of registration('. $guid .') failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
|
|
|
|
|
148
|
|
|
$this->flashMessage('Creation of registration failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$this->redirect('Registration:check', $guid); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param string $guid |
|
156
|
|
|
* @return void |
|
157
|
|
|
*/ |
|
158
|
|
View Code Duplication |
public function actionUpdate($guid) |
|
|
|
|
|
|
159
|
|
|
{ |
|
160
|
|
|
try { |
|
161
|
|
|
$postData = $this->getHttpRequest()->getPost(); |
|
162
|
|
|
|
|
163
|
|
|
$result = $this->getVisitorService()->update($guid, $postData); |
|
164
|
|
|
$result = $this->sendRegistrationSummary($postData, $guid); |
|
165
|
|
|
|
|
166
|
|
|
Debugger::log('Modification of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO); |
|
167
|
|
|
$this->flashMessage('Registrace(' . $guid . ') byla úspěšně upravena.', self::FLASH_TYPE_OK); |
|
168
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
169
|
|
|
Debugger::log('Modification of registration('. $guid .') failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
170
|
|
|
$this->flashMessage('Modification of registration(' . $guid . ') failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
$this->redirect('Registration:check', $guid); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return void |
|
178
|
|
|
*/ |
|
179
|
|
|
public function renderDefault() |
|
180
|
|
|
{ |
|
181
|
|
|
$template = $this->getTemplate(); |
|
182
|
|
|
|
|
183
|
|
|
////otevirani a uzavirani prihlasovani |
|
184
|
|
|
$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled"; |
|
|
|
|
|
|
185
|
|
|
$template->disabled = $disabled; |
|
|
|
|
|
|
186
|
|
|
$template->loggedIn = $this->getUserService()->isLoggedIn(); |
|
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
if($this->getUserService()->isLoggedIn()) { |
|
189
|
|
|
$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray()); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @param string $guid |
|
195
|
|
|
* @return void |
|
196
|
|
|
*/ |
|
197
|
|
|
public function renderCheck($guid) |
|
198
|
|
|
{ |
|
199
|
|
|
$visitor = $this->getVisitorModel()->findByGuid($guid); |
|
200
|
|
|
|
|
201
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting); |
|
202
|
|
|
|
|
203
|
|
|
$template = $this->getTemplate(); |
|
204
|
|
|
$template->guid = $guid; |
|
|
|
|
|
|
205
|
|
|
$template->visitor = $visitor; |
|
|
|
|
|
|
206
|
|
|
$template->meetingId = $visitor->meeting; |
|
|
|
|
|
|
207
|
|
|
$template->meals = $this->getMealModel()->findByVisitorId($visitor->id); |
|
|
|
|
|
|
208
|
|
|
$template->province = $this->getMeetingModel()->getProvinceNameById($visitor->province); |
|
|
|
|
|
|
209
|
|
|
$template->programs = $this->getProgramModel()->findByVisitorId($visitor->id); |
|
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param string $guid |
|
214
|
|
|
* @return void |
|
215
|
|
|
*/ |
|
216
|
|
|
public function renderEdit($guid) |
|
217
|
|
|
{ |
|
218
|
|
|
$visitor = $this->getVisitorService()->findByGuid($guid); |
|
219
|
|
|
$meetingId = $visitor['meeting']; |
|
220
|
|
|
|
|
221
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($meetingId); |
|
222
|
|
|
|
|
223
|
|
|
$template = $this->getTemplate(); |
|
224
|
|
|
$template->guid = $guid; |
|
|
|
|
|
|
225
|
|
|
$template->meetingId = $meetingId; |
|
|
|
|
|
|
226
|
|
|
$template->loggedIn = $this->getUserService()->isLoggedIn(); |
|
|
|
|
|
|
227
|
|
|
$template->disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled"; |
|
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
$this['registrationForm']->setDefaults($visitor); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @return RegistrationFormControl |
|
234
|
|
|
*/ |
|
235
|
|
|
protected function createComponentRegistrationForm(): RegistrationForm |
|
236
|
|
|
{ |
|
237
|
|
|
$control = $this->registrationFormFactory->create(); |
|
238
|
|
|
$control->setMeetingId($this->getMeetingId()); |
|
239
|
|
|
$control->onRegistrationSave[] = function(RegistrationForm $control, $newVisitor) { |
|
240
|
|
|
try { |
|
241
|
|
|
$guid = $this->getVisitorService()->create((array) $newVisitor); |
|
242
|
|
|
$result = $this->sendRegistrationSummary((array) $newVisitor, $guid); |
|
243
|
|
|
|
|
244
|
|
|
Debugger::log('Storage of visitor('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO); |
|
245
|
|
|
$this->flashMessage('Účastník(' . $guid . ') byl úspěšně uložen.', self::FLASH_TYPE_OK); |
|
246
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
247
|
|
|
Debugger::log('Storage of visitor('. $guid .') failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
248
|
|
|
$this->flashMessage('Uložení účastníka selhalo, chyba: ' . $e->getMessage(), self::FLASH_TYPE_ERROR); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
$this->redirect('Registration:check', $guid); |
|
252
|
|
|
}; |
|
253
|
|
|
|
|
254
|
|
|
return $control; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @return VisitorEntity |
|
259
|
|
|
*/ |
|
260
|
|
|
protected function useLoggedVisitor(): VisitorEntity |
|
261
|
|
|
{ |
|
262
|
|
|
$userDetail = $this->getUserService()->getUserDetail(); |
|
263
|
|
|
$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person); |
|
264
|
|
|
$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person); |
|
265
|
|
|
|
|
266
|
|
|
if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) { |
|
267
|
|
|
$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0]; |
|
268
|
|
|
} else { |
|
269
|
|
|
$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
$visitor = new VisitorEntity; |
|
273
|
|
|
$visitor->name = $skautisUser->FirstName; |
|
274
|
|
|
$visitor->surname = $skautisUser->LastName; |
|
275
|
|
|
$visitor->nick = $skautisUser->NickName; |
|
276
|
|
|
$visitor->email = $skautisUser->Email; |
|
277
|
|
|
$visitor->street = $skautisUser->Street; |
|
278
|
|
|
$visitor->city = $skautisUser->City; |
|
279
|
|
|
$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode); |
|
280
|
|
|
$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y'); |
|
281
|
|
|
$visitor->group_name = $skautisUserUnit->DisplayName; |
|
282
|
|
|
$visitor->group_num = $skautisUserUnit->RegistrationNumber; |
|
283
|
|
|
if(isset($membership->Unit)) { |
|
284
|
|
|
$visitor->troop_name = $membership->Unit; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
return $visitor; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* @return MealModel |
|
292
|
|
|
*/ |
|
293
|
|
|
protected function getMealModel() |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->mealModel; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @param MealModel $model |
|
300
|
|
|
* @return $this |
|
301
|
|
|
*/ |
|
302
|
|
|
protected function setMealModel(MealModel $model) |
|
303
|
|
|
{ |
|
304
|
|
|
$this->mealModel = $model; |
|
305
|
|
|
|
|
306
|
|
|
return $this; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* @return MeetingModel |
|
311
|
|
|
*/ |
|
312
|
|
|
protected function getMeetingModel() |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->meetingModel; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param MeetingModel $model |
|
319
|
|
|
* @return $this |
|
320
|
|
|
*/ |
|
321
|
|
|
protected function setMeetingModel(MeetingModel $model) |
|
322
|
|
|
{ |
|
323
|
|
|
$this->meetingModel = $model; |
|
324
|
|
|
|
|
325
|
|
|
return $this; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return VisitorModel |
|
330
|
|
|
*/ |
|
331
|
|
|
protected function getVisitorModel() |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->visitorModel; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param VisitorModel $model |
|
338
|
|
|
* @return $this |
|
339
|
|
|
*/ |
|
340
|
|
|
protected function setVisitorModel(VisitorModel $model) |
|
341
|
|
|
{ |
|
342
|
|
|
$this->visitorModel = $model; |
|
343
|
|
|
|
|
344
|
|
|
return $this; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* @return ProgramModel |
|
349
|
|
|
*/ |
|
350
|
|
|
protected function getProgramModel() |
|
351
|
|
|
{ |
|
352
|
|
|
return $this->programModel; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @param ProgramModel $model |
|
357
|
|
|
* @return $this |
|
358
|
|
|
*/ |
|
359
|
|
|
protected function setProgramModel(ProgramModel $model) |
|
360
|
|
|
{ |
|
361
|
|
|
$this->programModel = $model; |
|
362
|
|
|
|
|
363
|
|
|
return $this; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @return UserService |
|
368
|
|
|
*/ |
|
369
|
|
|
protected function getUserService() |
|
370
|
|
|
{ |
|
371
|
|
|
return $this->userService; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* @param UserService $service |
|
376
|
|
|
* @return $this |
|
377
|
|
|
*/ |
|
378
|
|
|
protected function setUserService(UserService $service) |
|
379
|
|
|
{ |
|
380
|
|
|
$this->userService = $service; |
|
381
|
|
|
|
|
382
|
|
|
return $this; |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* @return ProgramService |
|
387
|
|
|
*/ |
|
388
|
|
|
protected function getProgramService() |
|
389
|
|
|
{ |
|
390
|
|
|
return $this->programService; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* @param ProgramService $service |
|
395
|
|
|
* @return $this |
|
396
|
|
|
*/ |
|
397
|
|
|
protected function setProgramService(ProgramService $service) |
|
398
|
|
|
{ |
|
399
|
|
|
$this->programService = $service; |
|
400
|
|
|
|
|
401
|
|
|
return $this; |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
} |
|
405
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: