-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
428 lines (360 loc) · 14.3 KB
/
query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<?php
require_once '../../db.php';
class Query {
public static function login($login, $senha) {
if ((null === $login) or ( null === $senha)) {
throw new Exception('Informe login e senha');
}
$con = Database::getCon();
$q = mysqli_query($con, "select * from professor where email = '{$login}' and senha = '{$senha}'");
$r = mysqli_fetch_array($q);
if (null !== $r) {
$_SESSION['user'] = array(
'id' => $r['idProfessor'],
'nome' => $r['nome'],
);
header('location: /index.php');
}
}
public static function pegarAlternativa($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select a.*, q.titulo q_titulo "
. "from alternativa a "
. "left join questao q "
. "on a.idQuestao = q.idQuestao "
. "where a.idQuestao = {$id} ");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarAlternativaQuiz($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select a.*, q.titulo q_titulo "
. "from alternativaquiz a "
. "left join questaoquiz q "
. "on a.idQuestaoquiz = q.idQuestaoquiz "
. "where a.idQuestaoquiz = {$id} ");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarAlunos($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select a.* "
. "from aluno a "
. "left join grupoaluno g "
. "on a.idAluno = g.idAluno "
. "where g.idGrupo = {$id}");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarAula($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from aula where idAula = {$id}");
$r = mysqli_fetch_assoc($q);
return $r;
}
public static function pegarAulas($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from aula where idProfessor = {$id} order by data desc");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarAulasGrupo($id, $prof) {
$con = Database::getCon();
$q = mysqli_query($con, "select a.*, g.status from aula a LEFT JOIN grupoaula g on (a.idAula = g.idAula) where a.idProfessor = {$prof} and g.idGrupo = {$id} order by data desc");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarAulasRelacionadas($id, $prof) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT a . * FROM aula a WHERE a.idProfessor = {$prof} AND a.idAula NOT IN (SELECT idAula FROM grupoaula WHERE idGrupo = {$id})");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarGrupo($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from grupo where idGrupo = {$id}");
return mysqli_fetch_assoc($q);
}
public static function pegarGrupos($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from grupo where idProfessor = {$id}");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarMateriais($id) {
$con = Database::getCon();
$q = mysqli_query($con, " SELECT a.*, a.status a_status, v.*, v.titulo as m3_titulo, s.*,s.titulo m2_titulo, q.*, q.titulo m1_titulo, qui.idQuiz, qui.titulo m4_titulo FROM aulamaterial a
LEFT JOIN video v on (v.idVideo = a.idMaterial) and (a.tipo = 3)
LEFT JOIN slide s on (s.idSlide = a.idMaterial) and (a.tipo = 2)
LEFT JOIN quiz qui on (qui.idQuiz = a.idMaterial) and (a.tipo = 4)
LEFT JOIN questionario q on (q.idQuestionario = a.idMaterial) and (a.tipo = 1)
WHERE a.idAula = {$id}
ORDER BY a.Tipo ASC");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarQuestionario($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM questionario
WHERE idQuestionario = {$id}");
return mysqli_fetch_assoc($q);
}
public static function pegarQuestionarios($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM questionario
WHERE idProfessor = {$id}
ORDER BY idQuestionario DESC");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarQuestao($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT a.*, q.titulo q_titulo
FROM alternativa a
LEFT JOIN questao q
ON a.idQuestao = q.idQuestao
WHERE idQuestao = {$id}
ORDER BY idQuestao");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarQuestoes($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM questao
WHERE idQuestionario = {$id}
ORDER BY idQuestao");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarQuestoesquiz($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM questaoquiz
WHERE idQuiz = {$id}
ORDER BY idQuiz");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarQuiz($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM quiz
WHERE idProfessor = {$id}
ORDER BY idQuiz DESC");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarRelacionados($idAula, $idTipo) {
$con = Database::getCon();
switch ($idTipo) {
case MATERIAL_QUESTIONARIO:
$sql = "SELECT q.*, q.idQuestionario id
FROM questionario q
WHERE q.idQuestionario not in (
SELECT a.idMaterial from aulamaterial a
WHERE a.tipo = {$idTipo}
AND a.idAula = {$idAula}
)
ORDER BY q.idQuestionario DESC";
break;
case MATERIAL_SLIDE:
$sql = "SELECT s.*, s.idSlide id
FROM slide s
WHERE s.idSlide not in (
SELECT a.idMaterial from aulamaterial a
WHERE a.tipo = {$idTipo}
AND a.idAula = {$idAula}
)
ORDER BY s.idSlide DESC";
break;
case MATERIAL_VIDEO:
$sql = "SELECT v.*, v.idVideo id
FROM video v
WHERE v.idVideo not in (
SELECT a.idMaterial from aulamaterial a
WHERE a.tipo = {$idTipo}
AND a.idAula = {$idAula}
)
ORDER BY v.idVideo DESC";
break;
default:
case MATERIAL_QUIZ:
$sql = "SELECT q.*, q.idQuiz id
FROM quiz q
WHERE q.idQuiz not in (
SELECT a.idMaterial from aulamaterial a
WHERE a.tipo = {$idTipo}
AND a.idAula = {$idAula}
)
ORDER BY q.idQuiz DESC";
break;
default:
break;
}
$q = mysqli_query($con, $sql);
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarRespostas($idQuestionario, $idAula, $tabela) {
$con = Database::getCon();
$queryAluno = "select * from aluno";
$qAluno = mysqli_query($con, $queryAluno);
$alunos = array();
if (mysqli_num_rows($qAluno)) {
while ($row = mysqli_fetch_assoc($qAluno)) {
$alunos[] = $row;
}
}
if ($tabela == "questionario") {
$queryResposta = "select r.*, a.*, a.titulo a_titulo, a.idAlternativa aluno, q.*, q.titulo q_titulo, ac.titulo ac_titulo, ac.idAlternativa correta "
. "from resposta r "
. "left join alternativa a on(a.idAlternativa = r.idAlternativa) "
. "left join alternativa ac on(ac.idQuestao = a.idQuestao) and (ac.correta = 1) "
. "left join questao q on(q.idQuestao = a.idQuestao) "
. "left join questionario que on(que.idQuestionario = q.idQuestionario) "
. "where que.idQuestionario = {$idQuestionario} "
. "order by r.idAluno";
}else if($tabela == "quiz"){
$queryResposta = "select r.*, a.*, a.titulo a_titulo, a.idAlternativaquiz aluno, q.*, q.titulo q_titulo, ac.titulo ac_titulo, ac.idAlternativaquiz correta "
. "from respostaquiz r "
. "left join alternativaquiz a on(a.idAlternativaquiz = r.idAlternativaquiz) "
. "left join alternativaquiz ac on(ac.idQuestaoquiz = a.idQuestaoquiz) and (ac.correta = 1) "
. "left join questaoquiz q on(q.idQuestaoquiz = a.idQuestaoquiz) "
. "left join quiz que on(que.idQuiz = q.idQuiz) "
. "where que.idQuiz = {$idQuestionario} "
. "order by r.idAluno";
}
$qResposta = mysqli_query($con, $queryResposta);
$respostas = array();
if (mysqli_num_rows($qResposta)) {
while ($row = mysqli_fetch_assoc($qResposta)) {
$respostas[] = $row;
}
}
return array('alunos' => $alunos, 'respostas' => $respostas);
}
public static function pegarSlide($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM slide WHERE idProfessor = {$id}");
return mysqli_fetch_assoc($q);
}
public static function pegarSlides($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM slide WHERE idProfessor = {$id}");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarSlideImg($id) {
$con = Database::getCon();
$q = mysqli_query($con, "SELECT * FROM slideimg WHERE idSlide = {$id}");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function pegarVideo($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from video where idVideo = {$id}");
return mysqli_fetch_assoc($q);
}
public static function pegarVideos($id) {
$con = Database::getCon();
$q = mysqli_query($con, "select * from video where idProfessor = {$id} order by idVideo desc");
$r = array();
if (null !== $q) {
while ($row = mysqli_fetch_assoc($q)) {
$r[] = $row;
}
}
return $r;
}
public static function salvarAula($id = null, $aula) {
$con = Database::getCon();
if (null == $id) {
$data = dateDb($aula['data']);
$titulo = $aula['titulo'];
$q = mysqli_query($con, "INSERT INTO aula (data, titulo) VALUES('{$data}', '{$titulo}' )");
} else {
$data = dateDb($aula['data']);
$titulo = $aula['titulo'];
$q = mysqli_query($con, "UPDATE aula SET (data = '{$data}', titulo = '{$titulo}') WHERE idAula = {$id}");
}
return $q;
}
}