|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Nette\Database\Context; |
|
6
|
|
|
use App\Models\ProgramModel; |
|
7
|
|
|
use App\Models\BaseModel; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Meeting |
|
11
|
|
|
* |
|
12
|
|
|
* class for handling meeting |
|
13
|
|
|
* |
|
14
|
|
|
* @created 2012-11-09 |
|
15
|
|
|
* @author Tomas Litera <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class MeetingModel extends BaseModel |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
private $weekendDays = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
public $form_names = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
public $dbColumns = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var DateTime |
|
37
|
|
|
*/ |
|
38
|
|
|
public $regOpening = NULL; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var DateTime |
|
42
|
|
|
*/ |
|
43
|
|
|
public $regClosing = NULL; |
|
44
|
|
|
|
|
45
|
|
|
/** @var string registration heading text */ |
|
46
|
|
|
public $regHeading = ''; |
|
47
|
|
|
|
|
48
|
|
|
public $eventId; |
|
49
|
|
|
public $courseId; |
|
50
|
|
|
|
|
51
|
|
|
private $configuration; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
private $program; |
|
54
|
|
|
private $httpEncoding; |
|
55
|
|
|
private $dbTable; |
|
56
|
|
|
|
|
57
|
|
|
protected $table = 'kk_meetings'; |
|
58
|
|
|
|
|
59
|
|
|
/** Constructor */ |
|
60
|
|
|
public function __construct(Context $database, ProgramModel $program) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->weekendDays = array("pátek", "sobota", "neděle"); |
|
63
|
|
|
$this->form_names = array( |
|
64
|
|
|
"place", |
|
65
|
|
|
"start_date", |
|
66
|
|
|
"end_date", |
|
67
|
|
|
"open_reg", |
|
68
|
|
|
"close_reg", |
|
69
|
|
|
"contact", |
|
70
|
|
|
"email", |
|
71
|
|
|
"gsm", |
|
72
|
|
|
"cost", |
|
73
|
|
|
"advance", |
|
74
|
|
|
"numbering", |
|
75
|
|
|
'skautis_event_id', |
|
76
|
|
|
'skautis_course_id', |
|
77
|
|
|
); |
|
78
|
|
|
$this->dbColumns = array( |
|
79
|
|
|
"place", |
|
80
|
|
|
"start_date", |
|
81
|
|
|
"end_date", |
|
82
|
|
|
"open_reg", |
|
83
|
|
|
"close_reg", |
|
84
|
|
|
"contact", |
|
85
|
|
|
"email", |
|
86
|
|
|
"gsm", |
|
87
|
|
|
"cost", |
|
88
|
|
|
"advance", |
|
89
|
|
|
"numbering", |
|
90
|
|
|
'skautis_event_id', |
|
91
|
|
|
'skautis_course_id', |
|
92
|
|
|
); |
|
93
|
|
|
$this->dbTable = "kk_meetings"; |
|
94
|
|
|
$this->setDatabase($database); |
|
95
|
|
|
$this->program = $program; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param string $encoding |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setHttpEncoding($encoding) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->httpEncoding = $encoding; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Create new or return existing instance of class |
|
108
|
|
|
* |
|
109
|
|
|
* @return mixed instance of class |
|
110
|
|
|
*/ |
|
111
|
|
|
public static function getInstance() |
|
112
|
|
|
{ |
|
113
|
|
|
if(self::$instance === false) { |
|
114
|
|
|
self::$instance = new self(); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
return self::$instance; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return Nette\Database\Table\IRow |
|
121
|
|
|
*/ |
|
122
|
|
|
public function all() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->getDatabase() |
|
125
|
|
|
->table($this->getTable()) |
|
126
|
|
|
->where('deleted', '0') |
|
127
|
|
|
->fetchAll(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param int $id |
|
132
|
|
|
* @return Nette\Database\Table\IRow |
|
133
|
|
|
*/ |
|
134
|
|
|
public function find($id) |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->getDatabase() |
|
137
|
|
|
->table($this->getTable()) |
|
138
|
|
|
->where('deleted ? AND id ?', '0', $id) |
|
139
|
|
|
->fetch(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Create a new record |
|
144
|
|
|
* |
|
145
|
|
|
* @param mixed array of data |
|
146
|
|
|
* @return boolean |
|
147
|
|
|
*/ |
|
148
|
|
|
public function create(array $data) |
|
149
|
|
|
{ |
|
150
|
|
|
$data['guid'] = md5(uniqid()); |
|
151
|
|
|
$result = $this->getDatabase()->query('INSERT INTO ' . $this->getTable(), $data); |
|
152
|
|
|
|
|
153
|
|
|
return $result; |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Modify record |
|
158
|
|
|
* |
|
159
|
|
|
* @param int $id ID of record |
|
160
|
|
|
* @param array $db_data array of data |
|
|
|
|
|
|
161
|
|
|
* @return bool |
|
162
|
|
|
*/ |
|
163
|
|
|
public function update($id, array $data) |
|
164
|
|
|
{ |
|
165
|
|
|
$result = $this->getDatabase()->table($this->getTable())->where('id', $id)->update($data); |
|
166
|
|
|
|
|
167
|
|
|
return $result; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Delete one or multiple record/s |
|
172
|
|
|
* |
|
173
|
|
|
* @param int ID/s of record |
|
174
|
|
|
* @return boolean |
|
175
|
|
|
*/ |
|
176
|
|
View Code Duplication |
public function delete($ids) |
|
|
|
|
|
|
177
|
|
|
{ |
|
178
|
|
|
$data = array('deleted' => '1'); |
|
179
|
|
|
$result = $this->getDatabase()->table($this->getTable())->where('id', $ids)->update($data); |
|
180
|
|
|
|
|
181
|
|
|
return $result; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Return meeting data |
|
186
|
|
|
* |
|
187
|
|
|
* @return Nette\Database\Table\IRow |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getData($meetingId = null) |
|
190
|
|
|
{ |
|
191
|
|
|
if(isset($meetingId)) { |
|
192
|
|
|
$data = $this->find($meetingId); |
|
193
|
|
|
} else { |
|
194
|
|
|
$data = $this->all(); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
if(!$data) { |
|
198
|
|
|
return 0; |
|
199
|
|
|
} else { |
|
200
|
|
|
return $data; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param string $priceType cost|advance |
|
206
|
|
|
* @return integer |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getPrice($priceType) |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->getDatabase() |
|
211
|
|
|
->table($this->getTable()) |
|
212
|
|
|
->select($priceType) |
|
213
|
|
|
->where('id', $this->getMeetingId()) |
|
214
|
|
|
->limit(1) |
|
215
|
|
|
->fetchField(); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Render HTML Provinces <select> |
|
220
|
|
|
* |
|
221
|
|
|
* @param int ID of selected province |
|
222
|
|
|
* @return string html <select> |
|
223
|
|
|
*/ |
|
224
|
|
|
public function renderHtmlProvinceSelect($selectedProvince) |
|
225
|
|
|
{ |
|
226
|
|
|
$html_select = "<select style='width: 195px; font-size: 10px' name='province'>\n"; |
|
227
|
|
|
|
|
228
|
|
|
$result = $this->getDatabase() |
|
229
|
|
|
->table('kk_provinces') |
|
230
|
|
|
->fetchAll(); |
|
231
|
|
|
|
|
232
|
|
|
foreach($result as $data) { |
|
233
|
|
|
if($data['id'] == $selectedProvince) { |
|
234
|
|
|
$sel = "selected"; |
|
235
|
|
|
} |
|
236
|
|
|
else $sel = ""; |
|
237
|
|
|
$html_select .= "<option value='" . $data['id'] . "' " . $sel . ">" . $data['province_name'] . "</option>"; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
$html_select .= "</select>\n"; |
|
241
|
|
|
|
|
242
|
|
|
return $html_select; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @param integer $meetingId |
|
247
|
|
|
* @return $this |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setRegistrationHandlers($meetingId = 1) |
|
250
|
|
|
{ |
|
251
|
|
|
$meeting = $this->getDatabase() |
|
252
|
|
|
->table($this->getTable()) |
|
253
|
|
|
->select('id') |
|
254
|
|
|
->select('place') |
|
255
|
|
|
->select('DATE_FORMAT(start_date, "%Y") AS year') |
|
256
|
|
|
->select('UNIX_TIMESTAMP(open_reg) AS open_reg') |
|
257
|
|
|
->select('UNIX_TIMESTAMP(close_reg) AS close_reg') |
|
258
|
|
|
->where('id', $meetingId) |
|
259
|
|
|
->order('id DESC') |
|
260
|
|
|
->limit(1) |
|
261
|
|
|
->fetch(); |
|
262
|
|
|
|
|
263
|
|
|
$this->setRegHeading($meeting->place . ' ' . $meeting->year); |
|
264
|
|
|
$this->setRegClosing($meeting->close_reg); |
|
265
|
|
|
$this->setRegOpening($meeting->open_reg); |
|
266
|
|
|
|
|
267
|
|
|
return $this; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return string |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getRegOpening() |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->regOpening; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param string $value |
|
280
|
|
|
* @return $this |
|
281
|
|
|
*/ |
|
282
|
|
|
public function setRegOpening($value = '') |
|
283
|
|
|
{ |
|
284
|
|
|
$this->regOpening = $value; |
|
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
return $this; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @return string |
|
291
|
|
|
*/ |
|
292
|
|
|
public function getRegClosing() |
|
293
|
|
|
{ |
|
294
|
|
|
return $this->regClosing; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @param string $value |
|
299
|
|
|
* @return $this |
|
300
|
|
|
*/ |
|
301
|
|
|
public function setRegClosing($value = '') |
|
302
|
|
|
{ |
|
303
|
|
|
$this->regClosing = $value; |
|
|
|
|
|
|
304
|
|
|
|
|
305
|
|
|
return $this; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* @return string |
|
310
|
|
|
*/ |
|
311
|
|
|
public function getRegHeading() |
|
312
|
|
|
{ |
|
313
|
|
|
return $this->regHeading; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @param string $value |
|
318
|
|
|
* @return $this |
|
319
|
|
|
*/ |
|
320
|
|
|
public function setRegHeading($value = '') |
|
321
|
|
|
{ |
|
322
|
|
|
$this->regHeading = $value; |
|
323
|
|
|
|
|
324
|
|
|
return $this; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Is registration open? |
|
329
|
|
|
* |
|
330
|
|
|
* @return boolean |
|
331
|
|
|
*/ |
|
332
|
|
|
public function isRegOpen($debug = false) |
|
333
|
|
|
{ |
|
334
|
|
|
return (($this->getRegOpening() < time()) && (time() < $this->getRegClosing()) || $debug); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @param integer $id |
|
339
|
|
|
* @return string |
|
340
|
|
|
*/ |
|
341
|
|
|
public function getProvinceNameById($id) |
|
342
|
|
|
{ |
|
343
|
|
|
return $this->getDatabase() |
|
344
|
|
|
->table('kk_provinces') |
|
345
|
|
|
->select('province_name') |
|
346
|
|
|
->where('id', $id) |
|
347
|
|
|
->limit(1) |
|
348
|
|
|
->fetchField('province_name'); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @return Row |
|
353
|
|
|
*/ |
|
354
|
|
|
public function findEventId() |
|
355
|
|
|
{ |
|
356
|
|
|
return $this->getDatabase() |
|
357
|
|
|
->table($this->getTable()) |
|
358
|
|
|
->where('id', $this->getMeetingId()) |
|
359
|
|
|
->limit(1) |
|
360
|
|
|
->fetchField('skautis_event_id'); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* @return Row |
|
365
|
|
|
*/ |
|
366
|
|
|
public function findCourseId() |
|
367
|
|
|
{ |
|
368
|
|
|
return $this->getDatabase() |
|
369
|
|
|
->table($this->getTable()) |
|
370
|
|
|
->where('id', $this->getMeetingId()) |
|
371
|
|
|
->limit(1) |
|
372
|
|
|
->fetchField('skautis_course_id'); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @param integer|string $meetingId |
|
377
|
|
|
* @return ActiveRow |
|
378
|
|
|
*/ |
|
379
|
|
|
public function getPlaceAndYear($meetingId) |
|
380
|
|
|
{ |
|
381
|
|
|
return $this->getDatabase() |
|
382
|
|
|
->table($this->getTable()) |
|
383
|
|
|
->select('place') |
|
384
|
|
|
->select('DATE_FORMAT(start_date, "%Y") AS year') |
|
385
|
|
|
->where('id = ? AND deleted = ?', $meetingId, '0') |
|
386
|
|
|
->limit(1) |
|
387
|
|
|
->fetch(); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* @return ActiveRow |
|
392
|
|
|
*/ |
|
393
|
|
|
public function getMenuItems() |
|
394
|
|
|
{ |
|
395
|
|
|
return $this->getDatabase() |
|
396
|
|
|
->table($this->getTable()) |
|
397
|
|
|
->select('id AS mid') |
|
398
|
|
|
->select('place') |
|
399
|
|
|
->select('DATE_FORMAT(start_date, "%Y") AS year') |
|
400
|
|
|
->where('deleted', '0') |
|
401
|
|
|
->order('id DESC') |
|
402
|
|
|
->fetchAll(); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* @return integer |
|
407
|
|
|
*/ |
|
408
|
|
|
public function getLastMeetingId() |
|
409
|
|
|
{ |
|
410
|
|
|
return $this->getDatabase() |
|
411
|
|
|
->table($this->getTable()) |
|
412
|
|
|
->select('id') |
|
413
|
|
|
->order('id DESC') |
|
414
|
|
|
->limit(1) |
|
415
|
|
|
->fetchField(); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
} |
|
419
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.