|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Nette\Database\Context; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Blocks |
|
9
|
|
|
* |
|
10
|
|
|
* class for handling program blocks |
|
11
|
|
|
* |
|
12
|
|
|
* @created 2012-09-14 |
|
13
|
|
|
* @author Tomas Litera <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class BlockModel extends BaseModel |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
protected $table = 'kk_blocks'; |
|
20
|
|
|
|
|
21
|
|
|
/** @var array */ |
|
22
|
|
|
public $columns = [ |
|
23
|
|
|
'guid', |
|
24
|
|
|
'name', |
|
25
|
|
|
'day', |
|
26
|
|
|
'from', |
|
27
|
|
|
'to', |
|
28
|
|
|
'program', |
|
29
|
|
|
'display_progs', |
|
30
|
|
|
'description', |
|
31
|
|
|
'tutor', |
|
32
|
|
|
'email', |
|
33
|
|
|
'category', |
|
34
|
|
|
'material', |
|
35
|
|
|
'capacity', |
|
36
|
|
|
//"meeting", |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
private static $connection; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param Context $database |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(Context $database) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->setDatabase($database); |
|
47
|
|
|
self::$connection = $this->getDatabase(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return ActiveRow |
|
52
|
|
|
*/ |
|
53
|
|
|
public function all() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getDatabase() |
|
56
|
|
|
->query('SELECT blocks.guid AS guid, |
|
57
|
|
|
blocks.id AS id, |
|
58
|
|
|
blocks.name AS name, |
|
59
|
|
|
cat.name AS cat_name, |
|
60
|
|
|
day, |
|
61
|
|
|
DATE_FORMAT(`from`, "%H:%i") AS `from`, |
|
62
|
|
|
DATE_FORMAT(`to`, "%H:%i") AS `to`, |
|
63
|
|
|
description, |
|
64
|
|
|
tutor, |
|
65
|
|
|
email, |
|
66
|
|
|
style |
|
67
|
|
|
FROM kk_blocks AS blocks |
|
68
|
|
|
LEFT JOIN kk_categories AS cat ON cat.id = blocks.category |
|
69
|
|
|
WHERE blocks.meeting = ? AND blocks.deleted = ? |
|
70
|
|
|
ORDER BY day, `from` ASC', |
|
71
|
|
|
$this->getMeetingId(), '0') |
|
72
|
|
|
->fetchAll(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return blocks that contents programs |
|
77
|
|
|
* |
|
78
|
|
|
* @param int meeting ID |
|
79
|
|
|
* @return array result and number of affected rows |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getProgramBlocks($meetingId) |
|
82
|
|
|
{ |
|
83
|
|
|
$data = $this->getDatabase() |
|
84
|
|
|
->query('SELECT id, |
|
85
|
|
|
day, |
|
86
|
|
|
DATE_FORMAT(`from`, "%H:%i") AS `from`, |
|
87
|
|
|
DATE_FORMAT(`to`, "%H:%i") AS `to`, |
|
88
|
|
|
name, |
|
89
|
|
|
program |
|
90
|
|
|
FROM kk_blocks |
|
91
|
|
|
WHERE deleted = ? AND program = ? AND meeting = ? |
|
92
|
|
|
ORDER BY `day`, `from` ASC', |
|
93
|
|
|
'0', '1', $meetingId)->fetchAll(); |
|
94
|
|
|
|
|
95
|
|
|
return $data; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param integer $meetingId |
|
100
|
|
|
* @return ActiveRow |
|
101
|
|
|
*/ |
|
102
|
|
|
public function idsFromCurrentMeeting($meetingId) |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->getDatabase() |
|
105
|
|
|
->table($this->getTable()) |
|
106
|
|
|
->select('id') |
|
107
|
|
|
->where('meeting ? AND program ? AND deleted ?', $meetingId, '1', '0') |
|
108
|
|
|
->fetchAll(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param integer $meetingId |
|
113
|
|
|
* @param string $dayVal |
|
114
|
|
|
* @return ActiveRow |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getExportBlocks($meetingId, $dayVal) |
|
117
|
|
|
{ |
|
118
|
|
|
$result = $this->getDatabase() |
|
119
|
|
|
->query('SELECT blocks.id AS id, |
|
120
|
|
|
day, |
|
121
|
|
|
DATE_FORMAT(`from`, "%H:%i") AS `from`, |
|
122
|
|
|
DATE_FORMAT(`to`, "%H:%i") AS `to`, |
|
123
|
|
|
blocks.name AS name, |
|
124
|
|
|
program, |
|
125
|
|
|
display_progs, |
|
126
|
|
|
style, |
|
127
|
|
|
cat.id AS category |
|
128
|
|
|
FROM kk_blocks AS blocks |
|
129
|
|
|
LEFT JOIN kk_categories AS cat ON cat.id = blocks.category |
|
130
|
|
|
/* 18 - pauzy */ |
|
131
|
|
|
WHERE blocks.deleted = ? AND day = ? AND meeting = ? AND category != ? |
|
132
|
|
|
ORDER BY `from` ASC', |
|
133
|
|
|
'0', $dayVal, $meetingId, '18')->fetchAll(); |
|
134
|
|
|
|
|
135
|
|
|
return $result; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Get tutor e-mail address |
|
140
|
|
|
* |
|
141
|
|
|
* @param int $blockId id of block item |
|
142
|
|
|
* @return Nette\Database\Table\ActiveRow object with e-mail address |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getTutor($blockId) |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->getDatabase() |
|
147
|
|
|
->table($this->getTable()) |
|
148
|
|
|
->select('guid, email, tutor') |
|
149
|
|
|
->where('id ? AND deleted ?', $blockId, '0') |
|
150
|
|
|
->limit(1) |
|
151
|
|
|
->fetch(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param int $meetingId |
|
156
|
|
|
* @return Database |
|
157
|
|
|
*/ |
|
158
|
|
|
public function findByMeeting($meetingId) |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->getDatabase() |
|
161
|
|
|
->table($this->getTable()) |
|
162
|
|
|
->select('id, day, from, to, name') |
|
163
|
|
|
->where('meeting ? AND program ? AND deleted ?', $meetingId, '1', '0') |
|
164
|
|
|
->fetchAll(); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param string $day |
|
169
|
|
|
* @return Row |
|
170
|
|
|
*/ |
|
171
|
|
|
public function findByDay($day = '') |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->getDatabase() |
|
174
|
|
|
->query('SELECT blocks.id AS id, |
|
175
|
|
|
day, |
|
176
|
|
|
DATE_FORMAT(`from`, "%H:%i") AS `from`, |
|
177
|
|
|
DATE_FORMAT(`to`, "%H:%i") AS `to`, |
|
178
|
|
|
blocks.name AS name, |
|
179
|
|
|
program, |
|
180
|
|
|
style |
|
181
|
|
|
FROM kk_blocks AS blocks |
|
182
|
|
|
LEFT JOIN kk_categories AS cat ON cat.id = blocks.category |
|
183
|
|
|
WHERE blocks.deleted = ? AND day = ? AND blocks.meeting = ? |
|
184
|
|
|
ORDER BY `from` ASC', |
|
185
|
|
|
'0', $day, $this->getMeetingId()) |
|
186
|
|
|
->fetchAll(); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Return blocks that contents programs |
|
191
|
|
|
* |
|
192
|
|
|
* @param int meeting ID |
|
193
|
|
|
* @return array result and number of affected rows |
|
194
|
|
|
*/ |
|
195
|
|
|
public function findProgramBlocksByMeeting(int $meetingId) |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->getDatabase() |
|
198
|
|
|
->query('SELECT id, |
|
199
|
|
|
day, |
|
200
|
|
|
DATE_FORMAT(`from`, "%H:%i") AS `from`, |
|
201
|
|
|
DATE_FORMAT(`to`, "%H:%i") AS `to`, |
|
202
|
|
|
name, |
|
203
|
|
|
program |
|
204
|
|
|
FROM kk_blocks |
|
205
|
|
|
WHERE deleted = ? AND program = ? AND meeting = ? |
|
206
|
|
|
ORDER BY `day`, `from` ASC', |
|
207
|
|
|
'0', '1', $meetingId)->fetchAll(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function findByProgramId(int $programId) |
|
|
|
|
|
|
211
|
|
|
{ |
|
212
|
|
|
return $this->getDatabase() |
|
213
|
|
|
->query() |
|
214
|
|
|
->fetch(); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.