|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use App\Components\PublicProgramOverviewControl; |
|
6
|
|
|
use App\Components\CategoryStylesControl; |
|
7
|
|
|
use App\Components\IProgramOverviewControl; |
|
8
|
|
|
use App\Models\BlockModel; |
|
9
|
|
|
use App\Models\MeetingModel; |
|
10
|
|
|
use App\Models\ProgramModel; |
|
11
|
|
|
use App\Services\Emailer; |
|
12
|
|
|
use Tracy\Debugger; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Program controller |
|
16
|
|
|
* |
|
17
|
|
|
* This file handles the retrieval and serving of blocks |
|
18
|
|
|
* |
|
19
|
|
|
* @created 2013-06-05 |
|
20
|
|
|
* @author Tomas Litera <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class ProgramPresenter extends BasePresenter |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var integer |
|
27
|
|
|
*/ |
|
28
|
|
|
private $programId = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Emailer |
|
32
|
|
|
*/ |
|
33
|
|
|
private $emailer; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var BlockModel |
|
37
|
|
|
*/ |
|
38
|
|
|
private $blockModel; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var MeetingModel |
|
42
|
|
|
*/ |
|
43
|
|
|
private $meetingModel; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var ProgramOverviewControl |
|
47
|
|
|
*/ |
|
48
|
|
|
private $programOverview; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var CategoryStylesControl |
|
52
|
|
|
*/ |
|
53
|
|
|
private $categoryStyles; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Prepare model classes and get meeting id |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct( |
|
59
|
|
|
ProgramModel $model, |
|
60
|
|
|
Emailer $emailer, |
|
61
|
|
|
BlockModel $blockModel, |
|
62
|
|
|
MeetingModel $meetingModel, |
|
63
|
|
|
PublicProgramOverviewControl $publicProgramOverview, |
|
64
|
|
|
CategoryStylesControl $categoryStyles |
|
65
|
|
|
) { |
|
66
|
|
|
$this->setModel($model); |
|
|
|
|
|
|
67
|
|
|
$this->setEmailer($emailer); |
|
68
|
|
|
$this->setBlockModel($blockModel); |
|
69
|
|
|
$this->setMeetingModel($meetingModel); |
|
70
|
|
|
$this->setProgramOverviewControl($publicProgramOverview); |
|
71
|
|
|
$this->setCategoryStylesControl($categoryStyles); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
public function startup() |
|
78
|
|
|
{ |
|
79
|
|
|
parent::startup(); |
|
80
|
|
|
|
|
81
|
|
|
$meetingId = $this->getMeetingId(); |
|
82
|
|
|
$this->getModel()->setMeetingId($meetingId); |
|
83
|
|
|
$this->getMeetingModel()->setMeetingId($meetingId); |
|
84
|
|
|
$this->getBlockModel()->setMeetingId($meetingId); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function actionCreate() |
|
91
|
|
|
{ |
|
92
|
|
|
$model = $this->getModel(); |
|
|
|
|
|
|
93
|
|
|
$data = $this->getHttpRequest()->getPost(); |
|
94
|
|
|
|
|
95
|
|
|
try { |
|
96
|
|
View Code Duplication |
if(array_key_exists('backlink', $data) && isset($data['backlink'])) { |
|
|
|
|
|
|
97
|
|
|
$this->setBacklink($data['backlink']); |
|
98
|
|
|
unset($data['backlink']); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if(!array_key_exists('display_in_reg', $data)) { |
|
102
|
|
|
$data['display_in_reg'] = 1; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$result = $this->getModel()->create($data); |
|
106
|
|
|
|
|
107
|
|
|
$this->logInfo('Creation of program successfull, result: %s', [ |
|
108
|
|
|
json_encode($result) |
|
109
|
|
|
]); |
|
110
|
|
|
|
|
111
|
|
|
$this->flashSuccess('Položka byla úspěšně vytvořena'); |
|
112
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
113
|
|
|
$this->logError('Creation of program with data %s failed, result: %s', [ |
|
114
|
|
|
json_encode($data), |
|
115
|
|
|
$e->getMessage() |
|
116
|
|
|
]); |
|
117
|
|
|
|
|
118
|
|
|
$this->flashError('Záznam se nepodařilo uložit, result: %s', [ |
|
|
|
|
|
|
119
|
|
|
$e->getMessage() |
|
120
|
|
|
]); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param integer $id |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
|
|
public function actionUpdate($id) |
|
131
|
|
|
{ |
|
132
|
|
|
$model = $this->getModel(); |
|
|
|
|
|
|
133
|
|
|
$data = $this->getHttpRequest()->getPost(); |
|
134
|
|
|
|
|
135
|
|
|
try { |
|
136
|
|
View Code Duplication |
if(array_key_exists('backlink', $data) && isset($data['backlink'])) { |
|
|
|
|
|
|
137
|
|
|
$this->setBacklink($data['backlink']); |
|
138
|
|
|
unset($data['backlink']); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if(!array_key_exists('display_in_reg', $data)) { |
|
142
|
|
|
$data['display_in_reg'] = 1; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
$result = $this->getModel()->update($id, $data); |
|
146
|
|
|
|
|
147
|
|
|
$this->logInfo('Modification of program id %s with data %s successfull, result: %s', [ |
|
148
|
|
|
$id, |
|
149
|
|
|
json_encode($data), |
|
150
|
|
|
json_encode($result) |
|
151
|
|
|
]); |
|
152
|
|
|
|
|
153
|
|
|
$this->flashSuccess('Položka byla úspěšně upravena.'); |
|
154
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
155
|
|
|
$this->logError('Modification of program id %s failed, result: %s', [ |
|
156
|
|
|
$id, |
|
157
|
|
|
$e->getMessage() |
|
158
|
|
|
]); |
|
159
|
|
|
|
|
160
|
|
|
$this->flashError('Modification of program id %s failed, result: %s', [ |
|
|
|
|
|
|
161
|
|
|
$id, |
|
162
|
|
|
$e->getMessage() |
|
163
|
|
|
]); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param integer $id |
|
171
|
|
|
* @return void |
|
172
|
|
|
*/ |
|
173
|
|
|
public function actionDelete($id) |
|
174
|
|
|
{ |
|
175
|
|
|
try { |
|
176
|
|
|
$result = $this->getModel()->delete($id); |
|
177
|
|
|
$this->logInfo('Destroying of program successfull, result: %s', [ |
|
178
|
|
|
json_encode($result) |
|
179
|
|
|
]); |
|
180
|
|
|
$this->flashSuccess('Položka byla úspěšně smazána.'); |
|
181
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
182
|
|
|
$this->logError('Destroying of program failed, result: %s', [ |
|
183
|
|
|
$e->getMessage() |
|
184
|
|
|
]); |
|
185
|
|
|
$this->flashError('Smazání programu se nezdařilo, result: %s', [ |
|
|
|
|
|
|
186
|
|
|
$e->getMessage() |
|
187
|
|
|
]); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
$this->redirect('Program:listing'); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return void |
|
195
|
|
|
*/ |
|
196
|
|
|
public function actionMail($id) |
|
197
|
|
|
{ |
|
198
|
|
|
try { |
|
199
|
|
|
$tutors = $this->getModel()->getTutor($id); |
|
200
|
|
|
$recipients = $this->parseTutorEmail($tutors); |
|
201
|
|
|
|
|
202
|
|
|
$this->getEmailer()->tutor($recipients, $tutors->guid, 'program'); |
|
203
|
|
|
|
|
204
|
|
|
$this->logInfo('Sending email to program tutor successfull, result: %s, %s', [ |
|
205
|
|
|
json_encode($recipients), |
|
206
|
|
|
$tutors->guid |
|
207
|
|
|
]); |
|
208
|
|
|
$this->flashSuccess('Email lektorovi byl odeslán..'); |
|
209
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
210
|
|
|
$this->logError('Sending email to program tutor failed, result: %s', [ |
|
211
|
|
|
$e->getMessage() |
|
212
|
|
|
]); |
|
213
|
|
|
$this->flashError('Email lektorovi nebyl odeslán, result: %s', [ |
|
|
|
|
|
|
214
|
|
|
$e->getMessage() |
|
215
|
|
|
]); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
$this->redirect('Program:edit', $id); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* View public program |
|
223
|
|
|
* |
|
224
|
|
|
* @return void |
|
225
|
|
|
*/ |
|
226
|
|
|
public function renderPublic() |
|
227
|
|
|
{ |
|
228
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId()); |
|
229
|
|
|
|
|
230
|
|
|
$template = $this->getTemplate(); |
|
231
|
|
|
$template->meeting_heading = $this->getMeetingModel()->getRegHeading(); |
|
|
|
|
|
|
232
|
|
|
////otevirani a uzavirani prihlasovani |
|
233
|
|
|
if(($this->getMeetingModel()->getRegOpening() < time()) || $this->getDebugMode()) { |
|
234
|
|
|
$template->display_program = true; |
|
|
|
|
|
|
235
|
|
|
} else { |
|
236
|
|
|
$template->display_program = false; |
|
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
$template->page_title = 'Srazy VS - veřejný program'; |
|
|
|
|
|
|
239
|
|
|
$template->style = 'table { border-collapse:separate; width:100%; } |
|
|
|
|
|
|
240
|
|
|
td { .width:100%; text-align:center; padding:0px; } |
|
241
|
|
|
td.day { border:1px solid black; background-color:#777777; width:80px; } |
|
242
|
|
|
td.time { background-color:#cccccc; width:80px; }'; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @return void |
|
247
|
|
|
*/ |
|
248
|
|
View Code Duplication |
public function renderListing() |
|
|
|
|
|
|
249
|
|
|
{ |
|
250
|
|
|
$model = $this->getModel(); |
|
251
|
|
|
$template = $this->getTemplate(); |
|
252
|
|
|
|
|
253
|
|
|
$template->programs = $model->all(); |
|
|
|
|
|
|
254
|
|
|
$template->mid = $this->meetingId; |
|
|
|
|
|
|
255
|
|
|
$template->heading = $this->heading; |
|
|
|
|
|
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @return void |
|
260
|
|
|
*/ |
|
261
|
|
|
public function renderNew() |
|
262
|
|
|
{ |
|
263
|
|
|
$template = $this->getTemplate(); |
|
264
|
|
|
|
|
265
|
|
|
$template->heading = 'nový program'; |
|
|
|
|
|
|
266
|
|
|
$template->page = $this->getHttpRequest()->getQuery('page'); |
|
|
|
|
|
|
267
|
|
|
$template->error_name = ''; |
|
|
|
|
|
|
268
|
|
|
$template->error_description = ''; |
|
|
|
|
|
|
269
|
|
|
$template->error_tutor = ''; |
|
|
|
|
|
|
270
|
|
|
$template->error_email = ''; |
|
|
|
|
|
|
271
|
|
|
$template->error_material = ''; |
|
|
|
|
|
|
272
|
|
|
$template->display_in_reg_checkbox = $this->renderHtmlCheckBox('display_in_reg', 0, 1); |
|
|
|
|
|
|
273
|
|
|
$template->block_select = $this->getBlockModel()->renderHtmlSelect(null); |
|
|
|
|
|
|
274
|
|
|
$template->selectedCategory = null; |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param integer $id |
|
279
|
|
|
* @return void |
|
280
|
|
|
*/ |
|
281
|
|
|
public function renderEdit($id) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->programId = $id; |
|
284
|
|
|
$program = $this->getModel()->find($id); |
|
285
|
|
|
|
|
286
|
|
|
$template = $this->getTemplate(); |
|
287
|
|
|
$template->heading = 'úprava programu'; |
|
|
|
|
|
|
288
|
|
|
$template->error_name = ''; |
|
|
|
|
|
|
289
|
|
|
$template->error_description = ''; |
|
|
|
|
|
|
290
|
|
|
$template->error_tutor = ''; |
|
|
|
|
|
|
291
|
|
|
$template->error_email = ''; |
|
|
|
|
|
|
292
|
|
|
$template->error_material = ''; |
|
|
|
|
|
|
293
|
|
|
$template->display_in_reg_checkbox = $this->renderHtmlCheckBox('display_in_reg', 1, $program->display_in_reg); |
|
|
|
|
|
|
294
|
|
|
$template->block_select = $this->getBlockModel()->renderHtmlSelect($program->block); |
|
|
|
|
|
|
295
|
|
|
$template->selectedCategory = $program->category; |
|
|
|
|
|
|
296
|
|
|
$template->program_visitors = $this->getModel()->getProgramVisitors($id); |
|
|
|
|
|
|
297
|
|
|
$template->program = $program; |
|
|
|
|
|
|
298
|
|
|
$template->id = $id; |
|
|
|
|
|
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @return ProgramOverviewControl |
|
303
|
|
|
*/ |
|
304
|
|
|
protected function createComponentProgramOverview() |
|
305
|
|
|
{ |
|
306
|
|
|
return $this->programOverview->setMeetingId($this->getMeetingId()); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* @return CategoryStylesControl |
|
311
|
|
|
*/ |
|
312
|
|
|
protected function createComponentCategoryStyles(): CategoryStylesControl |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->categoryStyles; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param ProgramOverviewControl $control |
|
319
|
|
|
* @return $this |
|
320
|
|
|
*/ |
|
321
|
|
|
protected function setProgramOverviewControl(IProgramOverviewControl $control) |
|
322
|
|
|
{ |
|
323
|
|
|
$this->programOverview = $control; |
|
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
return $this; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return Emailer |
|
330
|
|
|
*/ |
|
331
|
|
|
protected function getEmailer() |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->emailer; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param Emailer $emailer |
|
338
|
|
|
* @return $this |
|
339
|
|
|
*/ |
|
340
|
|
|
protected function setEmailer(Emailer $emailer) |
|
341
|
|
|
{ |
|
342
|
|
|
$this->emailer = $emailer; |
|
343
|
|
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return BlockModel |
|
348
|
|
|
*/ |
|
349
|
|
|
protected function getBlockModel() |
|
350
|
|
|
{ |
|
351
|
|
|
return $this->blockModel; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
/** |
|
355
|
|
|
* @param BlockModel $blockModel |
|
356
|
|
|
* @return $this |
|
357
|
|
|
*/ |
|
358
|
|
|
protected function setBlockModel(BlockModel $blockModel) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->blockModel = $blockModel; |
|
361
|
|
|
return $this; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @return MeetingModel |
|
366
|
|
|
*/ |
|
367
|
|
|
protected function getMeetingModel() |
|
368
|
|
|
{ |
|
369
|
|
|
return $this->meetingModel; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* @param MeetingModel $model |
|
374
|
|
|
* @return $this |
|
375
|
|
|
*/ |
|
376
|
|
|
protected function setMeetingModel(MeetingModel $model) |
|
377
|
|
|
{ |
|
378
|
|
|
$this->meetingModel = $model; |
|
379
|
|
|
return $this; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @param CategoryStylesControl $categoryStyles |
|
384
|
|
|
* |
|
385
|
|
|
* @return self |
|
386
|
|
|
*/ |
|
387
|
|
|
public function setCategoryStylesControl(CategoryStylesControl $categoryStyles): self |
|
388
|
|
|
{ |
|
389
|
|
|
$this->categoryStyles = $categoryStyles; |
|
390
|
|
|
|
|
391
|
|
|
return $this; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
} |
|
395
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: