|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
use App\Entities\VisitorEntity; |
|
8
|
|
|
use App\Models\MeetingModel; |
|
9
|
|
|
use App\Models\MealModel; |
|
10
|
|
|
use App\Services\SkautIS\UserService; |
|
11
|
|
|
use App\Services\Emailer; |
|
12
|
|
|
use App\Repositories\VisitorRepository; |
|
13
|
|
|
use App\Repositories\ProgramRepository; |
|
14
|
|
|
use App\Components\Forms\RegistrationForm; |
|
15
|
|
|
use App\Components\Forms\Factories\IRegistrationFormFactory; |
|
16
|
|
|
use App\Services\SkautIS\EventService; |
|
17
|
|
|
use Nette\Utils\ArrayHash; |
|
18
|
|
|
use Skautis\Wsdl\WsdlException; |
|
19
|
|
|
use App\Models\SettingsModel; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Registration controller |
|
23
|
|
|
* |
|
24
|
|
|
* This file handles the registration of visitors |
|
25
|
|
|
* |
|
26
|
|
|
* @author Tomas Litera |
|
27
|
|
|
* @copyright 2013-06-12 <[email protected]> |
|
28
|
|
|
* @package srazvs |
|
29
|
|
|
*/ |
|
30
|
|
|
class RegistrationPresenter extends VisitorPresenter |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var UserService |
|
35
|
|
|
*/ |
|
36
|
|
|
private $userService; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var SettingsModel |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $settingsModel; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var boolean |
|
45
|
|
|
*/ |
|
46
|
|
|
private $disabled = false; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var IRegistrationFormFactory |
|
50
|
|
|
*/ |
|
51
|
|
|
private $registrationFormFactory; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var EventService |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $skautisEventService; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var MealModel |
|
60
|
|
|
*/ |
|
61
|
|
|
private $mealModel; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var ProgramRepository |
|
65
|
|
|
*/ |
|
66
|
|
|
private $programRepository; |
|
67
|
|
|
|
|
68
|
|
|
protected $error = FALSE; |
|
69
|
|
|
protected $hash = NULL; |
|
70
|
|
|
private $user; |
|
|
|
|
|
|
71
|
|
|
private $event; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param MeetingModel $meetingModel |
|
75
|
|
|
* @param UserService $userService |
|
76
|
|
|
* @param MealModel $mealModel |
|
77
|
|
|
* @param ProgramRepository $programRepository |
|
78
|
|
|
* @param VisitorRepository $visitorRepository |
|
79
|
|
|
* @param SettingsModel $settingsModel |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __construct( |
|
82
|
|
|
MeetingModel $meetingModel, |
|
83
|
|
|
UserService $userService, |
|
84
|
|
|
MealModel $mealModel, |
|
85
|
|
|
Emailer $emailer, |
|
86
|
|
|
VisitorRepository $visitorRepository, |
|
87
|
|
|
ProgramRepository $programRepository, |
|
88
|
|
|
EventService $skautisEvent, |
|
89
|
|
|
SettingsModel $settingsModel |
|
90
|
|
|
) { |
|
91
|
|
|
$this->setMeetingModel($meetingModel); |
|
92
|
|
|
$this->setUserService($userService); |
|
93
|
|
|
$this->setMealModel($mealModel); |
|
94
|
|
|
$this->setEmailer($emailer); |
|
95
|
|
|
$this->setVisitorRepository($visitorRepository); |
|
96
|
|
|
$this->setProgramRepository($programRepository); |
|
97
|
|
|
$this->setEventService($skautisEvent); |
|
98
|
|
|
$this->setSettingsModel($settingsModel); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return IRegistrationFormFactory |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getRegistrationFormFactory(): IRegistrationFormFactory |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->registrationFormFactory; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Injector |
|
111
|
|
|
* |
|
112
|
|
|
* @param IRegistrationFormFactory $factory |
|
113
|
|
|
*/ |
|
114
|
|
|
public function injectRegistrationFormFactory(IRegistrationFormFactory $factory) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->registrationFormFactory = $factory; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return void |
|
121
|
|
|
*/ |
|
122
|
|
|
public function startup() |
|
123
|
|
|
{ |
|
124
|
|
|
parent::startup(); |
|
125
|
|
|
|
|
126
|
|
|
$this->getMeetingModel()->setMeetingId($this->getMeetingId()); |
|
127
|
|
|
|
|
128
|
|
|
if($this->getDebugMode() || $this->getSettingsModel()->findDebugRegime()) { |
|
129
|
|
|
$this->getMeetingModel()->setRegistrationHandlers(1); |
|
130
|
|
|
$this->setMeetingId(1); |
|
131
|
|
|
} else { |
|
132
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId()); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
//$this->user = $this->container->getService('userService'); |
|
136
|
|
|
//$this->event = $this->container->getService('eventService'); |
|
137
|
|
|
|
|
138
|
|
|
$template = $this->getTemplate(); |
|
139
|
|
|
|
|
140
|
|
|
$template->page_title = "Registrace srazu VS"; |
|
|
|
|
|
|
141
|
|
|
$template->meeting_heading = $this->getMeetingModel()->getRegHeading(); |
|
|
|
|
|
|
142
|
|
|
$template->isRegistrationOpen = $this->getMeetingModel()->isRegOpen($this->getDebugMode()); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Process data from form |
|
147
|
|
|
* |
|
148
|
|
|
* @return void |
|
149
|
|
|
*/ |
|
150
|
|
|
public function actionCreate($visitor) |
|
151
|
|
|
{ |
|
152
|
|
|
try { |
|
153
|
|
|
$guid = $this->getVisitorRepository()->create($visitor); |
|
154
|
|
|
$result = $this->sendRegistrationSummary($visitor, $guid); |
|
155
|
|
|
|
|
156
|
|
|
$this->logInfo('Creation of registration(%s) successfull, result: %s', [ |
|
157
|
|
|
$guid, |
|
158
|
|
|
json_encode($result), |
|
159
|
|
|
]); |
|
160
|
|
|
$this->flashSuccess("Registrace({$guid}) byla úspěšně založena."); |
|
161
|
|
|
} catch(Exception $e) { |
|
162
|
|
|
$this->logError('Creation of registration failed, result: %s', [ |
|
163
|
|
|
$e->getMessage(), |
|
164
|
|
|
]); |
|
165
|
|
|
$this->flashError('Uložení účastníka selhalo, chyba: ' . $e->getMessage()); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
return $guid; |
|
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param string $guid |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
public function actionUpdate($guid, $visitor) |
|
176
|
|
|
{ |
|
177
|
|
|
try { |
|
178
|
|
|
$result = $this->getVisitorRepository()->updateByGuid($guid, $visitor); |
|
179
|
|
|
$result = $this->sendRegistrationSummary($visitor, $guid); |
|
180
|
|
|
|
|
181
|
|
|
$this->logInfo('Modification of registration(%s) successfull, result: %s', [ |
|
182
|
|
|
$guid, |
|
183
|
|
|
json_encode($result), |
|
184
|
|
|
]); |
|
185
|
|
|
$this->flashSuccess("Registrace({$guid}) byla úspěšně upravena."); |
|
186
|
|
|
} catch(Exception $e) { |
|
187
|
|
|
$this->logError('Modification of registration(%s) failed, result: %s', [ |
|
188
|
|
|
$guid, |
|
189
|
|
|
$e->getMessage(), |
|
190
|
|
|
]); |
|
191
|
|
|
$this->flashError('Uložení účastníka selhalo, chyba: ' . $e->getMessage()); |
|
192
|
|
|
$result = false; |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
return $guid; |
|
|
|
|
|
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Renders default template |
|
200
|
|
|
*/ |
|
201
|
|
|
public function renderDefault() |
|
202
|
|
|
{ |
|
203
|
|
|
$template = $this->getTemplate(); |
|
204
|
|
|
$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled"; |
|
205
|
|
|
$template->disabled = $disabled; |
|
|
|
|
|
|
206
|
|
|
$template->loggedIn = $this->getUserService()->isLoggedIn(); |
|
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
if($this->getUserService()->isLoggedIn()) { |
|
209
|
|
|
$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray()); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Renders new template |
|
215
|
|
|
*/ |
|
216
|
|
|
public function renderNew() |
|
217
|
|
|
{ |
|
218
|
|
|
$template = $this->getTemplate(); |
|
219
|
|
|
$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled"; |
|
220
|
|
|
$template->disabled = $disabled; |
|
|
|
|
|
|
221
|
|
|
$template->loggedIn = false; |
|
|
|
|
|
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @param string $guid |
|
226
|
|
|
* @return void |
|
227
|
|
|
*/ |
|
228
|
|
|
public function renderCheck($guid) |
|
229
|
|
|
{ |
|
230
|
|
|
$visitor = $this->getVisitorRepository()->findByGuid($guid); |
|
231
|
|
|
|
|
232
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting); |
|
233
|
|
|
|
|
234
|
|
|
$template = $this->getTemplate(); |
|
235
|
|
|
$template->guid = $guid; |
|
|
|
|
|
|
236
|
|
|
$template->visitor = $visitor; |
|
|
|
|
|
|
237
|
|
|
$template->meetingId = $visitor->meeting; |
|
|
|
|
|
|
238
|
|
|
$template->meals = ArrayHash::from($this->getMealModel()->findByVisitorId($visitor->id)); |
|
|
|
|
|
|
239
|
|
|
$template->province = $this->getMeetingModel()->getProvinceNameById($visitor->province); |
|
|
|
|
|
|
240
|
|
|
$template->programs = $this->getProgramRepository()->findByVisitorId($visitor->id); |
|
|
|
|
|
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @param string $guid |
|
245
|
|
|
* @return void |
|
246
|
|
|
*/ |
|
247
|
|
|
public function renderEdit($guid) |
|
248
|
|
|
{ |
|
249
|
|
|
$visitor = $this->getVisitorRepository()->findExpandedByGuid($guid); |
|
250
|
|
|
$meetingId = $visitor['meeting']; |
|
251
|
|
|
|
|
252
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($meetingId); |
|
253
|
|
|
|
|
254
|
|
|
$template = $this->getTemplate(); |
|
255
|
|
|
$template->guid = $guid; |
|
|
|
|
|
|
256
|
|
|
$template->meetingId = $meetingId; |
|
|
|
|
|
|
257
|
|
|
$template->loggedIn = $this->getUserService()->isLoggedIn(); |
|
|
|
|
|
|
258
|
|
|
$template->disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled"; |
|
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
$this['registrationForm']->setDefaults($visitor); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @return RegistrationFormControl |
|
265
|
|
|
*/ |
|
266
|
|
|
protected function createComponentRegistrationForm(): RegistrationForm |
|
267
|
|
|
{ |
|
268
|
|
|
$control = $this->registrationFormFactory->create(); |
|
269
|
|
|
$control->setMeetingId($this->getMeetingId()); |
|
270
|
|
|
$control->onRegistrationSave[] = function(RegistrationForm $control, $visitor) { |
|
271
|
|
|
$guid = $this->getParameter('guid'); |
|
272
|
|
|
|
|
273
|
|
|
if($guid) { |
|
274
|
|
|
$guid = $this->actionUpdate($guid, $visitor); |
|
275
|
|
|
} else { |
|
276
|
|
|
$guid = $this->actionCreate($visitor); |
|
277
|
|
|
} |
|
278
|
|
|
/* |
|
279
|
|
|
if($this->getUserService()->isLoggedIn() && $this->getMeetingModel()->findCourseId()) { |
|
280
|
|
|
$this->getEventService()->insertEnroll( |
|
281
|
|
|
$this->getUserService()->getSkautis()->getUser()->getLoginId(), |
|
282
|
|
|
$this->getMeetingModel()->findCourseId(), |
|
283
|
|
|
// TODO: get real phone number |
|
284
|
|
|
'123456789' |
|
285
|
|
|
); |
|
286
|
|
|
} |
|
287
|
|
|
*/ |
|
288
|
|
|
$this->redirect('Registration:check', $guid); |
|
289
|
|
|
}; |
|
290
|
|
|
|
|
291
|
|
|
return $control; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @return VisitorEntity |
|
296
|
|
|
*/ |
|
297
|
|
|
protected function useLoggedVisitor(): VisitorEntity |
|
298
|
|
|
{ |
|
299
|
|
|
$userDetail = $this->getUserService()->getUserDetail(); |
|
300
|
|
|
$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person); |
|
301
|
|
|
$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person); |
|
302
|
|
|
|
|
303
|
|
|
if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) { |
|
304
|
|
|
$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0]; |
|
305
|
|
|
} else { |
|
306
|
|
|
$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
$visitor = new VisitorEntity; |
|
310
|
|
|
$visitor->name = $skautisUser->FirstName; |
|
311
|
|
|
$visitor->surname = $skautisUser->LastName; |
|
312
|
|
|
$visitor->nick = $skautisUser->NickName; |
|
313
|
|
|
$visitor->email = $skautisUser->Email; |
|
314
|
|
|
$visitor->street = $skautisUser->Street; |
|
315
|
|
|
$visitor->city = $skautisUser->City; |
|
316
|
|
|
$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode); |
|
317
|
|
|
$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y'); |
|
318
|
|
|
$visitor->group_name = $skautisUserUnit->DisplayName; |
|
319
|
|
|
$visitor->group_num = $skautisUserUnit->RegistrationNumber; |
|
320
|
|
|
if(isset($membership->Unit)) { |
|
321
|
|
|
$visitor->troop_name = $membership->Unit; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
return $visitor; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @return MealModel |
|
329
|
|
|
*/ |
|
330
|
|
|
protected function getMealModel() |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->mealModel; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* @param MealModel $model |
|
337
|
|
|
* @return $this |
|
338
|
|
|
*/ |
|
339
|
|
|
protected function setMealModel(MealModel $model) |
|
340
|
|
|
{ |
|
341
|
|
|
$this->mealModel = $model; |
|
342
|
|
|
|
|
343
|
|
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return MeetingModel |
|
348
|
|
|
*/ |
|
349
|
|
|
protected function getMeetingModel() |
|
350
|
|
|
{ |
|
351
|
|
|
return $this->meetingModel; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
/** |
|
355
|
|
|
* @param MeetingModel $model |
|
356
|
|
|
* @return $this |
|
357
|
|
|
*/ |
|
358
|
|
|
protected function setMeetingModel(MeetingModel $model) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->meetingModel = $model; |
|
361
|
|
|
|
|
362
|
|
|
return $this; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @return UserService |
|
367
|
|
|
*/ |
|
368
|
|
|
protected function getUserService() |
|
369
|
|
|
{ |
|
370
|
|
|
return $this->userService; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* @param UserService $service |
|
375
|
|
|
* @return $this |
|
376
|
|
|
*/ |
|
377
|
|
|
protected function setUserService(UserService $service) |
|
378
|
|
|
{ |
|
379
|
|
|
$this->userService = $service; |
|
380
|
|
|
|
|
381
|
|
|
return $this; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* @return EventService |
|
386
|
|
|
*/ |
|
387
|
|
|
protected function getEventService(): EventService |
|
388
|
|
|
{ |
|
389
|
|
|
return $this->skautisEventService; |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* @param EventService $skautisEvent |
|
|
|
|
|
|
394
|
|
|
* |
|
395
|
|
|
* @return self |
|
396
|
|
|
*/ |
|
397
|
|
|
protected function setEventService(EventService $service): self |
|
398
|
|
|
{ |
|
399
|
|
|
$this->skautisEventService = $service; |
|
400
|
|
|
|
|
401
|
|
|
return $this; |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* @return SettingsModel |
|
407
|
|
|
*/ |
|
408
|
|
|
protected function getSettingsModel(): SettingsModel |
|
409
|
|
|
{ |
|
410
|
|
|
return $this->settingsModel; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
/** |
|
414
|
|
|
* @param SettingsModel $model |
|
415
|
|
|
* |
|
416
|
|
|
* @return self |
|
417
|
|
|
*/ |
|
418
|
|
|
protected function setSettingsModel(SettingsModel $model): self |
|
419
|
|
|
{ |
|
420
|
|
|
$this->settingsModel = $model; |
|
421
|
|
|
|
|
422
|
|
|
return $this; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* @return ProgramRepository |
|
427
|
|
|
*/ |
|
428
|
|
|
protected function getProgramRepository(): ProgramRepository |
|
429
|
|
|
{ |
|
430
|
|
|
return $this->programRepository; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* @param ProgramRepository $repository |
|
435
|
|
|
* @return RegistrationPresenter |
|
436
|
|
|
*/ |
|
437
|
|
|
protected function setProgramRepository(ProgramRepository $repository): self |
|
438
|
|
|
{ |
|
439
|
|
|
$this->programRepository = $repository; |
|
440
|
|
|
|
|
441
|
|
|
return $this; |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
} |
|
445
|
|
|
|