|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\ProgramModel; |
|
6
|
|
|
use App\Models\BlockModel; |
|
7
|
|
|
use App\Models\MeetingModel; |
|
8
|
|
|
use App\Services\Emailer; |
|
9
|
|
|
use Tracy\Debugger; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Program controller |
|
13
|
|
|
* |
|
14
|
|
|
* This file handles the retrieval and serving of blocks |
|
15
|
|
|
* |
|
16
|
|
|
* @created 2013-06-05 |
|
17
|
|
|
* @author Tomas Litera <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class ProgramPresenter extends BasePresenter |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var integer |
|
24
|
|
|
*/ |
|
25
|
|
|
private $programId = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Emailer |
|
29
|
|
|
*/ |
|
30
|
|
|
private $emailer; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var BlockModel |
|
34
|
|
|
*/ |
|
35
|
|
|
private $blockModel; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var MeetingModel |
|
39
|
|
|
*/ |
|
40
|
|
|
private $meetingModel; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Prepare model classes and get meeting id |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
ProgramModel $model, |
|
47
|
|
|
Emailer $emailer, |
|
48
|
|
|
BlockModel $blockModel, |
|
49
|
|
|
MeetingModel $meetingModel |
|
50
|
|
|
) { |
|
51
|
|
|
$this->setModel($model); |
|
|
|
|
|
|
52
|
|
|
$this->setEmailer($emailer); |
|
53
|
|
|
$this->setBlockModel($blockModel); |
|
54
|
|
|
$this->setMeetingModel($meetingModel); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function startup() |
|
61
|
|
|
{ |
|
62
|
|
|
parent::startup(); |
|
63
|
|
|
|
|
64
|
|
|
$meetingId = $this->getMeetingId(); |
|
65
|
|
|
$this->getModel()->setMeetingId($meetingId); |
|
66
|
|
|
$this->getMeetingModel()->setMeetingId($meetingId); |
|
67
|
|
|
$this->getBlockModel()->setMeetingId($meetingId); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
public function actionCreate() |
|
74
|
|
|
{ |
|
75
|
|
|
$model = $this->getModel(); |
|
|
|
|
|
|
76
|
|
|
$data = $this->getHttpRequest()->getPost(); |
|
77
|
|
|
|
|
78
|
|
|
$this->setBacklink($data['backlink']); |
|
79
|
|
|
unset($data['backlink']); |
|
80
|
|
|
|
|
81
|
|
|
if(!array_key_exists('display_in_reg', $data)) { |
|
82
|
|
|
$data['display_in_reg'] = 1; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
try { |
|
86
|
|
|
$result = $this->getModel()->create($data); |
|
87
|
|
|
|
|
88
|
|
|
Debugger::log('Creation of program successfull, result: ' . json_encode($result), Debugger::INFO); |
|
89
|
|
|
|
|
90
|
|
|
$this->flashMessage('Položka byla úspěšně vytvořena', 'ok'); |
|
91
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
92
|
|
|
Debugger::log('Creation of program with data ' . json_encode($data) . ' failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
93
|
|
|
|
|
94
|
|
|
$this->flashMessage('Záznam se nepodařilo uložit, result: ' . $e->getMessage(), 'error'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param integer $id |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
public function actionUpdate($id) |
|
105
|
|
|
{ |
|
106
|
|
|
$model = $this->getModel(); |
|
|
|
|
|
|
107
|
|
|
$data = $this->getHttpRequest()->getPost(); |
|
108
|
|
|
|
|
109
|
|
|
$this->setBacklink($data['backlink']); |
|
110
|
|
|
unset($data['backlink']); |
|
111
|
|
|
|
|
112
|
|
|
if(!array_key_exists('display_in_reg', $data)) { |
|
113
|
|
|
$data['display_in_reg'] = 1; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
try { |
|
117
|
|
|
$result = $this->getModel()->update($id, $data); |
|
118
|
|
|
|
|
119
|
|
|
Debugger::log('Modification of program id ' . $id . ' with data ' . json_encode($data) . ' successfull, result: ' . json_encode($result), Debugger::INFO); |
|
120
|
|
|
|
|
121
|
|
|
$this->flashMessage('Položka byla úspěšně upravena.', 'ok'); |
|
122
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
123
|
|
|
Debugger::log('Modification of program id ' . $id . ' failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
124
|
|
|
|
|
125
|
|
|
$this->flashMessage('Modification of program id ' . $id . ' failed, result: ' . $e->getMessage(), 'error'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$this->redirect($this->getBacklink() ?: 'Program:listing'); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param integer $id |
|
133
|
|
|
* @return void |
|
134
|
|
|
*/ |
|
135
|
|
View Code Duplication |
public function actionDelete($id) |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
try { |
|
138
|
|
|
$result = $this->getModel()->delete($id); |
|
139
|
|
|
Debugger::log('Destroying of program successfull, result: ' . json_encode($result), Debugger::INFO); |
|
140
|
|
|
$this->flashMessage('Položka byla úspěšně smazána.', 'ok'); |
|
141
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
142
|
|
|
Debugger::log('Destroying of program failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
143
|
|
|
$this->flashMessage('Smazání programu se nezdařilo, result: ' . $e->getMessage(), 'error'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$this->redirect('Program:listing'); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return void |
|
151
|
|
|
*/ |
|
152
|
|
View Code Duplication |
public function actionMail($id) |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
try { |
|
155
|
|
|
$tutors = $this->getModel()->getTutor($id); |
|
156
|
|
|
$recipients = $this->parseTutorEmail($tutors); |
|
157
|
|
|
|
|
158
|
|
|
$this->getEmailer()->tutor($recipients, $tutors->guid, 'program'); |
|
159
|
|
|
|
|
160
|
|
|
Debugger::log('Sending email to program tutor successfull, result: ' . json_encode($recipients) . ', ' . $tutors->guid, Debugger::INFO); |
|
161
|
|
|
$this->flashMessage('Email lektorovi byl odeslán..', 'ok'); |
|
162
|
|
|
} catch(Exception $e) { |
|
|
|
|
|
|
163
|
|
|
Debugger::log('Sending email to program tutor failed, result: ' . $e->getMessage(), Debugger::ERROR); |
|
164
|
|
|
$this->flashMessage('Email lektorovi nebyl odeslán, result: ' . $e->getMessage(), 'error'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$this->redirect('Program:edit', $id); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* View public program |
|
172
|
|
|
* |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
public function renderPublic() |
|
176
|
|
|
{ |
|
177
|
|
|
$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId()); |
|
178
|
|
|
|
|
179
|
|
|
$template = $this->getTemplate(); |
|
180
|
|
|
$template->meeting_heading = $this->getMeetingModel()->getRegHeading(); |
|
|
|
|
|
|
181
|
|
|
////otevirani a uzavirani prihlasovani |
|
182
|
|
|
if(($this->getMeetingModel()->getRegOpening() < time()) || $this->getDebugMode()) { |
|
183
|
|
|
$template->display_program = true; |
|
|
|
|
|
|
184
|
|
|
} else { |
|
185
|
|
|
$template->display_program = false; |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
$template->public_program = $this->getMeetingModel()->renderPublicProgramOverview($this->getMeetingId()); |
|
|
|
|
|
|
188
|
|
|
$template->page_title = 'Srazy VS - veřejný program'; |
|
|
|
|
|
|
189
|
|
|
$template->style = 'table { border-collapse:separate; width:100%; } |
|
|
|
|
|
|
190
|
|
|
td { .width:100%; text-align:center; padding:0px; } |
|
191
|
|
|
td.day { border:1px solid black; background-color:#777777; width:80px; } |
|
192
|
|
|
td.time { background-color:#cccccc; width:80px; }'; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @return void |
|
197
|
|
|
*/ |
|
198
|
|
View Code Duplication |
public function renderListing() |
|
|
|
|
|
|
199
|
|
|
{ |
|
200
|
|
|
$model = $this->getModel(); |
|
201
|
|
|
$template = $this->getTemplate(); |
|
202
|
|
|
|
|
203
|
|
|
$template->programs = $model->all(); |
|
|
|
|
|
|
204
|
|
|
$template->mid = $this->meetingId; |
|
|
|
|
|
|
205
|
|
|
$template->heading = $this->heading; |
|
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return void |
|
210
|
|
|
*/ |
|
211
|
|
|
public function renderNew() |
|
212
|
|
|
{ |
|
213
|
|
|
$template = $this->getTemplate(); |
|
214
|
|
|
|
|
215
|
|
|
$template->heading = 'nový program'; |
|
|
|
|
|
|
216
|
|
|
$template->page = $this->getHttpRequest()->getQuery('page'); |
|
|
|
|
|
|
217
|
|
|
$template->error_name = ''; |
|
|
|
|
|
|
218
|
|
|
$template->error_description = ''; |
|
|
|
|
|
|
219
|
|
|
$template->error_tutor = ''; |
|
|
|
|
|
|
220
|
|
|
$template->error_email = ''; |
|
|
|
|
|
|
221
|
|
|
$template->error_material = ''; |
|
|
|
|
|
|
222
|
|
|
$template->display_in_reg_checkbox = $this->renderHtmlCheckBox('display_in_reg', 0, 1); |
|
|
|
|
|
|
223
|
|
|
$template->block_select = $this->getBlockModel()->renderHtmlSelect(null); |
|
|
|
|
|
|
224
|
|
|
$template->selectedCategory = null; |
|
|
|
|
|
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param integer $id |
|
229
|
|
|
* @return void |
|
230
|
|
|
*/ |
|
231
|
|
|
public function renderEdit($id) |
|
232
|
|
|
{ |
|
233
|
|
|
$this->programId = $id; |
|
234
|
|
|
$program = $this->getModel()->find($id); |
|
235
|
|
|
|
|
236
|
|
|
$template = $this->getTemplate(); |
|
237
|
|
|
$template->heading = 'úprava programu'; |
|
|
|
|
|
|
238
|
|
|
$template->error_name = ''; |
|
|
|
|
|
|
239
|
|
|
$template->error_description = ''; |
|
|
|
|
|
|
240
|
|
|
$template->error_tutor = ''; |
|
|
|
|
|
|
241
|
|
|
$template->error_email = ''; |
|
|
|
|
|
|
242
|
|
|
$template->error_material = ''; |
|
|
|
|
|
|
243
|
|
|
$template->display_in_reg_checkbox = $this->renderHtmlCheckBox('display_in_reg', 1, $program->display_in_reg); |
|
|
|
|
|
|
244
|
|
|
$template->block_select = $this->getBlockModel()->renderHtmlSelect($program->block); |
|
|
|
|
|
|
245
|
|
|
$template->selectedCategory = $program->category; |
|
|
|
|
|
|
246
|
|
|
$template->program_visitors = $this->getModel()->getProgramVisitors($id); |
|
|
|
|
|
|
247
|
|
|
$template->program = $program; |
|
|
|
|
|
|
248
|
|
|
$template->id = $id; |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @return Emailer |
|
253
|
|
|
*/ |
|
254
|
|
|
protected function getEmailer() |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->emailer; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param Emailer $emailer |
|
261
|
|
|
* @return $this |
|
262
|
|
|
*/ |
|
263
|
|
|
protected function setEmailer(Emailer $emailer) |
|
264
|
|
|
{ |
|
265
|
|
|
$this->emailer = $emailer; |
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @return BlockModel |
|
271
|
|
|
*/ |
|
272
|
|
|
protected function getBlockModel() |
|
273
|
|
|
{ |
|
274
|
|
|
return $this->blockModel; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param BlockModel $blockModel |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
protected function setBlockModel(BlockModel $blockModel) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->blockModel = $blockModel; |
|
284
|
|
|
return $this; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @return MeetingModel |
|
289
|
|
|
*/ |
|
290
|
|
|
protected function getMeetingModel() |
|
291
|
|
|
{ |
|
292
|
|
|
return $this->meetingModel; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* @param MeetingModel $model |
|
297
|
|
|
* @return $this |
|
298
|
|
|
*/ |
|
299
|
|
|
protected function setMeetingModel(MeetingModel $model) |
|
300
|
|
|
{ |
|
301
|
|
|
$this->meetingModel = $model; |
|
302
|
|
|
return $this; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
} |
|
306
|
|
|
|
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: