1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// assessment_provas.php,v 1 |
3
|
|
|
// $Id: assessment_provas.php,v 1.11 2007/03/24 20:08:53 marcellobrandao Exp $ |
4
|
|
|
// ------------------------------------------------------------------------ // |
5
|
|
|
// XOOPS - PHP Content Management System // |
6
|
|
|
// Copyright (c) 2000 XOOPS.org // |
7
|
|
|
// <http://www.xoops.org/> // |
8
|
|
|
// ------------------------------------------------------------------------ // |
9
|
|
|
// This program is free software; you can redistribute it and/or modify // |
10
|
|
|
// it under the terms of the GNU General Public License as published by // |
11
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
12
|
|
|
// (at your option) any later version. // |
13
|
|
|
// // |
14
|
|
|
// You may not change or alter any portion of this comment or credits // |
15
|
|
|
// of supporting developers from this source code or any supporting // |
16
|
|
|
// source code which is considered copyrighted (c) material of the // |
17
|
|
|
// original comment or credit authors. // |
18
|
|
|
// // |
19
|
|
|
// This program is distributed in the hope that it will be useful, // |
20
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
21
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
22
|
|
|
// GNU General Public License for more details. // |
23
|
|
|
// // |
24
|
|
|
// You should have received a copy of the GNU General Public License // |
25
|
|
|
// along with this program; if not, write to the Free Software // |
26
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
27
|
|
|
// ------------------------------------------------------------------------ // |
28
|
|
|
|
29
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* assessment_provas class. |
33
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
34
|
|
|
* of XOOPS user class objects. |
35
|
|
|
*/ |
36
|
|
|
class assessment_provas extends XoopsObject |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
public $db; |
39
|
|
|
|
40
|
|
|
// constructor |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param null $id |
44
|
|
|
* @return assessment_provas |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function __construct($id = null) |
47
|
|
|
{ |
48
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
49
|
|
|
$this->initVar('cod_prova', XOBJ_DTYPE_INT, null, false, 10); |
50
|
|
|
$this->initVar('data_criacao', XOBJ_DTYPE_TXTBOX, '2017-01-01', false); |
51
|
|
|
$this->initVar('data_update', XOBJ_DTYPE_TXTBOX, '2017-01-01', false); |
52
|
|
|
$this->initVar('titulo', XOBJ_DTYPE_TXTBOX, null, false); |
53
|
|
|
$this->initVar('descricao', XOBJ_DTYPE_TXTBOX, null, false); |
54
|
|
|
$this->initVar('instrucoes', XOBJ_DTYPE_TXTBOX, null, false); |
55
|
|
|
$this->initVar('acesso', XOBJ_DTYPE_TXTBOX, null, false); |
56
|
|
|
$this->initVar('tempo', XOBJ_DTYPE_TXTBOX, null, false); |
57
|
|
|
$this->initVar('uid_elaboradores', XOBJ_DTYPE_TXTBOX, null, false); |
58
|
|
|
$this->initVar('data_inicio', XOBJ_DTYPE_TXTBOX, null, false); |
59
|
|
|
$this->initVar('data_fim', XOBJ_DTYPE_TXTBOX, null, false); |
60
|
|
View Code Duplication |
if (!empty($id)) { |
|
|
|
|
61
|
|
|
if (is_array($id)) { |
62
|
|
|
$this->assignVars($id); |
63
|
|
|
} else { |
64
|
|
|
$this->load((int)$id); |
65
|
|
|
} |
66
|
|
|
} else { |
67
|
|
|
$this->setNew(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $id |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function load($id) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_provas') . ' WHERE cod_prova=' . $id; |
77
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
78
|
|
|
$this->assignVars($myrow); |
79
|
|
|
if (!$myrow) { |
80
|
|
|
$this->setNew(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $criteria |
86
|
|
|
* @param bool $asobject |
87
|
|
|
* @param string $sort |
88
|
|
|
* @param string $order |
89
|
|
|
* @param int $limit |
90
|
|
|
* @param int $start |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function getAllassessment_provass($criteria = array(), $asobject = false, $sort = 'cod_prova', $order = 'ASC', $limit = 0, $start = 0) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
97
|
|
|
$ret = array(); |
98
|
|
|
$where_query = ''; |
99
|
|
|
if (is_array($criteria) && count($criteria) > 0) { |
100
|
|
|
$where_query = ' WHERE'; |
101
|
|
|
foreach ($criteria as $c) { |
102
|
|
|
$where_query .= " $c AND"; |
103
|
|
|
} |
104
|
|
|
$where_query = substr($where_query, 0, -4); |
105
|
|
|
} elseif (!is_array($criteria) && $criteria) { |
106
|
|
|
$where_query = ' WHERE ' . $criteria; |
107
|
|
|
} |
108
|
|
|
if (!$asobject) { |
109
|
|
|
$sql = 'SELECT cod_prova FROM ' . $db->prefix('assessment_provas') . "$where_query ORDER BY $sort $order"; |
110
|
|
|
$result = $db->query($sql, $limit, $start); |
111
|
|
|
while ($myrow = $db->fetchArray($result)) { |
112
|
|
|
$ret[] = $myrow['assessment_provas_id']; |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('assessment_provas') . "$where_query ORDER BY $sort $order"; |
116
|
|
|
$result = $db->query($sql, $limit, $start); |
117
|
|
|
while ($myrow = $db->fetchArray($result)) { |
118
|
|
|
$ret[] = new assessment_provas($myrow); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $ret; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Verifica se aluno pode acessar esta prova |
127
|
|
|
* |
128
|
|
|
* @param object member $aluno |
129
|
|
|
* |
130
|
|
|
* @return bool true se autorizado e false se n�o autorizado |
131
|
|
|
*/ |
132
|
|
|
public function isAutorizado($aluno = null) |
133
|
|
|
{ |
134
|
|
|
global $xoopsUser, $xoopsDB; |
|
|
|
|
135
|
|
|
if ($aluno == null) { |
136
|
|
|
$aluno = $xoopsUser; |
137
|
|
|
} |
138
|
|
|
$acesso = $this->getVar('acesso', 'n'); |
139
|
|
|
$acesso = explode(',', $acesso); |
140
|
|
|
$grupos = $aluno->getGroups(); |
141
|
|
|
$intersect = array_intersect($acesso, $grupos); |
142
|
|
|
if (!(count($intersect) > 0)) { |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$inicio = $this->getVar('data_inicio', 'n'); |
147
|
|
|
$fabrica_de_provas = new Xoopsassessment_provasHandler($xoopsDB); |
148
|
|
|
if ($fabrica_de_provas->dataMysql2dataUnix($inicio) > time()) { |
149
|
|
|
return false; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return true; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Verifica se aluno pode acessar esta prova |
157
|
|
|
* |
158
|
|
|
* @param vetorgrupos |
159
|
|
|
* |
160
|
|
|
* @return bool true se autorizado e false se n�o autorizado |
161
|
|
|
*/ |
162
|
|
|
public function isAutorizado2($grupos) |
163
|
|
|
{ |
164
|
|
|
global $xoopsUser, $xoopsDB; |
|
|
|
|
165
|
|
|
|
166
|
|
|
$acesso = $this->getVar('acesso', 'n'); |
167
|
|
|
$acesso = explode(',', $acesso); |
168
|
|
|
$intersect = array_intersect($acesso, $grupos); |
169
|
|
|
if (!(count($intersect) > 0)) { |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$inicio = $this->getVar('data_inicio', 'n'); |
174
|
|
|
$fabrica_de_provas = new Xoopsassessment_provasHandler($xoopsDB); |
175
|
|
|
if ($fabrica_de_provas->dataMysql2dataUnix($inicio) > time()) { |
176
|
|
|
return false; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return true; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
// ------------------------------------------------------------------------- |
184
|
|
|
// ------------------assessment_provas user handler class ------------------- |
185
|
|
|
// ------------------------------------------------------------------------- |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* assessment_provashandler class. |
189
|
|
|
* This class provides simple mecanisme for assessment_provas object |
190
|
|
|
*/ |
191
|
|
|
class Xoopsassessment_provasHandler extends XoopsPersistableObjectHandler |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
/** |
194
|
|
|
* create a new assessment_provas |
195
|
|
|
* |
196
|
|
|
* @param bool $isNew flag the new objects as "new"? |
197
|
|
|
* |
198
|
|
|
* @return object assessment_provas |
199
|
|
|
*/ |
200
|
|
|
public function &create($isNew = true) |
201
|
|
|
{ |
202
|
|
|
$assessment_provas = new assessment_provas(); |
203
|
|
|
if ($isNew) { |
204
|
|
|
$assessment_provas->setNew(); |
205
|
|
|
} //hack consertando |
206
|
|
|
else { |
207
|
|
|
$assessment_provas->unsetNew(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
//fim do hack para consertar |
211
|
|
|
return $assessment_provas; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* retrieve a assessment_provas |
216
|
|
|
* |
217
|
|
|
* @param mixed $id ID |
218
|
|
|
* @param array $fields fields to fetch |
|
|
|
|
219
|
|
|
* @return XoopsObject {@link XoopsObject} |
|
|
|
|
220
|
|
|
*/ |
221
|
|
View Code Duplication |
public function get($id = null, $fields = null) |
|
|
|
|
222
|
|
|
{ |
223
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_provas') . ' WHERE cod_prova=' . $id; |
224
|
|
|
if (!$result = $this->db->query($sql)) { |
225
|
|
|
return false; |
226
|
|
|
} |
227
|
|
|
$numrows = $this->db->getRowsNum($result); |
228
|
|
|
if ($numrows == 1) { |
229
|
|
|
$assessment_provas = new assessment_provas(); |
230
|
|
|
$assessment_provas->assignVars($this->db->fetchArray($result)); |
231
|
|
|
|
232
|
|
|
return $assessment_provas; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return false; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* insert a new assessment_provas in the database |
240
|
|
|
* |
241
|
|
|
* @param XoopsObject $assessment_provas reference to the {@link assessment_provas} object |
242
|
|
|
* @param bool $force |
243
|
|
|
* |
244
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
245
|
|
|
*/ |
246
|
|
|
public function insert(XoopsObject $assessment_provas, $force = false) |
247
|
|
|
{ |
248
|
|
|
global $xoopsConfig; |
|
|
|
|
249
|
|
|
if (get_class($assessment_provas) != 'assessment_provas') { |
250
|
|
|
return false; |
251
|
|
|
} |
252
|
|
|
if (!$assessment_provas->isDirty()) { |
253
|
|
|
return true; |
254
|
|
|
} |
255
|
|
|
if (!$assessment_provas->cleanVars()) { |
256
|
|
|
return false; |
257
|
|
|
} |
258
|
|
|
foreach ($assessment_provas->cleanVars as $k => $v) { |
259
|
|
|
${$k} = $v; |
260
|
|
|
} |
261
|
|
|
$now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
|
|
|
|
262
|
|
|
if ($assessment_provas->isNew()) { |
263
|
|
|
// ajout/modification d'un assessment_provas |
264
|
|
|
$assessment_provas = new assessment_provas(); |
265
|
|
|
$format = 'INSERT INTO %s (cod_prova, data_criacao, data_update, titulo, descricao, instrucoes, acesso, tempo, uid_elaboradores, data_inicio, data_fim)'; |
266
|
|
|
$format .= 'VALUES (%u, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'; |
267
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_provas'), $cod_prova, $this->db->quoteString($data_criacao), $this->db->quoteString($data_update), $this->db->quoteString($titulo), $this->db->quoteString($descricao), |
|
|
|
|
268
|
|
|
$this->db->quoteString($instrucoes), $this->db->quoteString($acesso), $this->db->quoteString($tempo), $this->db->quoteString($uid_elaboradores), $this->db->quoteString($data_inicio), |
|
|
|
|
269
|
|
|
$this->db->quoteString($data_fim)); |
|
|
|
|
270
|
|
|
$force = true; |
271
|
|
|
} else { |
272
|
|
|
$format = 'UPDATE %s SET '; |
273
|
|
|
$format .= 'cod_prova=%u, data_criacao=%s, data_update=%s, titulo=%s, descricao=%s, instrucoes=%s, acesso=%s, tempo=%s, uid_elaboradores=%s, data_inicio=%s, data_fim=%s'; |
274
|
|
|
$format .= ' WHERE cod_prova = %u'; |
275
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_provas'), $cod_prova, $this->db->quoteString($data_criacao), $this->db->quoteString($data_update), $this->db->quoteString($titulo), $this->db->quoteString($descricao), |
|
|
|
|
276
|
|
|
$this->db->quoteString($instrucoes), $this->db->quoteString($acesso), $this->db->quoteString($tempo), $this->db->quoteString($uid_elaboradores), $this->db->quoteString($data_inicio), $this->db->quoteString($data_fim), |
277
|
|
|
$cod_prova); |
|
|
|
|
278
|
|
|
} |
279
|
|
|
if (false != $force) { |
|
|
|
|
280
|
|
|
$result = $this->db->queryF($sql); |
281
|
|
|
} else { |
282
|
|
|
$result = $this->db->query($sql); |
283
|
|
|
} |
284
|
|
|
if (!$result) { |
285
|
|
|
return false; |
286
|
|
|
} |
287
|
|
|
if (empty($cod_prova)) { |
|
|
|
|
288
|
|
|
$cod_prova = $this->db->getInsertId(); |
289
|
|
|
} |
290
|
|
|
$assessment_provas->assignVar('cod_prova', $cod_prova); |
291
|
|
|
|
292
|
|
|
return true; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* delete a assessment_provas from the database |
297
|
|
|
* |
298
|
|
|
* @param XoopsObject $assessment_provas reference to the assessment_provas to delete |
299
|
|
|
* @param bool $force |
300
|
|
|
* |
301
|
|
|
* @return bool FALSE if failed. |
302
|
|
|
*/ |
303
|
|
View Code Duplication |
public function delete(XoopsObject $assessment_provas, $force = false) |
|
|
|
|
304
|
|
|
{ |
305
|
|
|
if (get_class($assessment_provas) != 'assessment_provas') { |
306
|
|
|
return false; |
307
|
|
|
} |
308
|
|
|
$sql = sprintf('DELETE FROM %s WHERE cod_prova = %u', $this->db->prefix('assessment_provas'), $assessment_provas->getVar('cod_prova')); |
309
|
|
|
if (false != $force) { |
|
|
|
|
310
|
|
|
$result = $this->db->queryF($sql); |
311
|
|
|
} else { |
312
|
|
|
$result = $this->db->query($sql); |
313
|
|
|
} |
314
|
|
|
if (!$result) { |
315
|
|
|
return false; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
return true; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @param $cod_prova |
323
|
|
|
*/ |
324
|
|
|
public function clonarProva($cod_prova) |
325
|
|
|
{ |
326
|
|
|
$prova = $this->get($cod_prova); |
327
|
|
|
|
328
|
|
|
$prova->setVar('titulo', _AM_ASSESSMENT_CLONE . $prova->getVar('titulo')); |
329
|
|
|
$prova->setVar('cod_prova', 0); |
330
|
|
|
$prova->setNew(); |
331
|
|
|
$this->insert($prova); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* retrieve assessment_provass from the database |
336
|
|
|
* |
337
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
|
|
|
338
|
|
|
* @param bool $id_as_key use the UID as key for the array? |
339
|
|
|
* |
340
|
|
|
* @param bool $as_object |
341
|
|
|
* @return array array of <a href='psi_element://assessment_perguntas'>assessment_perguntas</a> objects |
342
|
|
|
* objects |
343
|
|
|
*/ |
344
|
|
View Code Duplication |
public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true) |
|
|
|
|
345
|
|
|
{ |
346
|
|
|
$ret = array(); |
347
|
|
|
$limit = $start = 0; |
348
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_provas'); |
349
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
350
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
351
|
|
|
if ($criteria->getSort() != '') { |
352
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
353
|
|
|
} |
354
|
|
|
$limit = $criteria->getLimit(); |
355
|
|
|
$start = $criteria->getStart(); |
356
|
|
|
} |
357
|
|
|
$result = $this->db->query($sql, $limit, $start); |
358
|
|
|
if (!$result) { |
359
|
|
|
return $ret; |
360
|
|
|
} |
361
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
362
|
|
|
$assessment_provas = new assessment_provas(); |
363
|
|
|
$assessment_provas->assignVars($myrow); |
364
|
|
|
if (!$id_as_key) { |
365
|
|
|
$ret[] =& $assessment_provas; |
366
|
|
|
} else { |
367
|
|
|
$ret[$myrow['cod_prova']] = $assessment_provas; |
368
|
|
|
} |
369
|
|
|
unset($assessment_provas); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
return $ret; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* count assessment_provass matching a condition |
377
|
|
|
* |
378
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
|
|
|
379
|
|
|
* |
380
|
|
|
* @return int count of assessment_provass |
381
|
|
|
*/ |
382
|
|
View Code Duplication |
public function getCount(CriteriaElement $criteria = null) |
|
|
|
|
383
|
|
|
{ |
384
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('assessment_provas'); |
385
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
386
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
387
|
|
|
} |
388
|
|
|
$result = $this->db->query($sql); |
389
|
|
|
if (!$result) { |
390
|
|
|
return 0; |
391
|
|
|
} |
392
|
|
|
list($count) = $this->db->fetchRow($result); |
393
|
|
|
|
394
|
|
|
return $count; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* delete assessment_provass matching a set of conditions |
399
|
|
|
* |
400
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} |
|
|
|
|
401
|
|
|
* |
402
|
|
|
* @param bool $force |
403
|
|
|
* @param bool $asObject |
404
|
|
|
* @return bool FALSE if deletion failed |
405
|
|
|
*/ |
406
|
|
View Code Duplication |
public function deleteAll(CriteriaElement $criteria = null, $force = true, $asObject = false) |
|
|
|
|
407
|
|
|
{ |
408
|
|
|
$sql = 'DELETE FROM ' . $this->db->prefix('assessment_provas'); |
409
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
410
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
411
|
|
|
} |
412
|
|
|
if (!$result = $this->db->query($sql)) { |
413
|
|
|
return false; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
return true; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* cria form de inser��o e edi��o de pergunta |
421
|
|
|
* |
422
|
|
|
* @param string $action caminho para arquivo que ... |
423
|
|
|
* @return bool FALSE if deletion failed |
424
|
|
|
* @internal param object $assessment_perguntas <a href='psi_element://assessment_perguntas'>assessment_perguntas</a> |
425
|
|
|
* |
426
|
|
|
*/ |
427
|
|
|
public function renderFormCadastrar($action) |
428
|
|
|
{ |
429
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_CADASTRAR . ' ' . _AM_ASSESSMENT_PROVA, 'form_prova', $action, 'post', true); |
430
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', '', 2, 50); |
431
|
|
|
$campo_descricao = new XoopsFormTextArea(_AM_ASSESSMENT_DESCRICAO, 'campo_descricao', '', 2, 50); |
432
|
|
|
$campo_instrucoes = new XoopsFormTextArea(_AM_ASSESSMENT_INSTRUCOES, 'campo_instrucoes', '', 2, 50); |
433
|
|
|
$campo_tempo = new XoopsFormText(_AM_ASSESSMENT_TEMPO, 'campo_tempo', 10, 20); |
434
|
|
|
|
435
|
|
|
$campo_acesso = new XoopsFormSelectGroup(_AM_ASSESSMENT_GRUPOSACESSO, 'campo_grupo', false, null, 4, true); |
436
|
|
|
$botao_enviar = new XoopsFormButton(_AM_ASSESSMENT_CADASTRAR, 'botao_submit', _SUBMIT, 'submit'); |
437
|
|
|
$campo_data_inicio = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_INICIO, 'campo_data_inicio'); |
438
|
|
|
$campo_data_fim = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_FIM, 'campo_data_fim'); |
439
|
|
|
$form->addElement($campo_titulo, true); |
440
|
|
|
$form->addElement($campo_descricao, true); |
441
|
|
|
$form->addElement($campo_instrucoes, true); |
442
|
|
|
$form->addElement($campo_tempo, true); |
443
|
|
|
|
444
|
|
|
$form->addElement($campo_data_inicio, true); |
445
|
|
|
$form->addElement($campo_data_fim, true); |
446
|
|
|
$form->addElement($campo_acesso, true); |
447
|
|
|
$form->addElement($botao_enviar); |
448
|
|
|
$form->display(); |
449
|
|
|
|
450
|
|
|
return true; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* cria form de inser��o e edi��o de pergunta |
455
|
|
|
* |
456
|
|
|
* @param string $action caminho para arquivo que ... |
457
|
|
|
* @param $prova |
458
|
|
|
* @return bool FALSE if deletion failed |
459
|
|
|
* @internal param object $assessment_perguntas <a href='psi_element://assessment_perguntas'>assessment_perguntas</a> |
460
|
|
|
* |
461
|
|
|
*/ |
462
|
|
|
public function renderFormEditar($action, $prova) |
463
|
|
|
{ |
464
|
|
|
$cod_prova = $prova->getVar('cod_prova'); |
465
|
|
|
$titulo = $prova->getVar('titulo'); |
466
|
|
|
$descricao = $prova->getVar('descricao'); |
467
|
|
|
$instrucoes = $prova->getVar('instrucoes'); |
468
|
|
|
$acessos = explode(',', $prova->getVar('acesso')); |
469
|
|
|
$tempo = $prova->getVar('tempo'); |
470
|
|
|
$inicio = $this->dataMysql2dataUnix($prova->getVar('data_inicio')); |
471
|
|
|
$fim = $this->dataMysql2dataUnix($prova->getVar('data_fim')); |
472
|
|
|
|
473
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_EDITAR . ' ' . _AM_ASSESSMENT_PROVA, 'form_prova', $action, 'post', true); |
474
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', $titulo, 2, 50); |
475
|
|
|
$campo_descricao = new XoopsFormTextArea(_AM_ASSESSMENT_DESCRICAO, 'campo_descricao', $descricao, 2, 50); |
476
|
|
|
$campo_instrucoes = new XoopsFormTextArea(_AM_ASSESSMENT_INSTRUCOES, 'campo_instrucoes', $instrucoes, 2, 50); |
477
|
|
|
$campo_tempo = new XoopsFormText(_AM_ASSESSMENT_TEMPO, 'campo_tempo', 10, 20, $tempo); |
478
|
|
|
$campo_acesso = new XoopsFormSelectGroup(_AM_ASSESSMENT_GRUPOSACESSO, 'campo_grupo', false, $acessos, 4, true); |
479
|
|
|
$campo_cod_prova = new XoopsFormHidden('campo_cod_prova', $cod_prova); |
480
|
|
|
$campo_data_inicio = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_INICIO, 'campo_data_inicio', null, $inicio); |
481
|
|
|
$campo_data_fim = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_FIM, 'campo_data_fim', null, $fim); |
482
|
|
|
$botao_enviar = new XoopsFormButton('', 'botao_submit', _AM_ASSESSMENT_SALVARALTERACOES, 'submit'); |
483
|
|
|
$form->addElement($campo_titulo, true); |
484
|
|
|
$form->addElement($campo_descricao, true); |
485
|
|
|
$form->addElement($campo_instrucoes, true); |
486
|
|
|
$form->addElement($campo_cod_prova, true); |
487
|
|
|
|
488
|
|
|
$form->addElement($campo_tempo, true); |
489
|
|
|
$form->addElement($campo_data_inicio, true); |
490
|
|
|
$form->addElement($campo_data_fim, true); |
491
|
|
|
$form->addElement($campo_acesso, true); |
492
|
|
|
$form->addElement($botao_enviar); |
493
|
|
|
$form->display(); |
494
|
|
|
|
495
|
|
|
return true; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* @param $db |
500
|
|
|
* |
501
|
|
|
* @return mixed |
502
|
|
|
*/ |
503
|
|
|
public function pegarultimocodigo(&$db) |
504
|
|
|
{ |
505
|
|
|
return $db->getInsertId(); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* @param $dataMYSQL |
510
|
|
|
* |
511
|
|
|
* @return int |
512
|
|
|
*/ |
513
|
|
|
public function dataMysql2dataUnix($dataMYSQL) |
514
|
|
|
{ |
515
|
|
|
$d = @explode(' ', $dataMYSQL, 2); |
516
|
|
|
$t = @explode(':', $d[1], 3); |
517
|
|
|
$d = @explode('-', $d[0], 3); |
518
|
|
|
$ts = @mktime($t[0], $t[1], $t[2], $d[1], $d[2], $d[0]); |
519
|
|
|
|
520
|
|
|
return $ts; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @param $total_segundos |
525
|
|
|
* @param string $inicio |
526
|
|
|
* |
527
|
|
|
* @return mixed |
528
|
|
|
*/ |
529
|
|
|
public function converte_segundos($total_segundos, $inicio = 'Y') |
530
|
|
|
{ |
531
|
|
|
/** |
532
|
|
|
* @autor: Carlos H. Reche |
533
|
|
|
* @data : 11/08/2004 |
534
|
|
|
*/ |
535
|
|
|
|
536
|
|
|
$comecou = false; |
537
|
|
|
|
538
|
|
|
if ($inicio == 'Y') { |
539
|
|
|
$array['anos'] = floor($total_segundos / (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH * 12)); |
|
|
|
|
540
|
|
|
$total_segundos = ($total_segundos % (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH * 12)); |
541
|
|
|
$comecou = true; |
542
|
|
|
} |
543
|
|
|
if (($inicio == 'm') || ($comecou == true)) { |
|
|
|
|
544
|
|
|
$array['meses'] = floor($total_segundos / (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH)); |
|
|
|
|
545
|
|
|
$total_segundos = ($total_segundos % (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH)); |
546
|
|
|
$comecou = true; |
547
|
|
|
} |
548
|
|
View Code Duplication |
if (($inicio == 'd') || ($comecou == true)) { |
|
|
|
|
549
|
|
|
$array['dias'] = floor($total_segundos / (60 * 60 * 24)); |
550
|
|
|
$total_segundos = ($total_segundos % (60 * 60 * 24)); |
551
|
|
|
$comecou = true; |
552
|
|
|
} |
553
|
|
View Code Duplication |
if (($inicio == 'H') || ($comecou == true)) { |
|
|
|
|
554
|
|
|
$array['horas'] = floor($total_segundos / (60 * 60)); |
555
|
|
|
$total_segundos = ($total_segundos % (60 * 60)); |
556
|
|
|
$comecou = true; |
557
|
|
|
} |
558
|
|
|
if (($inicio == 'i') || ($comecou == true)) { |
|
|
|
|
559
|
|
|
$array['minutos'] = floor($total_segundos / 60); |
560
|
|
|
$total_segundos = ($total_segundos % 60); |
561
|
|
|
$comecou = true; |
|
|
|
|
562
|
|
|
} |
563
|
|
|
$array['segundos'] = $total_segundos; |
564
|
|
|
|
565
|
|
|
return $array; |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
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.