|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use App\Components\CategoryStylesControl; |
|
6
|
|
|
use App\Components\Forms\Factories\IProgramFormFactory; |
|
7
|
|
|
use App\Components\Forms\ProgramForm; |
|
8
|
|
|
use App\Components\IProgramOverviewControl; |
|
9
|
|
|
use App\Components\ProgramOverviewControl; |
|
10
|
|
|
use App\Components\PublicProgramOverviewControl; |
|
11
|
|
|
use App\Components\ProgramVisitorsControl; |
|
12
|
|
|
use App\Models\BlockModel; |
|
13
|
|
|
use App\Models\MeetingModel; |
|
14
|
|
|
use App\Repositories\ProgramRepository; |
|
15
|
|
|
use App\Services\Emailer; |
|
16
|
|
|
use Nette\Utils\ArrayHash; |
|
17
|
|
|
use Tracy\Debugger; |
|
18
|
|
|
use Exception; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Program controller |
|
22
|
|
|
* |
|
23
|
|
|
* This file handles the retrieval and serving of blocks |
|
24
|
|
|
* |
|
25
|
|
|
* @created 2013-06-05 |
|
26
|
|
|
* @author Tomas Litera <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class ProgramPresenter extends BasePresenter |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var integer |
|
33
|
|
|
*/ |
|
34
|
|
|
private $programId = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Emailer |
|
38
|
|
|
*/ |
|
39
|
|
|
private $emailer; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var BlockModel |
|
43
|
|
|
*/ |
|
44
|
|
|
private $blockModel; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var MeetingModel |
|
48
|
|
|
*/ |
|
49
|
|
|
private $meetingModel; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var ProgramRepository |
|
53
|
|
|
*/ |
|
54
|
|
|
private $programRepository; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var IProgramFormFactory |
|
58
|
|
|
*/ |
|
59
|
|
|
private $programFormFactory; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var ProgramOverviewControl |
|
63
|
|
|
*/ |
|
64
|
|
|
private $programOverview; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var CategoryStylesControl |
|
68
|
|
|
*/ |
|
69
|
|
|
private $categoryStyles; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var ProgramVisitorsControl |
|
73
|
|
|
*/ |
|
74
|
|
|
private $programVisitors; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Prepare model classes and get meeting id |
|
78
|
|
|
*/ |
|
79
|
|
|
public function __construct( |
|
80
|
|
|
Emailer $emailer, |
|
81
|
|
|
BlockModel $blockModel, |
|
82
|
|
|
MeetingModel $meetingModel, |
|
83
|
|
|
ProgramRepository $programRepository, |
|
84
|
|
|
PublicProgramOverviewControl $publicProgramOverview, |
|
85
|
|
|
CategoryStylesControl $categoryStyles, |
|
86
|
|
|
ProgramVisitorsControl $programVisitors |
|
87
|
|
|
) { |
|
88
|
|
|
$this->setEmailer($emailer); |
|
89
|
|
|
$this->setBlockModel($blockModel); |
|
90
|
|
|
$this->setMeetingModel($meetingModel); |
|
91
|
|
|
$this->setProgramRepository($programRepository); |
|
92
|
|
|
$this->setProgramOverviewControl($publicProgramOverview); |
|
93
|
|
|
$this->setCategoryStylesControl($categoryStyles); |
|
94
|
|
|
$this->setProgramVisitorsControl($programVisitors); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param IProgramFormFactory $factory |
|
99
|
|
|
*/ |
|
100
|
|
|
public function injectProgramFormFactory(IProgramFormFactory $factory) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->programFormFactory = $factory; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function startup() |
|
109
|
|
|
{ |
|
110
|
|
|
parent::startup(); |
|
111
|
|
|
|
|
112
|
|
|
$meetingId = $this->getMeetingId(); |
|
113
|
|
|
$this->getProgramRepository()->setMeetingId($meetingId); |
|
114
|
|
|
$this->getMeetingModel()->setMeetingId($meetingId); |
|
115
|
|
|
$this->getBlockModel()->setMeetingId($meetingId); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Stores program into storage |
|
120
|
|
|
* |
|
121
|
|
|
* @param Nette\Utils\ArrayHash $program |
|
122
|
|
|
* @return boolean |
|
123
|
|
|
*/ |
|
124
|
|
|
public function actionCreate(ArrayHash $program) |
|
125
|
|
|
{ |
|
126
|
|
|
try { |
|
127
|
|
|
$this->logInfo('Storing new program.'); |
|
128
|
|
|
|
|
129
|
|
|
$result = $this->getProgramRepository()->create($program); |
|
130
|
|
|
|
|
131
|
|
|
$this->logInfo('Storing of new program with data %s successfull, result: %s', [ |
|
132
|
|
|
json_encode($program), |
|
133
|
|
|
json_encode($result), |
|
134
|
|
|
]); |
|
135
|
|
|
|
|
136
|
|
|
$this->flashSuccess('Položka byla úspěšně vytvořena'); |
|
137
|
|
|
} catch(Exception $e) { |
|
138
|
|
|
$this->logError('Creation of program with data %s failed, result: %s', [ |
|
139
|
|
|
json_encode($data), |
|
|
|
|
|
|
140
|
|
|
$e->getMessage() |
|
141
|
|
|
]); |
|
142
|
|
|
|
|
143
|
|
|
$this->flashError('Položku se nepodařilo vytvořit.'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $result; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Updates program in storage |
|
151
|
|
|
* |
|
152
|
|
|
* @param int $id |
|
153
|
|
|
* @param Nette\Utils\ArrayHash $program |
|
154
|
|
|
* @return boolean |
|
155
|
|
|
*/ |
|
156
|
|
|
public function actionUpdate(int $id, ArrayHash $program) |
|
157
|
|
|
{ |
|
158
|
|
|
try { |
|
159
|
|
|
$this->logInfo('Updating program(%s).', [$id]); |
|
160
|
|
|
|
|
161
|
|
|
$result = $this->getProgramRepository()->update($id, $program); |
|
162
|
|
|
|
|
163
|
|
|
$this->logInfo('Updating of program(%s) with data %s successfull, result: %s', [ |
|
164
|
|
|
$id, |
|
165
|
|
|
json_encode($program), |
|
166
|
|
|
json_encode($result), |
|
167
|
|
|
]); |
|
168
|
|
|
|
|
169
|
|
|
$this->flashSuccess('Položka byla úspěšně upravena'); |
|
170
|
|
|
} catch(Exception $e) { |
|
171
|
|
|
$this->logError('Updating of program(%s) failed, result: %s', [ |
|
172
|
|
|
$program->guid, |
|
173
|
|
|
$e->getMessage(), |
|
174
|
|
|
]); |
|
175
|
|
|
|
|
176
|
|
|
$this->flashError('Položku se nepodařilo upravit.'); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return $result; |
|
|
|
|
|
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @param integer $id |
|
184
|
|
|
* @return void |
|
185
|
|
|
*/ |
|
186
|
|
|
public function actionDelete($id) |
|
187
|
|
|
{ |
|
188
|
|
|
try { |
|
189
|
|
|
$result = $this->getProgramRepository()->delete($id); |
|
190
|
|
|
|
|
191
|
|
|
$this->logInfo('Destroying of program successfull, result: %s', [ |
|
192
|
|
|
json_encode($result) |
|
193
|
|
|
]); |
|
194
|
|
|
$this->flashSuccess('Položka byla úspěšně smazána.'); |
|
195
|
|
|
} catch(Exception $e) { |
|
196
|
|
|
$this->logError('Destroying of program failed, result: %s', [ |
|
197
|
|
|
$e->getMessage() |
|
198
|
|
|
]); |
|
199
|
|
|
$this->flashError('Smazání programu se nezdařilo, result: %s', [ |
|
|
|
|
|
|
200
|
|
|
$e->getMessage() |
|
201
|
|
|
]); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$this->redirect('Program:listing'); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return void |
|
209
|
|
|
*/ |
|
210
|
|
|
public function actionMail($id) |
|
211
|
|
|
{ |
|
212
|
|
|
try { |
|
213
|
|
|
$tutors = $this->getProgramRepository()->findTutor($id); |
|
214
|
|
|
$recipients = $this->parseTutorEmail($tutors); |
|
215
|
|
|
|
|
216
|
|
|
$this->getEmailer()->tutor($recipients, $tutors->guid, 'program'); |
|
217
|
|
|
|
|
218
|
|
|
$this->logInfo('Sending email to program tutor successfull, result: %s, %s', [ |
|
219
|
|
|
json_encode($recipients), |
|
220
|
|
|
$tutors->guid |
|
221
|
|
|
]); |
|
222
|
|
|
$this->flashSuccess('Email lektorovi byl odeslán.'); |
|
223
|
|
|
} catch(Exception $e) { |
|
224
|
|
|
$this->logError('Sending email to program tutor failed, result: %s', [ |
|
225
|
|
|
$e->getMessage() |
|
226
|
|
|
]); |
|
227
|
|
|
$this->flashError('Email lektorovi nebyl odeslán, result: %s', [ |
|
|
|
|
|
|
228
|
|
|
$e->getMessage() |
|
229
|
|
|
]); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
$this->redirect('Program:edit', $id); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* View public program |
|
237
|
|
|
* |
|
238
|
|
|
* @return void |
|
239
|
|
|
*/ |
|
240
|
|
|
public function renderPublic() |
|
241
|
|
|
{ |
|
242
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId()); |
|
243
|
|
|
|
|
244
|
|
|
$template = $this->getTemplate(); |
|
245
|
|
|
$template->meeting_heading = $this->getMeetingModel()->getRegHeading(); |
|
|
|
|
|
|
246
|
|
|
////otevirani a uzavirani prihlasovani |
|
247
|
|
|
if(($this->getMeetingModel()->getRegOpening() < time()) || $this->getDebugMode()) { |
|
248
|
|
|
$template->display_program = true; |
|
|
|
|
|
|
249
|
|
|
} else { |
|
250
|
|
|
$template->display_program = false; |
|
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
$template->page_title = 'Srazy VS - veřejný program'; |
|
|
|
|
|
|
253
|
|
|
$template->style = 'table { border-collapse:separate; width:100%; } |
|
|
|
|
|
|
254
|
|
|
td { .width:100%; text-align:center; padding:0px; } |
|
255
|
|
|
td.day { border:1px solid black; background-color:#777777; width:80px; } |
|
256
|
|
|
td.time { background-color:#cccccc; width:80px; }'; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @return void |
|
261
|
|
|
*/ |
|
262
|
|
|
public function renderListing() |
|
263
|
|
|
{ |
|
264
|
|
|
$template = $this->getTemplate(); |
|
265
|
|
|
$template->programs = $this->getProgramRepository()->all(); |
|
|
|
|
|
|
266
|
|
|
$template->mid = $this->meetingId; |
|
|
|
|
|
|
267
|
|
|
$template->heading = $this->heading; |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return void |
|
272
|
|
|
*/ |
|
273
|
|
|
public function renderNew() |
|
274
|
|
|
{ |
|
275
|
|
|
$template = $this->getTemplate(); |
|
276
|
|
|
$template->heading = 'nový program'; |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @param integer $id |
|
281
|
|
|
* @return void |
|
282
|
|
|
*/ |
|
283
|
|
|
public function renderEdit($id) |
|
284
|
|
|
{ |
|
285
|
|
|
$this->programId = $id; |
|
286
|
|
|
$program = $this->getProgramRepository()->find($id); |
|
287
|
|
|
|
|
288
|
|
|
$template = $this->getTemplate(); |
|
289
|
|
|
$template->heading = 'úprava programu'; |
|
|
|
|
|
|
290
|
|
|
$template->program = $program; |
|
|
|
|
|
|
291
|
|
|
$template->id = $id; |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
$this['programForm']->setDefaults($program); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* @return ProgramForm |
|
298
|
|
|
*/ |
|
299
|
|
|
protected function createComponentProgramForm(): ProgramForm |
|
300
|
|
|
{ |
|
301
|
|
|
$control = $this->programFormFactory->create(); |
|
302
|
|
|
$control->setMeetingId($this->getMeetingId()); |
|
303
|
|
View Code Duplication |
$control->onProgramSave[] = function(ProgramForm $control, $program) { |
|
|
|
|
|
|
304
|
|
|
//$guid = $this->getParameter('guid'); |
|
305
|
|
|
$id = $this->getParameter('id'); |
|
306
|
|
|
|
|
307
|
|
|
$this->setBacklinkFromArray($program); |
|
308
|
|
|
|
|
309
|
|
|
if($id) { |
|
310
|
|
|
$this->actionUpdate($id, $program); |
|
311
|
|
|
} else { |
|
312
|
|
|
$this->actionCreate($program); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
316
|
|
|
}; |
|
317
|
|
|
|
|
318
|
|
|
$control->onProgramReset[] = function(ProgramForm $control, $program) { |
|
319
|
|
|
$this->setBacklinkFromArray($program); |
|
320
|
|
|
|
|
321
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
322
|
|
|
}; |
|
323
|
|
|
|
|
324
|
|
|
return $control; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @return AProgramOverviewControl |
|
329
|
|
|
*/ |
|
330
|
|
|
protected function createComponentProgramOverview(): IProgramOverviewControl |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->programOverview->setMeetingId($this->getMeetingId()); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* @return CategoryStylesControl |
|
337
|
|
|
*/ |
|
338
|
|
|
protected function createComponentCategoryStyles(): CategoryStylesControl |
|
339
|
|
|
{ |
|
340
|
|
|
return $this->categoryStyles; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @return ProgramVisitorsControl |
|
345
|
|
|
*/ |
|
346
|
|
|
protected function createComponentProgramVisitors(): ProgramVisitorsControl |
|
347
|
|
|
{ |
|
348
|
|
|
return $this->programVisitors; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @param ProgramOverviewControl $control |
|
353
|
|
|
* @return $this |
|
354
|
|
|
*/ |
|
355
|
|
|
protected function setProgramOverviewControl(IProgramOverviewControl $control) |
|
356
|
|
|
{ |
|
357
|
|
|
$this->programOverview = $control; |
|
|
|
|
|
|
358
|
|
|
|
|
359
|
|
|
return $this; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* @return Emailer |
|
364
|
|
|
*/ |
|
365
|
|
|
protected function getEmailer(): Emailer |
|
366
|
|
|
{ |
|
367
|
|
|
return $this->emailer; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* @param Emailer $emailer |
|
372
|
|
|
* @return self |
|
373
|
|
|
*/ |
|
374
|
|
|
protected function setEmailer(Emailer $emailer): self |
|
375
|
|
|
{ |
|
376
|
|
|
$this->emailer = $emailer; |
|
377
|
|
|
|
|
378
|
|
|
return $this; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @return BlockModel |
|
383
|
|
|
*/ |
|
384
|
|
|
protected function getBlockModel(): BlockModel |
|
385
|
|
|
{ |
|
386
|
|
|
return $this->blockModel; |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* @param BlockModel $blockModel |
|
391
|
|
|
* @return self |
|
392
|
|
|
*/ |
|
393
|
|
|
protected function setBlockModel(BlockModel $blockModel): self |
|
394
|
|
|
{ |
|
395
|
|
|
$this->blockModel = $blockModel; |
|
396
|
|
|
|
|
397
|
|
|
return $this; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* @return MeetingModel |
|
402
|
|
|
*/ |
|
403
|
|
|
protected function getMeetingModel(): MeetingModel |
|
404
|
|
|
{ |
|
405
|
|
|
return $this->meetingModel; |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
/** |
|
409
|
|
|
* @param MeetingModel $model |
|
410
|
|
|
* @return $this |
|
411
|
|
|
*/ |
|
412
|
|
|
protected function setMeetingModel(MeetingModel $model): self |
|
413
|
|
|
{ |
|
414
|
|
|
$this->meetingModel = $model; |
|
415
|
|
|
|
|
416
|
|
|
return $this; |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* @return ProgramRepository |
|
421
|
|
|
*/ |
|
422
|
|
|
protected function getProgramRepository(): ProgramRepository |
|
423
|
|
|
{ |
|
424
|
|
|
return $this->programRepository; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* @param ProgramRepository $model |
|
|
|
|
|
|
429
|
|
|
* @return $this |
|
430
|
|
|
*/ |
|
431
|
|
|
protected function setProgramRepository(ProgramRepository $repository):self |
|
432
|
|
|
{ |
|
433
|
|
|
$this->programRepository = $repository; |
|
434
|
|
|
|
|
435
|
|
|
return $this; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* @param CategoryStylesControl $control |
|
440
|
|
|
* |
|
441
|
|
|
* @return self |
|
442
|
|
|
*/ |
|
443
|
|
|
public function setCategoryStylesControl(CategoryStylesControl $control): self |
|
444
|
|
|
{ |
|
445
|
|
|
$this->categoryStyles = $control; |
|
446
|
|
|
|
|
447
|
|
|
return $this; |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* @param ProgramVisitorsControl $control |
|
452
|
|
|
* @return self |
|
453
|
|
|
*/ |
|
454
|
|
|
public function setProgramVisitorsControl(ProgramVisitorsControl $control): self |
|
455
|
|
|
{ |
|
456
|
|
|
$this->programVisitors = $control; |
|
457
|
|
|
|
|
458
|
|
|
return $this; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
} |
|
462
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.