1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// $Id: assessment_resultados.php,v 1.7 2007/03/24 14:41:41 marcellobrandao Exp $ |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
6
|
|
|
// <http://www.xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* assessment_resultados class. |
31
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
32
|
|
|
* of XOOPS user class objects. |
33
|
|
|
*/ |
34
|
|
|
class assessment_resultados extends XoopsObject |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
public $db; |
37
|
|
|
|
38
|
|
|
// constructor |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param null $id |
42
|
|
|
* @return assessment_resultados |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function __construct($id = null) |
45
|
|
|
{ |
46
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
47
|
|
|
$this->initVar('cod_resultado', XOBJ_DTYPE_INT, null, false, 10); |
48
|
|
|
$this->initVar('cod_prova', XOBJ_DTYPE_INT, null, false, 10); |
49
|
|
|
$this->initVar('uid_aluno', XOBJ_DTYPE_INT, null, false, 10); |
50
|
|
|
$this->initVar('data_inicio', XOBJ_DTYPE_TXTBOX, null, false); |
51
|
|
|
$this->initVar('data_fim', XOBJ_DTYPE_TXTBOX, null, false); |
52
|
|
|
$this->initVar('resp_certas', XOBJ_DTYPE_TXTBOX, null, false); |
53
|
|
|
$this->initVar('resp_erradas', XOBJ_DTYPE_TXTBOX, null, false); |
54
|
|
|
$this->initVar('nota_final', XOBJ_DTYPE_INT, null, false, 10); |
55
|
|
|
$this->initVar('nivel', XOBJ_DTYPE_TXTBOX, null, false); |
56
|
|
|
$this->initVar('obs', XOBJ_DTYPE_TXTBOX, null, false); |
57
|
|
|
$this->initVar('fechada', XOBJ_DTYPE_INT, null, false, 10); |
58
|
|
|
$this->initVar('terminou', XOBJ_DTYPE_INT, null, false, 10); |
59
|
|
View Code Duplication |
if (!empty($id)) { |
|
|
|
|
60
|
|
|
if (is_array($id)) { |
61
|
|
|
$this->assignVars($id); |
62
|
|
|
} else { |
63
|
|
|
$this->load((int)$id); |
64
|
|
|
} |
65
|
|
|
} else { |
66
|
|
|
$this->setNew(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $id |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function load($id) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_resultados') . ' WHERE cod_resultado=' . $id; |
76
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
77
|
|
|
$this->assignVars($myrow); |
78
|
|
|
if (!$myrow) { |
79
|
|
|
$this->setNew(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array $criteria |
85
|
|
|
* @param bool $asobject |
86
|
|
|
* @param string $sort |
87
|
|
|
* @param string $order |
88
|
|
|
* @param int $limit |
89
|
|
|
* @param int $start |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function getAllassessment_resultadoss($criteria = array(), $asobject = false, $sort = 'cod_resultado', $order = 'ASC', $limit = 0, $start = 0) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
96
|
|
|
$ret = array(); |
97
|
|
|
$where_query = ''; |
98
|
|
|
if (is_array($criteria) && count($criteria) > 0) { |
99
|
|
|
$where_query = ' WHERE'; |
100
|
|
|
foreach ($criteria as $c) { |
101
|
|
|
$where_query .= " $c AND"; |
102
|
|
|
} |
103
|
|
|
$where_query = substr($where_query, 0, -4); |
104
|
|
|
} elseif (!is_array($criteria) && $criteria) { |
105
|
|
|
$where_query = ' WHERE ' . $criteria; |
106
|
|
|
} |
107
|
|
|
if (!$asobject) { |
108
|
|
|
$sql = 'SELECT cod_resultado FROM ' . $db->prefix('assessment_resultados') . "$where_query ORDER BY $sort $order"; |
109
|
|
|
$result = $db->query($sql, $limit, $start); |
110
|
|
|
while ($myrow = $db->fetchArray($result)) { |
111
|
|
|
$ret[] = $myrow['assessment_resultados_id']; |
112
|
|
|
} |
113
|
|
|
} else { |
114
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('assessment_resultados') . "$where_query ORDER BY $sort $order"; |
115
|
|
|
$result = $db->query($sql, $limit, $start); |
116
|
|
|
while ($myrow = $db->fetchArray($result)) { |
117
|
|
|
$ret[] = new assessment_resultados($myrow); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $ret; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
|
View Code Duplication |
public function getRespostasCertasAsArray() |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
$respostas = array(); |
|
|
|
|
130
|
|
|
$respostas = explode(',', $this->getVar('resp_certas')); |
131
|
|
|
$par_respostas = array(); |
132
|
|
|
foreach ($respostas as $resposta) { |
133
|
|
|
$x = explode('-', $resposta); |
134
|
|
|
$par_respostas[$x[0]] = @$x[1]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $par_respostas; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public function getRespostasErradasAsArray() |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$respostas = explode(',', $this->getVar('resp_erradas')); |
146
|
|
|
$par_respostas = array(); |
147
|
|
|
foreach ($respostas as $resposta) { |
148
|
|
|
$x = explode('-', $resposta); |
149
|
|
|
if (isset($x[1])) { |
150
|
|
|
$par_respostas[$x[0]] = $x[1]; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $par_respostas; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return array |
159
|
|
|
*/ |
160
|
|
View Code Duplication |
public function getRespostasAsArray() |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
$erradas = array(); |
|
|
|
|
163
|
|
|
$certas = array(); |
|
|
|
|
164
|
|
|
$erradas = $this->getRespostasErradasAsArray(); |
165
|
|
|
$certas = $this->getRespostasCertasAsArray(); |
166
|
|
|
|
167
|
|
|
$todas = $erradas + $certas; |
168
|
|
|
|
169
|
|
|
return $todas; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
View Code Duplication |
public function getCodPerguntasAsArray() |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
$erradas = array(); |
|
|
|
|
178
|
|
|
$certas = array(); |
|
|
|
|
179
|
|
|
$erradas = $this->getRespostasErradasAsArray(); |
180
|
|
|
$certas = $this->getRespostasCertasAsArray(); |
181
|
|
|
|
182
|
|
|
$todas = $erradas + $certas; |
183
|
|
|
|
184
|
|
|
return array_keys($todas); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param $respostasCertas |
189
|
|
|
*/ |
190
|
|
View Code Duplication |
public function setRespostasCertasAsArray($respostasCertas) |
|
|
|
|
191
|
|
|
{ |
192
|
|
|
$x = array(); |
193
|
|
|
foreach ($respostasCertas as $chave => $valor) { |
194
|
|
|
if (!($chave == null)) { |
195
|
|
|
$x[] = $chave . '-' . $valor; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$y = implode(',', $x); |
200
|
|
|
$this->setVar('resp_certas', $y); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param $respostasErradas |
205
|
|
|
*/ |
206
|
|
View Code Duplication |
public function setRespostasErradasAsArray($respostasErradas) |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
$x = array(); |
209
|
|
|
foreach ($respostasErradas as $chave => $valor) { |
210
|
|
|
if (!($chave == null)) { |
211
|
|
|
$x[] = $chave . '-' . $valor; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$y = implode(',', $x); |
216
|
|
|
$this->setVar('resp_erradas', $y); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param $cod_pergunta |
221
|
|
|
* |
222
|
|
|
* @return mixed |
223
|
|
|
*/ |
224
|
|
|
public function getRespostaUsuario($cod_pergunta) |
225
|
|
|
{ |
226
|
|
|
$respostas = $this->getRespostasAsArray(); |
227
|
|
|
|
228
|
|
|
return $respostas[$cod_pergunta]; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return int |
233
|
|
|
*/ |
234
|
|
|
public function contarRespostas() |
235
|
|
|
{ |
236
|
|
|
$respostas = $this->getRespostasAsArray(); |
237
|
|
|
unset($respostas[null]); |
238
|
|
|
|
239
|
|
|
$qtd = count($respostas); |
240
|
|
|
|
241
|
|
|
return $qtd; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
// ------------------------------------------------------------------------- |
246
|
|
|
// ------------------assessment_resultados user handler class ------------------- |
247
|
|
|
// ------------------------------------------------------------------------- |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* assessment_resultadoshandler class. |
251
|
|
|
* This class provides simple mecanisme for assessment_resultados object |
252
|
|
|
*/ |
253
|
|
|
class Xoopsassessment_resultadosHandler extends XoopsPersistableObjectHandler |
|
|
|
|
254
|
|
|
{ |
255
|
|
|
/** |
256
|
|
|
* create a new assessment_resultados |
257
|
|
|
* |
258
|
|
|
* @param bool $isNew flag the new objects as "new"? |
259
|
|
|
* |
260
|
|
|
* @return object assessment_resultados |
261
|
|
|
*/ |
262
|
|
|
public function &create($isNew = true) |
263
|
|
|
{ |
264
|
|
|
$assessment_resultados = new assessment_resultados(); |
265
|
|
|
if ($isNew) { |
266
|
|
|
$assessment_resultados->setNew(); |
267
|
|
|
} else { |
268
|
|
|
$assessment_resultados->unsetNew(); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
return $assessment_resultados; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* retrieve a assessment_resultados |
276
|
|
|
* |
277
|
|
|
* @param mixed $id ID |
278
|
|
|
* @param array $fields fields to fetch |
|
|
|
|
279
|
|
|
* @return XoopsObject {@link XoopsObject} |
|
|
|
|
280
|
|
|
*/ |
281
|
|
View Code Duplication |
public function get($id = null, $fields = null) |
|
|
|
|
282
|
|
|
{ |
283
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_resultados') . ' WHERE cod_resultado=' . $id; |
284
|
|
|
if (!$result = $this->db->query($sql)) { |
285
|
|
|
return false; |
286
|
|
|
} |
287
|
|
|
$numrows = $this->db->getRowsNum($result); |
288
|
|
|
if ($numrows == 1) { |
289
|
|
|
$assessment_resultados = new assessment_resultados(); |
290
|
|
|
$assessment_resultados->assignVars($this->db->fetchArray($result)); |
291
|
|
|
|
292
|
|
|
return $assessment_resultados; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
return false; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* insert a new assessment_resultados in the database |
300
|
|
|
* |
301
|
|
|
* @param XoopsObject $assessment_resultados reference to the {@link assessment_resultados} object |
302
|
|
|
* @param bool $force |
303
|
|
|
* |
304
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
305
|
|
|
*/ |
306
|
|
|
public function insert(XoopsObject $assessment_resultados, $force = false) |
307
|
|
|
{ |
308
|
|
|
global $xoopsConfig; |
|
|
|
|
309
|
|
|
if (get_class($assessment_resultados) != 'assessment_resultados') { |
310
|
|
|
return false; |
311
|
|
|
} |
312
|
|
|
if (!$assessment_resultados->isDirty()) { |
313
|
|
|
return true; |
314
|
|
|
} |
315
|
|
|
if (!$assessment_resultados->cleanVars()) { |
316
|
|
|
return false; |
317
|
|
|
} |
318
|
|
|
foreach ($assessment_resultados->cleanVars as $k => $v) { |
319
|
|
|
${$k} = $v; |
320
|
|
|
} |
321
|
|
|
//$now = "date_add(now(), interval ".$xoopsConfig['server_TZ']." hour)"; |
|
|
|
|
322
|
|
|
$now = 'now()'; |
323
|
|
|
if ($assessment_resultados->isNew()) { |
324
|
|
|
// ajout/modification d'un assessment_resultados |
325
|
|
|
$assessment_resultados = new assessment_resultados(); |
326
|
|
|
$format = 'INSERT INTO %s (cod_resultado, cod_prova, uid_aluno, data_inicio, data_fim, resp_certas, resp_erradas, nota_final, nivel, obs, fechada, terminou)'; |
327
|
|
|
$format .= 'VALUES (%u, %u, %u, %s, %s, %s, %s, %u, %s, %s, %u, %u)'; |
328
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_resultados'), $cod_resultado, $cod_prova, $uid_aluno//,$this->db->quoteString($data_inicio) |
|
|
|
|
329
|
|
|
, $now, $now, $this->db->quoteString($resp_certas), $this->db->quoteString($resp_erradas), $nota_final, $this->db->quoteString($nivel), $this->db->quoteString($obs), $fechada, $terminou); |
|
|
|
|
330
|
|
|
$force = true; |
331
|
|
|
} else { |
332
|
|
|
$format = 'UPDATE %s SET '; |
333
|
|
|
$format .= 'cod_resultado=%u, cod_prova=%u, uid_aluno=%u, data_inicio=%s, data_fim=%s, resp_certas=%s, resp_erradas=%s, nota_final=%u, nivel=%s, obs=%s, fechada=%u, terminou=%u'; |
334
|
|
|
$format .= ' WHERE cod_resultado = %u'; |
335
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_resultados'), $cod_resultado, $cod_prova, $uid_aluno, $this->db->quoteString($data_inicio), $now, $this->db->quoteString($resp_certas), $this->db->quoteString($resp_erradas), |
|
|
|
|
336
|
|
|
$nota_final, $this->db->quoteString($nivel), $this->db->quoteString($obs), $fechada, $terminou, $cod_resultado); |
|
|
|
|
337
|
|
|
} |
338
|
|
|
if (false != $force) { |
|
|
|
|
339
|
|
|
$result = $this->db->queryF($sql); |
340
|
|
|
} else { |
341
|
|
|
$result = $this->db->query($sql); |
342
|
|
|
} |
343
|
|
|
if (!$result) { |
344
|
|
|
return false; |
345
|
|
|
} |
346
|
|
|
if (empty($cod_resultado)) { |
|
|
|
|
347
|
|
|
$cod_resultado = $this->db->getInsertId(); |
348
|
|
|
} |
349
|
|
|
$assessment_resultados->assignVar('cod_resultado', $cod_resultado); |
350
|
|
|
|
351
|
|
|
return true; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* delete a assessment_resultados from the database |
356
|
|
|
* |
357
|
|
|
* @param XoopsObject $assessment_resultados reference to the assessment_resultados to delete |
358
|
|
|
* @param bool $force |
359
|
|
|
* |
360
|
|
|
* @return bool FALSE if failed. |
361
|
|
|
*/ |
362
|
|
View Code Duplication |
public function delete(XoopsObject $assessment_resultados, $force = false) |
|
|
|
|
363
|
|
|
{ |
364
|
|
|
if (get_class($assessment_resultados) != 'assessment_resultados') { |
365
|
|
|
return false; |
366
|
|
|
} |
367
|
|
|
$sql = sprintf('DELETE FROM %s WHERE cod_resultado = %u', $this->db->prefix('assessment_resultados'), $assessment_resultados->getVar('cod_resultado')); |
368
|
|
|
if (false != $force) { |
|
|
|
|
369
|
|
|
$result = $this->db->queryF($sql); |
370
|
|
|
} else { |
371
|
|
|
$result = $this->db->query($sql); |
372
|
|
|
} |
373
|
|
|
if (!$result) { |
374
|
|
|
return false; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
return true; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* retrieve assessment_resultadoss from the database |
382
|
|
|
* |
383
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
|
|
|
384
|
|
|
* @param bool $id_as_key use the UID as key for the array? |
385
|
|
|
* |
386
|
|
|
* @param bool $as_object |
387
|
|
|
* @return array array of <a href='psi_element://$assessment_resultados'>$assessment_resultados</a> objects |
388
|
|
|
* objects |
389
|
|
|
*/ |
390
|
|
View Code Duplication |
public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true) |
|
|
|
|
391
|
|
|
{ |
392
|
|
|
$ret = array(); |
393
|
|
|
$limit = $start = 0; |
394
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_resultados'); |
395
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
396
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
397
|
|
|
if ($criteria->getSort() != '') { |
398
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
399
|
|
|
} |
400
|
|
|
$limit = $criteria->getLimit(); |
401
|
|
|
$start = $criteria->getStart(); |
402
|
|
|
} |
403
|
|
|
$result = $this->db->query($sql, $limit, $start); |
404
|
|
|
if (!$result) { |
405
|
|
|
return $ret; |
406
|
|
|
} |
407
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
408
|
|
|
$assessment_resultados = new assessment_resultados(); |
409
|
|
|
$assessment_resultados->assignVars($myrow); |
410
|
|
|
if (!$id_as_key) { |
411
|
|
|
$ret[] = $assessment_resultados; |
412
|
|
|
} else { |
413
|
|
|
$ret[$myrow['cod_resultado']] = $assessment_resultados; |
414
|
|
|
} |
415
|
|
|
unset($assessment_resultados); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
return $ret; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* count assessment_resultadoss matching a condition |
423
|
|
|
* |
424
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
|
|
|
425
|
|
|
* |
426
|
|
|
* @return int count of assessment_perguntass |
427
|
|
|
*/ |
428
|
|
View Code Duplication |
public function getCount(CriteriaElement $criteria = null) |
|
|
|
|
429
|
|
|
{ |
430
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('assessment_resultados'); |
431
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
432
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
433
|
|
|
} |
434
|
|
|
$result = $this->db->query($sql); |
435
|
|
|
if (!$result) { |
436
|
|
|
return 0; |
437
|
|
|
} |
438
|
|
|
list($count) = $this->db->fetchRow($result); |
439
|
|
|
|
440
|
|
|
return $count; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* delete assessment_resultadoss matching a set of conditions |
445
|
|
|
* |
446
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} |
|
|
|
|
447
|
|
|
* |
448
|
|
|
* @param bool $force |
449
|
|
|
* @param bool $asObject |
450
|
|
|
* @return bool FALSE if deletion failed |
451
|
|
|
*/ |
452
|
|
View Code Duplication |
public function deleteAll(CriteriaElement $criteria = null, $force = true, $asObject = false) |
|
|
|
|
453
|
|
|
{ |
454
|
|
|
$sql = 'DELETE FROM ' . $this->db->prefix('assessment_resultados'); |
455
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
456
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
457
|
|
|
} |
458
|
|
|
if (!$result = $this->db->query($sql)) { |
459
|
|
|
return false; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
return true; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/* cria form de edi��o de resultado |
466
|
|
|
* |
467
|
|
|
* @param string $action caminho para arquivo que ... |
468
|
|
|
* @param object $assessment_perguntas {@link assessment_perguntas} |
469
|
|
|
* @return bool FALSE if deletion failed |
470
|
|
|
*/ |
471
|
|
|
/** |
472
|
|
|
* @param $resultado |
473
|
|
|
* @param $prova |
474
|
|
|
* @param $qtd_perguntas |
475
|
|
|
* @param $action |
476
|
|
|
* |
477
|
|
|
* @return bool |
478
|
|
|
*/ |
479
|
|
|
public function renderFormEditar($resultado, $prova, $qtd_perguntas, $action) |
480
|
|
|
{ |
481
|
|
|
$cod_prova = $prova->getVar('cod_prova'); |
|
|
|
|
482
|
|
|
$titulo = $prova->getVar('titulo'); |
|
|
|
|
483
|
|
|
$descricao = $prova->getVar('descricao'); |
|
|
|
|
484
|
|
|
$instrucoes = $prova->getVar('instrucoes'); |
|
|
|
|
485
|
|
|
$tempo = $prova->getVar('tempo'); |
|
|
|
|
486
|
|
|
|
487
|
|
|
$cod_resultado = $resultado->getVar('cod_resultado'); |
488
|
|
|
$data_inicio = $resultado->getVar('data_inicio'); |
|
|
|
|
489
|
|
|
$data_fim = $resultado->getVar('data_fim'); |
|
|
|
|
490
|
|
|
$resp_certas = $resultado->getVar('resp_certas'); |
491
|
|
|
$resp_erradas = $resultado->getVar('resp_erradas'); |
492
|
|
|
$nota_final = $resultado->getVar('nota_final'); |
493
|
|
|
$nivel = $resultado->getVar('nivel'); |
494
|
|
|
$observacoes = $resultado->getVar('obs'); |
495
|
|
|
$qtd_acertos = count(explode(',', $resp_certas)); |
496
|
|
|
$qtd_erros = count(explode(',', $resp_erradas)); |
497
|
|
|
|
498
|
|
|
$texto_resp_certas = _AM_ASSESSMENT_PERGDETALHES . '<br />'; |
499
|
|
|
$vetor_resp_certas = explode(',', $resp_certas); |
500
|
|
|
|
501
|
|
|
foreach ($vetor_resp_certas as $resp) { |
502
|
|
|
$detalhe_resp_certa = explode('-', $resp); |
503
|
|
|
$texto_resp_certas .= '<a href=main.php?op=ver_detalhe_pergunta&cod_pergunta=' . $detalhe_resp_certa[0] . '&cod_resposta=' . $detalhe_resp_certa[1] . '>' . $detalhe_resp_certa[0] . ' </a> '; |
504
|
|
|
} |
505
|
|
|
$texto_resp_erradas = _AM_ASSESSMENT_PERGDETALHES . ' <br />'; |
506
|
|
|
$vetor_resp_erradas = explode(',', $resp_erradas); |
507
|
|
|
|
508
|
|
|
foreach ($vetor_resp_erradas as $resp2) { |
509
|
|
|
$detalhe_resp_errada = explode('-', $resp2); |
510
|
|
|
$texto_resp_erradas .= '<a href=main.php?op=ver_detalhe_pergunta&cod_pergunta=' . $detalhe_resp_errada[0] . '&cod_resposta=' . $detalhe_resp_errada[1] . '>' . $detalhe_resp_errada[0] . ' </a> '; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
if ($vetor_resp_certas[0] == '') { |
514
|
|
|
$qtd_acertos = 0; |
515
|
|
|
} |
516
|
|
|
if ($vetor_resp_erradas[0] == '') { |
517
|
|
|
$qtd_erros = 0; |
518
|
|
|
} |
519
|
|
|
$qtd_branco = $qtd_perguntas - $qtd_acertos - $qtd_erros; |
520
|
|
|
$nota_sugest = round(100 * $qtd_acertos / $qtd_perguntas, 2); |
521
|
|
|
|
522
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_EDITAR . ' ' . _AM_ASSESSMENT_RESULTADO, 'form_resultado', $action, 'post', true); |
523
|
|
|
$campo_resp_certas = new XoopsFormLabel(_AM_ASSESSMENT_RESPCERTAS, $texto_resp_certas); |
524
|
|
|
$campo_resp_erradas = new XoopsFormLabel(_AM_ASSESSMENT_RESPERR, $texto_resp_erradas); |
525
|
|
|
$campo_sugest_nota_final = new XoopsFormLabel(_AM_ASSESSMENT_SUGESTNOTA, $nota_sugest |
526
|
|
|
. '/100 (' |
527
|
|
|
. _AM_ASSESSMENT_ACERTOU |
528
|
|
|
. ' ' |
529
|
|
|
. $qtd_acertos |
530
|
|
|
. ' ' |
531
|
|
|
. _AM_ASSESSMENT_ERROU |
532
|
|
|
. ' ' |
533
|
|
|
. $qtd_erros |
534
|
|
|
. ' ' |
535
|
|
|
. _AM_ASSESSMENT_SEMREPONDER |
536
|
|
|
. ' ' |
537
|
|
|
. $qtd_branco |
538
|
|
|
. ' ' |
539
|
|
|
. _AM_ASSESSMENT_DEUMTOTALDE |
540
|
|
|
. ' ' |
541
|
|
|
. $qtd_perguntas |
542
|
|
|
. ' ' |
543
|
|
|
. _AM_ASSESSMENT_PERGUNTAS |
544
|
|
|
. ' )'); |
545
|
|
|
$campo_nota_final = new XoopsFormText(_AM_ASSESSMENT_NOTAFINAL, 'campo_nota_final', 6, 10, $nota_final); |
546
|
|
|
$campo_nivel = new XoopsFormText(_AM_ASSESSMENT_NIVEL, 'campo_nivel', 10, 20, $nivel); |
547
|
|
|
$campo_observacoes = new XoopsFormTextArea(_AM_ASSESSMENT_OBS, 'campo_observacoes', $observacoes, 2, 50); |
548
|
|
|
$campo_cod_resultado = new XoopsFormHidden('campo_cod_resultado', $cod_resultado); |
549
|
|
|
$botao_enviar = new XoopsFormButton('', 'botao_submit', _AM_ASSESSMENT_SALVARALTERACOES, 'submit'); |
550
|
|
|
$form->addElement($campo_resp_certas, true); |
551
|
|
|
$form->addElement($campo_resp_erradas, true); |
552
|
|
|
$form->addElement($campo_sugest_nota_final); |
553
|
|
|
$form->addElement($campo_nota_final, true); |
554
|
|
|
$form->addElement($campo_nivel, true); |
555
|
|
|
|
556
|
|
|
$form->addElement($campo_observacoes, true); |
557
|
|
|
$form->addElement($campo_cod_resultado, true); |
558
|
|
|
$form->addElement($botao_enviar); |
559
|
|
|
$form->display(); |
560
|
|
|
|
561
|
|
|
return true; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* @param $cod_prova |
566
|
|
|
* |
567
|
|
|
* @return int |
|
|
|
|
568
|
|
|
*/ |
569
|
|
|
public function stats($cod_prova) |
570
|
|
|
{ |
571
|
|
|
$criteria = new criteria('cod_prova', $cod_prova); |
572
|
|
|
$qtd_provas = $this->getCount($criteria); |
573
|
|
|
$ret['qtd'] = $qtd_provas; |
|
|
|
|
574
|
|
|
$sql = 'SELECT max(nota_final),min(nota_final),avg(nota_final) FROM ' . $this->db->prefix('assessment_resultados'); |
575
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
576
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
577
|
|
|
} |
578
|
|
|
$result = $this->db->query($sql); |
579
|
|
|
if (!$result) { |
580
|
|
|
return 0; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
while (list($max, $min, $media) = $this->db->fetchRow($result)) { |
584
|
|
|
$ret['max'] = $max; |
585
|
|
|
$ret['min'] = $min; |
586
|
|
|
$ret['media'] = $media; |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
return $ret; |
590
|
|
|
} |
591
|
|
|
} |
592
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.