|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use Nette, |
|
6
|
|
|
App\Model; |
|
7
|
|
|
use Nette\Utils\Strings; |
|
8
|
|
|
use Nette\Http\Request; |
|
9
|
|
|
use App\Models\SunlightModel; |
|
10
|
|
|
use Nette\Caching\Cache; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Base presenter for all application presenters. |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class BasePresenter extends Nette\Application\UI\Presenter |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
const FLASH_TYPE_OK = 'success'; |
|
19
|
|
|
const FLASH_TYPE_ERROR = 'alert'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public $backlink = ''; |
|
25
|
|
|
|
|
26
|
|
|
/** @var Model */ |
|
27
|
|
|
protected $model; |
|
28
|
|
|
|
|
29
|
|
|
/** @var Nette\DI\Container */ |
|
30
|
|
|
protected $container; |
|
31
|
|
|
|
|
32
|
|
|
/** @var Latte */ |
|
33
|
|
|
protected $latte; |
|
34
|
|
|
|
|
35
|
|
|
/** @var Router */ |
|
36
|
|
|
protected $router; |
|
37
|
|
|
|
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
protected $action; |
|
40
|
|
|
|
|
41
|
|
|
/** @var Nette\Http\Request */ |
|
42
|
|
|
protected $request; |
|
43
|
|
|
|
|
44
|
|
|
/** @var integer */ |
|
45
|
|
|
protected $meetingId; |
|
46
|
|
|
|
|
47
|
|
|
protected $days = [ |
|
48
|
|
|
'pátek' => 'pátek', |
|
49
|
|
|
'sobota' => 'sobota', |
|
50
|
|
|
'neděle' => 'neděle', |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
protected $hours = [ |
|
54
|
|
|
0 => "00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23" |
|
|
|
|
|
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
protected $minutes = [ |
|
58
|
|
|
00 => "00", |
|
|
|
|
|
|
59
|
|
|
05 => "05", |
|
|
|
|
|
|
60
|
|
|
10 => "10", |
|
|
|
|
|
|
61
|
|
|
15 => "15", |
|
|
|
|
|
|
62
|
|
|
20 => "20", |
|
|
|
|
|
|
63
|
|
|
25 => "25", |
|
|
|
|
|
|
64
|
|
|
30 => "30", |
|
|
|
|
|
|
65
|
|
|
35 => "35", |
|
|
|
|
|
|
66
|
|
|
40 => "40", |
|
|
|
|
|
|
67
|
|
|
45 => "45", |
|
|
|
|
|
|
68
|
|
|
50 => "50", |
|
|
|
|
|
|
69
|
|
|
55 => "55", |
|
|
|
|
|
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Startup |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function startup() |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
parent::startup(); |
|
78
|
|
|
|
|
79
|
|
|
$meetingId = $this->getHttpRequest()->getQuery('mid', ''); |
|
80
|
|
|
|
|
81
|
|
|
$backlink = $this->getHttpRequest()->getQuery('backlink'); |
|
82
|
|
|
if(!empty($backlink)) { |
|
83
|
|
|
$this->setBacklink($backlink); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if($meetingId){ |
|
87
|
|
|
$_SESSION['meetingID'] = $meetingId; |
|
88
|
|
|
} elseif(!isset($_SESSION['meetingID'])) { |
|
89
|
|
|
$meeting = $this->getContainer()->getService('meeting'); |
|
90
|
|
|
$_SESSION['meetingID'] = $meeting->getLastMeetingId(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->setMeetingId($_SESSION['meetingID']); |
|
94
|
|
|
|
|
95
|
|
|
$model = $this->getModel(); |
|
96
|
|
|
if($model) { |
|
97
|
|
|
$model->setMeetingId($_SESSION['meetingID']); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->debugMode = $this->getContainer()->getParameters()['debugMode']; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Before render |
|
106
|
|
|
* Prepare variables for template |
|
107
|
|
|
*/ |
|
108
|
|
|
public function beforeRender() |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
|
|
parent::beforeRender(); |
|
111
|
|
|
|
|
112
|
|
|
$template = $this->getTemplate(); |
|
113
|
|
|
$meeting = $this->getContainer()->getService('meeting'); |
|
114
|
|
|
|
|
115
|
|
|
$template->baseDir = ROOT_DIR; |
|
|
|
|
|
|
116
|
|
|
$template->wwwDir = HTTP_DIR; |
|
|
|
|
|
|
117
|
|
|
$template->cssDir = CSS_DIR; |
|
|
|
|
|
|
118
|
|
|
$template->jsDir = JS_DIR; |
|
|
|
|
|
|
119
|
|
|
$template->imgDir = IMG_DIR; |
|
|
|
|
|
|
120
|
|
|
$template->catDir = CAT_DIR; |
|
|
|
|
|
|
121
|
|
|
$template->blockDir = BLOCK_DIR; |
|
|
|
|
|
|
122
|
|
|
$template->progDir = PROG_DIR; |
|
|
|
|
|
|
123
|
|
|
$template->visitDir = VISIT_DIR; |
|
|
|
|
|
|
124
|
|
|
$template->expDir = EXP_DIR; |
|
|
|
|
|
|
125
|
|
|
$template->meetDir = MEET_DIR; |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
$template->categories = $this->remember('categories:all', 10, function () { |
|
|
|
|
|
|
128
|
|
|
return $this->getContainer()->getService('category')->all(); |
|
129
|
|
|
}); |
|
130
|
|
|
|
|
131
|
|
|
if(isset($_SESSION[SESSION_PREFIX.'user'])) { |
|
132
|
|
|
$template->user = $this->getSunlight()->findUser($_SESSION[SESSION_PREFIX.'user']); |
|
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
$template->meeting = $meeting->getPlaceAndYear($_SESSION['meetingID']); |
|
|
|
|
|
|
135
|
|
|
$template->menuItems = $meeting->getMenuItems(); |
|
|
|
|
|
|
136
|
|
|
$template->meeting_heading = $meeting->getRegHeading(); |
|
|
|
|
|
|
137
|
|
|
$template->meetingId = $this->getMeetingId(); |
|
|
|
|
|
|
138
|
|
|
$template->backlinkUrl = $this->getBacklinkUrl(); |
|
|
|
|
|
|
139
|
|
|
$template->backlink = $this->getBacklink(); |
|
|
|
|
|
|
140
|
|
|
//$this->template->backlink = $this->getParameter("backlink"); |
|
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
//$this->template->production = $this->context->parameters['environment'] === 'production' ? 1 : 0; |
|
|
|
|
|
|
143
|
|
|
//$this->template->version = $this->context->parameters['site']['version']; |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* template |
|
148
|
|
|
* @var string |
|
149
|
|
|
*/ |
|
150
|
|
|
protected $template = 'listing'; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* template directory |
|
154
|
|
|
* @var string |
|
155
|
|
|
*/ |
|
156
|
|
|
protected $templateDir = ''; |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* category ID |
|
160
|
|
|
* @var integer |
|
161
|
|
|
*/ |
|
162
|
|
|
protected $itemId = NULL; |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* action what to do |
|
166
|
|
|
* @var string |
|
167
|
|
|
*/ |
|
168
|
|
|
protected $cms = ''; |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* page where to return |
|
172
|
|
|
* @var string |
|
173
|
|
|
*/ |
|
174
|
|
|
protected $page = ''; |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* heading tetxt |
|
178
|
|
|
* @var string |
|
179
|
|
|
*/ |
|
180
|
|
|
protected $heading = ''; |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* action what to do next |
|
184
|
|
|
* @var string |
|
185
|
|
|
*/ |
|
186
|
|
|
protected $todo = ''; |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* data |
|
190
|
|
|
* @var array |
|
191
|
|
|
*/ |
|
192
|
|
|
protected $data = array(); |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* error handler |
|
196
|
|
|
* @var string |
|
197
|
|
|
*/ |
|
198
|
|
|
protected $error = ''; |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* database connection |
|
202
|
|
|
* @var string |
|
203
|
|
|
*/ |
|
204
|
|
|
protected $database = NULL; |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* debug mode |
|
208
|
|
|
* @var boolean |
|
209
|
|
|
*/ |
|
210
|
|
|
protected $debugMode = false; |
|
211
|
|
|
|
|
212
|
|
|
protected $sunlight; |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Render check box |
|
216
|
|
|
* |
|
217
|
|
|
* @param string name |
|
218
|
|
|
* @param mixed value |
|
219
|
|
|
* @param var variable that match with value |
|
220
|
|
|
* @return string html of chceck box |
|
221
|
|
|
*/ |
|
222
|
|
|
protected function renderHtmlCheckBox($name, $value, $checked_variable) |
|
|
|
|
|
|
223
|
|
|
{ |
|
224
|
|
|
if($checked_variable == $value) { |
|
225
|
|
|
$checked = 'checked'; |
|
226
|
|
|
} else { |
|
227
|
|
|
$checked = ''; |
|
228
|
|
|
} |
|
229
|
|
|
$html_checkbox = "<input name='".$name."' type='checkbox' value='".$value."' ".$checked." />"; |
|
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
return $html_checkbox; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
protected function parseTutorEmail($item) |
|
235
|
|
|
{ |
|
236
|
|
|
$mails = explode(',', $item->email); |
|
237
|
|
|
$names = explode(',', $item->tutor); |
|
238
|
|
|
|
|
239
|
|
|
$i = 0; |
|
240
|
|
|
foreach ($mails as $mail) { |
|
241
|
|
|
$mail = trim($mail); |
|
242
|
|
|
$name = trim($names[$i]); |
|
243
|
|
|
|
|
244
|
|
|
$recipient[$mail] = ($name) ? $name : ''; |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
return $recipient; |
|
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
// zaheshovane udaje, aby se nedali jen tak ziskat data z databaze |
|
251
|
|
|
protected function formKeyHash($id, $meetingId) |
|
252
|
|
|
{ |
|
253
|
|
|
return ((int)$id . $meetingId) * 116 + 39147; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @return Model |
|
258
|
|
|
*/ |
|
259
|
|
|
protected function getModel() |
|
260
|
|
|
{ |
|
261
|
|
|
return $this->model; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @param Model $model |
|
266
|
|
|
* @return $this |
|
267
|
|
|
*/ |
|
268
|
|
|
protected function setModel($model) |
|
269
|
|
|
{ |
|
270
|
|
|
$this->model = $model; |
|
271
|
|
|
return $this; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @return Container |
|
276
|
|
|
*/ |
|
277
|
|
|
protected function getContainer() |
|
278
|
|
|
{ |
|
279
|
|
|
return $this->context; |
|
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @param Container $container |
|
284
|
|
|
* @return $this |
|
285
|
|
|
*/ |
|
286
|
|
|
protected function setContainer($container) |
|
287
|
|
|
{ |
|
288
|
|
|
$this->context = $container; |
|
|
|
|
|
|
289
|
|
|
return $this; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @return Router |
|
294
|
|
|
*/ |
|
295
|
|
|
protected function getRouter() |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->router; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @param Router $router |
|
302
|
|
|
* @return $this |
|
303
|
|
|
*/ |
|
304
|
|
|
protected function setRouter($router) |
|
305
|
|
|
{ |
|
306
|
|
|
$this->router = $router; |
|
307
|
|
|
return $this; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* @return Latte |
|
312
|
|
|
*/ |
|
313
|
|
|
protected function getLatte() |
|
314
|
|
|
{ |
|
315
|
|
|
return $this->latte; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @param Latte $latte |
|
320
|
|
|
* @return $this |
|
321
|
|
|
*/ |
|
322
|
|
|
protected function setLatte($latte) |
|
323
|
|
|
{ |
|
324
|
|
|
$this->latte = $latte; |
|
325
|
|
|
return $this; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return string |
|
330
|
|
|
*/ |
|
331
|
|
|
public function getAction($fullyQualified = false) |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->action; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param string $action |
|
338
|
|
|
* @return $this |
|
339
|
|
|
*/ |
|
340
|
|
|
public function setAction($action) |
|
341
|
|
|
{ |
|
342
|
|
|
$this->action = $action; |
|
343
|
|
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return SunlightModel |
|
348
|
|
|
*/ |
|
349
|
|
|
public function getSunlight() |
|
350
|
|
|
{ |
|
351
|
|
|
if(empty($this->sunlight)) { |
|
352
|
|
|
$this->setSunlight($this->getContainer()->getService('sunlight')); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
return $this->sunlight; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* @param SunlightModel $sunlight |
|
360
|
|
|
* @return $this |
|
361
|
|
|
*/ |
|
362
|
|
|
public function setSunlight(SunlightModel $sunlight) |
|
363
|
|
|
{ |
|
364
|
|
|
$this->sunlight = $sunlight; |
|
365
|
|
|
return $this; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* @return integer |
|
370
|
|
|
*/ |
|
371
|
|
|
protected function getMeetingId() |
|
372
|
|
|
{ |
|
373
|
|
|
return $this->meetingId; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* @param integer $meetingId |
|
378
|
|
|
* @return $this |
|
379
|
|
|
*/ |
|
380
|
|
|
protected function setMeetingId($meetingId) |
|
381
|
|
|
{ |
|
382
|
|
|
$this->meetingId = $meetingId; |
|
383
|
|
|
return $this; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* @param string $guid |
|
388
|
|
|
* @param array $data |
|
389
|
|
|
* @return ActiveRow |
|
390
|
|
|
*/ |
|
391
|
|
|
protected function updateByGuid($guid, array $data) |
|
392
|
|
|
{ |
|
393
|
|
|
return $this->getModel()->updateBy('guid', $guid, $data); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
public function remember($key, $minutes, \Closure $callback) |
|
397
|
|
|
{ |
|
398
|
|
|
// If the item exists in the cache we will just return this immediately |
|
399
|
|
|
// otherwise we will execute the given Closure and cache the result |
|
400
|
|
|
// of that execution for the given number of minutes in storage. |
|
401
|
|
|
if (! is_null($data = $this->getCache()->load($key))) { |
|
402
|
|
|
$items = []; |
|
403
|
|
|
|
|
404
|
|
|
foreach($data as $item) { |
|
405
|
|
|
$object = new \stdClass(); |
|
406
|
|
|
foreach ($item as $key => $value) { |
|
407
|
|
|
$object->$key = $value; |
|
408
|
|
|
} |
|
409
|
|
|
$items[] = $object; |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
return $items; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
$data = $callback(); |
|
416
|
|
|
$serialized = []; |
|
417
|
|
|
foreach ($data as $item) { |
|
418
|
|
|
$serialized[] = $item->toArray(); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
$this->getCache()->save( |
|
422
|
|
|
$key, |
|
423
|
|
|
$serialized, |
|
424
|
|
|
[ |
|
425
|
|
|
Cache::EXPIRE => $minutes . ' minutes', |
|
426
|
|
|
] |
|
427
|
|
|
); |
|
428
|
|
|
|
|
429
|
|
|
return $data; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
protected function getCache() |
|
433
|
|
|
{ |
|
434
|
|
|
return $this->getContainer()->getService('cache'); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
/** |
|
438
|
|
|
* @return string |
|
439
|
|
|
*/ |
|
440
|
|
|
protected function getDebugMode() |
|
441
|
|
|
{ |
|
442
|
|
|
return $this->debugMode; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* @return string |
|
447
|
|
|
*/ |
|
448
|
|
|
protected function getBacklink() |
|
449
|
|
|
{ |
|
450
|
|
|
return $this->backlink; |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* @param string $backlink |
|
455
|
|
|
* @return $this |
|
456
|
|
|
*/ |
|
457
|
|
|
protected function setBacklink($backlink) |
|
458
|
|
|
{ |
|
459
|
|
|
$this->backlink = $backlink; |
|
460
|
|
|
|
|
461
|
|
|
return $this; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* @return string |
|
466
|
|
|
*/ |
|
467
|
|
|
protected function getBacklinkUrl() |
|
468
|
|
|
{ |
|
469
|
|
|
if($this->getBacklink()) { |
|
470
|
|
|
return $this->link( |
|
471
|
|
|
$this->getBacklink(), |
|
472
|
|
|
[ |
|
473
|
|
|
'backlink' => null |
|
474
|
|
|
] |
|
475
|
|
|
); |
|
476
|
|
|
} |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
} |
|
480
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.