1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// $Id: assessment_perguntas.php,v 1.10 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
|
|
|
// assessment_perguntas.php,v 1 |
28
|
|
|
// ---------------------------------------------------------------- // |
29
|
|
|
// Author: Marcello Brandao // |
30
|
|
|
// ----------------------------------------------------------------- // |
31
|
|
|
|
32
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
33
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
34
|
|
|
//include_once("../class/assessment_respostas.php"); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* assessment_perguntas class. |
38
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
39
|
|
|
* of XOOPS user class objects. |
40
|
|
|
*/ |
41
|
|
|
class assessment_perguntas extends XoopsObject |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
public $db; |
44
|
|
|
|
45
|
|
|
// constructor |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param null $id |
49
|
|
|
* @return assessment_perguntas |
|
|
|
|
50
|
|
|
*/ |
51
|
|
|
public function __construct($id = null) |
52
|
|
|
{ |
53
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
54
|
|
|
$this->initVar('cod_pergunta', XOBJ_DTYPE_INT, null, false, 10); |
55
|
|
|
$this->initVar('cod_prova', XOBJ_DTYPE_INT, null, false, 10); |
56
|
|
|
$this->initVar('titulo', XOBJ_DTYPE_TXTBOX, null, false); |
57
|
|
|
$this->initVar('data_criacao', XOBJ_DTYPE_TXTBOX, null, false); |
58
|
|
|
$this->initVar('data_update', XOBJ_DTYPE_TXTBOX, null, false); |
59
|
|
|
$this->initVar('uid_elaborador', XOBJ_DTYPE_TXTBOX, null, false); |
60
|
|
|
$this->initVar('ordem', XOBJ_DTYPE_INT, null, false, 10); |
61
|
|
View Code Duplication |
if (!empty($id)) { |
|
|
|
|
62
|
|
|
if (is_array($id)) { |
63
|
|
|
$this->assignVars($id); |
64
|
|
|
} else { |
65
|
|
|
$this->load((int)$id); |
66
|
|
|
} |
67
|
|
|
} else { |
68
|
|
|
$this->setNew(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $id |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public function load($id) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_perguntas') . ' WHERE cod_pergunta=' . $id; |
78
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
79
|
|
|
$this->assignVars($myrow); |
80
|
|
|
if (!$myrow) { |
81
|
|
|
$this->setNew(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param array $criteria |
87
|
|
|
* @param bool $asobject |
88
|
|
|
* @param string $sort |
89
|
|
|
* @param string $order |
90
|
|
|
* @param int $limit |
91
|
|
|
* @param int $start |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
View Code Duplication |
public function getAllassessment_perguntass($criteria = array(), $asobject = false, $sort = 'cod_pergunta', $order = 'ASC', $limit = 0, $start = 0) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
98
|
|
|
$ret = array(); |
99
|
|
|
$where_query = ''; |
100
|
|
|
if (is_array($criteria) && count($criteria) > 0) { |
101
|
|
|
$where_query = ' WHERE'; |
102
|
|
|
foreach ($criteria as $c) { |
103
|
|
|
$where_query .= " $c AND"; |
104
|
|
|
} |
105
|
|
|
$where_query = substr($where_query, 0, -4); |
106
|
|
|
} elseif (!is_array($criteria) && $criteria) { |
107
|
|
|
$where_query = ' WHERE ' . $criteria; |
108
|
|
|
} |
109
|
|
|
if (!$asobject) { |
110
|
|
|
$sql = 'SELECT cod_pergunta FROM ' . $db->prefix('assessment_perguntas') . "$where_query ORDER BY $sort $order"; |
111
|
|
|
$result = $db->query($sql, $limit, $start); |
112
|
|
|
while ($myrow = $db->fetchArray($result)) { |
113
|
|
|
$ret[] = $myrow['assessment_perguntas_id']; |
114
|
|
|
} |
115
|
|
|
} else { |
116
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('assessment_perguntas') . "$where_query ORDER BY $sort $order"; |
117
|
|
|
$result = $db->query($sql, $limit, $start); |
118
|
|
|
while ($myrow = $db->fetchArray($result)) { |
119
|
|
|
$ret[] = new assessment_perguntas($myrow); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $ret; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// ------------------------------------------------------------------------- |
128
|
|
|
// ------------------assessment_perguntas user handler class ------------------- |
129
|
|
|
// ------------------------------------------------------------------------- |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* assessment_perguntashandler class. |
133
|
|
|
* This class provides simple mecanisme for assessment_perguntas object |
134
|
|
|
*/ |
135
|
|
|
class Xoopsassessment_perguntasHandler extends XoopsPersistableObjectHandler |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
/** |
138
|
|
|
* create a new assessment_perguntas |
139
|
|
|
* |
140
|
|
|
* @param bool $isNew flag the new objects as "new"? |
141
|
|
|
* |
142
|
|
|
* @return object assessment_perguntas |
143
|
|
|
*/ |
144
|
|
|
public function &create($isNew = true) |
145
|
|
|
{ |
146
|
|
|
$assessment_perguntas = new assessment_perguntas(); |
147
|
|
|
if ($isNew) { |
148
|
|
|
$assessment_perguntas->setNew(); |
149
|
|
|
} //hack consertando |
150
|
|
|
else { |
151
|
|
|
$assessment_perguntas->unsetNew(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
//fim do hack para consertar |
155
|
|
|
return $assessment_perguntas; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* retrieve a assessment_perguntas |
160
|
|
|
* |
161
|
|
|
* @param mixed $id ID |
162
|
|
|
* @param array $fields fields to fetch |
|
|
|
|
163
|
|
|
* @return XoopsObject {@link XoopsObject} |
|
|
|
|
164
|
|
|
*/ |
165
|
|
View Code Duplication |
public function get($id = null, $fields = null) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_perguntas') . ' WHERE cod_pergunta=' . $id; |
168
|
|
|
if (!$result = $this->db->query($sql)) { |
169
|
|
|
return false; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$numrows = $this->db->getRowsNum($result); |
173
|
|
|
if ($numrows == 1) { |
174
|
|
|
$assessment_perguntas = new assessment_perguntas(); |
175
|
|
|
$assessment_perguntas->assignVars($this->db->fetchArray($result)); |
176
|
|
|
|
177
|
|
|
return $assessment_perguntas; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return false; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* insert a new assessment_perguntas in the database |
185
|
|
|
* |
186
|
|
|
* @param XoopsObject $assessment_perguntas reference to the {@link assessment_perguntas} object |
187
|
|
|
* @param bool $force |
188
|
|
|
* |
189
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
190
|
|
|
*/ |
191
|
|
View Code Duplication |
public function insert(XoopsObject $assessment_perguntas, $force = false) |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
global $xoopsConfig; |
|
|
|
|
194
|
|
|
if (get_class($assessment_perguntas) != 'assessment_perguntas') { |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
if (!$assessment_perguntas->isDirty()) { |
198
|
|
|
return true; |
199
|
|
|
} |
200
|
|
|
if (!$assessment_perguntas->cleanVars()) { |
201
|
|
|
return false; |
202
|
|
|
} |
203
|
|
|
foreach ($assessment_perguntas->cleanVars as $k => $v) { |
204
|
|
|
${$k} = $v; |
205
|
|
|
} |
206
|
|
|
$now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
207
|
|
|
if ($assessment_perguntas->isNew()) { |
208
|
|
|
// ajout/modification d'un assessment_perguntas |
209
|
|
|
$assessment_perguntas = new assessment_perguntas(); |
210
|
|
|
$format = 'INSERT INTO %s (cod_pergunta, cod_prova, titulo, data_criacao, data_update, uid_elaborador,ordem)'; |
211
|
|
|
$format .= 'VALUES (%u, %u, %s, %s, %s, %s, %u)'; |
212
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_perguntas'), $cod_pergunta, $cod_prova, $this->db->quoteString($titulo), $now, $now, $this->db->quoteString($uid_elaborador), $ordem); |
|
|
|
|
213
|
|
|
$force = true; |
214
|
|
|
} else { |
215
|
|
|
$format = 'UPDATE %s SET '; |
216
|
|
|
$format .= 'cod_pergunta=%u, cod_prova=%u, titulo=%s, data_criacao=%s, data_update=%s, uid_elaborador=%s, ordem=%u'; |
217
|
|
|
$format .= ' WHERE cod_pergunta = %u'; |
218
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_perguntas'), $cod_pergunta, $cod_prova, $this->db->quoteString($titulo), $now, $now, $this->db->quoteString($uid_elaborador), $ordem, $cod_pergunta); |
|
|
|
|
219
|
|
|
} |
220
|
|
|
if (false != $force) { |
|
|
|
|
221
|
|
|
$result = $this->db->queryF($sql); |
222
|
|
|
} else { |
223
|
|
|
$result = $this->db->query($sql); |
224
|
|
|
} |
225
|
|
|
if (!$result) { |
226
|
|
|
return false; |
227
|
|
|
} |
228
|
|
|
if (empty($cod_pergunta)) { |
|
|
|
|
229
|
|
|
$cod_pergunta = $this->db->getInsertId(); |
230
|
|
|
} |
231
|
|
|
$assessment_perguntas->assignVar('cod_pergunta', $cod_pergunta); |
232
|
|
|
|
233
|
|
|
return true; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* delete a assessment_perguntas from the database |
238
|
|
|
* |
239
|
|
|
* @param XoopsObject $assessment_perguntas reference to the assessment_perguntas to delete |
240
|
|
|
* @param bool $force |
241
|
|
|
* |
242
|
|
|
* @return bool FALSE if failed. |
243
|
|
|
*/ |
244
|
|
View Code Duplication |
public function delete(XoopsObject $assessment_perguntas, $force = false) |
|
|
|
|
245
|
|
|
{ |
246
|
|
|
if (get_class($assessment_perguntas) != 'assessment_perguntas') { |
247
|
|
|
return false; |
248
|
|
|
} |
249
|
|
|
$sql = sprintf('DELETE FROM %s WHERE cod_pergunta = %u', $this->db->prefix('assessment_perguntas'), $assessment_perguntas->getVar('cod_pergunta')); |
250
|
|
|
if (false != $force) { |
|
|
|
|
251
|
|
|
$result = $this->db->queryF($sql); |
252
|
|
|
} else { |
253
|
|
|
$result = $this->db->query($sql); |
254
|
|
|
} |
255
|
|
|
if (!$result) { |
256
|
|
|
return false; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return true; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* retrieve assessment_perguntass from the database |
264
|
|
|
* |
265
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
|
|
|
266
|
|
|
* @param bool $id_as_key use the UID as key for the array? |
267
|
|
|
* |
268
|
|
|
* @param bool $as_object |
269
|
|
|
* @return array array of <a href='psi_element://assessment_perguntas'>assessment_perguntas</a> objects |
270
|
|
|
* objects |
271
|
|
|
*/ |
272
|
|
View Code Duplication |
public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true) |
|
|
|
|
273
|
|
|
{ |
274
|
|
|
$ret = array(); |
275
|
|
|
$limit = $start = 0; |
276
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_perguntas'); |
277
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
278
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
279
|
|
|
if ($criteria->getSort() != '') { |
280
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
281
|
|
|
} |
282
|
|
|
$limit = $criteria->getLimit(); |
283
|
|
|
$start = $criteria->getStart(); |
284
|
|
|
} |
285
|
|
|
$result = $this->db->query($sql, $limit, $start); |
286
|
|
|
if (!$result) { |
287
|
|
|
return $ret; |
288
|
|
|
} |
289
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
290
|
|
|
$assessment_perguntas = new assessment_perguntas(); |
291
|
|
|
$assessment_perguntas->assignVars($myrow); |
292
|
|
|
if (!$id_as_key) { |
293
|
|
|
$ret[] = $assessment_perguntas; |
294
|
|
|
} else { |
295
|
|
|
$ret[$myrow['cod_pergunta']] = $assessment_perguntas; |
296
|
|
|
} |
297
|
|
|
unset($assessment_perguntas); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
return $ret; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* retrieve assessment_perguntass from the database |
305
|
|
|
* |
306
|
|
|
* @param object $criteria {@link CriteriaElement} conditions to be met |
|
|
|
|
307
|
|
|
* @param bool $id_as_key use the UID as key for the array? |
308
|
|
|
* |
309
|
|
|
* @return array array of {@link assessment_perguntas} objects |
310
|
|
|
*/ |
311
|
|
|
public function &getCodObjects($criteria = null, $id_as_key = false) |
312
|
|
|
{ |
313
|
|
|
$ret = array(); |
314
|
|
|
$limit = $start = 0; |
315
|
|
|
$sql = 'SELECT cod_pergunta FROM ' . $this->db->prefix('assessment_perguntas'); |
316
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
317
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
318
|
|
|
if ($criteria->getSort() != '') { |
319
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
320
|
|
|
} |
321
|
|
|
$limit = $criteria->getLimit(); |
322
|
|
|
$start = $criteria->getStart(); |
323
|
|
|
} |
324
|
|
|
$result = $this->db->query($sql, $limit, $start); |
325
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
326
|
|
|
$ret[] = $myrow['cod_pergunta']; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return $ret; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* count assessment_perguntass matching a condition |
334
|
|
|
* |
335
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
|
|
|
336
|
|
|
* |
337
|
|
|
* @return int count of assessment_perguntass |
338
|
|
|
*/ |
339
|
|
View Code Duplication |
public function getCount(CriteriaElement $criteria = null) |
|
|
|
|
340
|
|
|
{ |
341
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('assessment_perguntas'); |
342
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
343
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
344
|
|
|
} |
345
|
|
|
$result = $this->db->query($sql); |
346
|
|
|
if (!$result) { |
347
|
|
|
return 0; |
348
|
|
|
} |
349
|
|
|
list($count) = $this->db->fetchRow($result); |
350
|
|
|
|
351
|
|
|
return $count; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* delete assessment_perguntass matching a set of conditions |
356
|
|
|
* |
357
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} |
|
|
|
|
358
|
|
|
* |
359
|
|
|
* @param bool $force |
360
|
|
|
* @param bool $asObject |
361
|
|
|
* @return bool FALSE if deletion failed |
362
|
|
|
*/ |
363
|
|
View Code Duplication |
public function deleteAll(CriteriaElement $criteria = null, $force = true, $asObject = false) |
|
|
|
|
364
|
|
|
{ |
365
|
|
|
$sql = 'DELETE FROM ' . $this->db->prefix('assessment_perguntas'); |
366
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
367
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
368
|
|
|
} |
369
|
|
|
if (!$result = $this->db->query($sql)) { |
370
|
|
|
return false; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
return true; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* cria form de inser��o e edi��o de pergunta |
378
|
|
|
* |
379
|
|
|
* @param string $action caminho para arquivo que ... |
380
|
|
|
* @param null $prova |
381
|
|
|
* @return bool FALSE if failed |
382
|
|
|
* @internal param object $assessment_prova <a href='psi_element://assessment_pprova'>assessment_pprova</a> |
383
|
|
|
* |
384
|
|
|
*/ |
385
|
|
|
public function renderFormCadastrar($action, $prova = null) |
386
|
|
|
{ |
387
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_CADASTRAR . ' ' . _AM_ASSESSMENT_PERGUNTA, 'form_pergunta', $action, 'post', true); |
388
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', '', 2, 50); |
389
|
|
|
$campo_ordem = new XoopsFormText(_AM_ASSESSMENT_ORDEM, 'campo_ordem', 3, 3, '0'); |
390
|
|
|
$cod_prova = $prova->getVar('cod_prova'); |
|
|
|
|
391
|
|
|
$titulo_prova = $prova->getVar('titulo'); |
|
|
|
|
392
|
|
|
$campo_prova_label = new XoopsFormLabel(_AM_ASSESSMENT_PROVA, $titulo_prova); |
393
|
|
|
$campo_prova_valor = new XoopsFormHidden('campo_cod_prova', $cod_prova); |
394
|
|
|
$campo_resposta1 = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . ' 1 <br />(correta)', 'campo_resposta1', '', 2, 50); |
395
|
|
|
$campo_resposta1->setExtra('style="background-color:#ECFFEC"'); |
396
|
|
|
$campo_resposta2 = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . ' 2 - (errada)', 'campo_resposta2', '', 2, 50); |
397
|
|
|
$campo_resposta2->setExtra('style="background-color:#FFF0F0"'); |
398
|
|
|
$campo_resposta3 = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . ' 3 - (errada)', 'campo_resposta3', '', 2, 50); |
399
|
|
|
$campo_resposta3->setExtra('style="background-color:#FFF0F0"'); |
400
|
|
|
$campo_resposta4 = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . ' 4 - (errada)', 'campo_resposta4', '', 2, 50); |
401
|
|
|
$campo_resposta4->setExtra('style="background-color:#FFF0F0"'); |
402
|
|
|
$campo_resposta5 = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . ' 5 - (errada)', 'campo_resposta5', '', 2, 50); |
403
|
|
|
$campo_resposta5->setExtra('style="background-color:#FFF0F0"'); |
404
|
|
|
$botao_enviar = new XoopsFormButton(_AM_ASSESSMENT_CADASTRAR, 'botao_submit', _SUBMIT, 'submit'); |
405
|
|
|
$form->addElement($campo_prova_label); |
406
|
|
|
$form->addElement($campo_prova_valor); |
407
|
|
|
$form->addElement($campo_ordem, true); |
408
|
|
|
$form->addElement($campo_titulo, true); |
409
|
|
|
$form->addElement($campo_resposta1, true); |
410
|
|
|
$form->addElement($campo_resposta2, true); |
411
|
|
|
$form->addElement($campo_resposta3, true); |
412
|
|
|
$form->addElement($campo_resposta4, true); |
413
|
|
|
$form->addElement($campo_resposta5, true); |
414
|
|
|
$form->addElement($botao_enviar); |
415
|
|
|
$form->display(); |
416
|
|
|
|
417
|
|
|
return true; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* @param $action |
422
|
|
|
* @param $pergunta |
423
|
|
|
* @param array $respostas |
424
|
|
|
* |
425
|
|
|
* @return bool |
426
|
|
|
*/ |
427
|
|
|
public function renderFormEditar($action, $pergunta, $respostas = array()) |
428
|
|
|
{ |
429
|
|
|
$cod_prova = $pergunta->getVar('cod_prova'); |
|
|
|
|
430
|
|
|
$titulo = $pergunta->getVar('titulo'); |
431
|
|
|
$cod_pergunta = $pergunta->getVar('cod_pergunta'); |
432
|
|
|
$ordem = $pergunta->getVar('ordem'); |
433
|
|
|
|
434
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_EDITAR . ' ' . _AM_ASSESSMENT_PERGUNTA, 'form_pergunta', $action, 'post', true); |
435
|
|
|
|
436
|
|
|
$campo_ordem = new XoopsFormText(_AM_ASSESSMENT_ORDEM, 'campo_ordem', 3, 3, $ordem); |
437
|
|
|
$form->addElement($campo_ordem, true); |
438
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_PERGUNTA, 'campo_titulo', $titulo, 2, 50); |
439
|
|
|
$form->addElement($campo_titulo, true); |
440
|
|
|
$botao_enviar = new XoopsFormButton('', 'botao_submit', _AM_ASSESSMENT_SALVARALTERACOES, 'submit'); |
441
|
|
|
$campo_cod_pergunta = new XoopsFormHidden('campo_cod_pergunta', $cod_pergunta); |
442
|
|
|
|
443
|
|
|
$i = 1; |
444
|
|
|
foreach ($respostas as $resposta) { |
445
|
|
|
$titulo_resposta = $resposta->getVar('titulo'); |
446
|
|
|
$cod_resposta = $resposta->getVar('cod_resposta'); |
447
|
|
|
$nome_campo_titulo_resposta = 'campo_resposta' . $i; |
448
|
|
|
if ($resposta->getVar('iscerta') == 1) { |
449
|
|
|
$resposta_correta = new XoopsFormTextArea(_AM_ASSESSMENT_RESPCORRETA . $i, $nome_campo_titulo_resposta, $titulo_resposta, 2, 50); |
450
|
|
|
$resposta_correta->setExtra('style="background-color:#ECFFEC"'); |
451
|
|
|
$cod_resposta_correta = new XoopsFormHidden('campo_cod_resp1', $cod_resposta); |
452
|
|
|
$form->addElement($cod_resposta_correta, true); |
453
|
|
|
$form->addElement($resposta_correta, true); |
454
|
|
|
} else { |
455
|
|
|
$vetor_respostas_erradas[$i] = new XoopsFormTextArea(_AM_ASSESSMENT_RESPOSTA . $i, $nome_campo_titulo_resposta, $titulo_resposta, 2, 50); |
|
|
|
|
456
|
|
|
$vetor_respostas_erradas[$i]->setExtra('style="background-color:#FFF0F0"'); |
|
|
|
|
457
|
|
|
$vetor_cod_respostas_erradas[$i] = new XoopsFormHidden('campo_cod_resp' . $i, $cod_resposta); |
|
|
|
|
458
|
|
|
$form->addElement($vetor_respostas_erradas[$i], true); |
459
|
|
|
$form->addElement($vetor_cod_respostas_erradas[$i], true); |
|
|
|
|
460
|
|
|
} |
461
|
|
|
++$i; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
$form->addElement($campo_prova_valor, true); |
|
|
|
|
465
|
|
|
$form->addElement($campo_cod_pergunta, true); |
466
|
|
|
|
467
|
|
|
$form->addElement($botao_enviar); |
468
|
|
|
$form->display(); |
469
|
|
|
|
470
|
|
|
return true; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* @param $action |
475
|
|
|
* @param $pergunta |
476
|
|
|
* @param array $respostas |
477
|
|
|
* @param int $param_cod_resposta |
478
|
|
|
* |
479
|
|
|
* @return XoopsThemeForm |
480
|
|
|
*/ |
481
|
|
|
public function renderFormResponder($action, $pergunta, $respostas = array(), $param_cod_resposta = 0) |
|
|
|
|
482
|
|
|
{ |
483
|
|
|
global $_GET; |
|
|
|
|
484
|
|
|
$start = $_GET['start']; |
485
|
|
|
$cod_prova = $pergunta->getVar('cod_prova'); |
|
|
|
|
486
|
|
|
$titulo = $pergunta->getVar('titulo'); |
487
|
|
|
$cod_pergunta = $pergunta->getVar('cod_pergunta'); |
488
|
|
|
$form = new XoopsThemeForm("$titulo", 'form_resposta', $action, 'post', true); |
489
|
|
|
|
490
|
|
|
$botao_enviar = new XoopsFormButton('', 'botao_submit', _SUBMIT, 'submit'); |
491
|
|
|
$campo_cod_pergunta = new XoopsFormHidden('cod_pergunta', $cod_pergunta); |
492
|
|
|
$campo_start = new XoopsFormHidden('start', $start); |
493
|
|
|
$campo_respostas = new XoopsFormRadio(_MA_ASSESSMENT_RESPOSTA, 'cod_resposta', '','<br/>'); |
494
|
|
|
shuffle($respostas); |
495
|
|
|
|
496
|
|
|
$campo_respostas->setValue($param_cod_resposta); |
497
|
|
|
foreach ($respostas as $resposta) { |
498
|
|
|
$titulo_resposta = $resposta->getVar('titulo'); |
499
|
|
|
$cod_resposta = $resposta->getVar('cod_resposta'); |
500
|
|
|
$campo_respostas->addOption($cod_resposta, $titulo_resposta . '<br />'); |
501
|
|
|
} |
502
|
|
|
//$form->addElement($campo_prova_valor,true); |
|
|
|
|
503
|
|
|
$form->addElement($campo_cod_pergunta); |
504
|
|
|
$form->addElement($campo_respostas, true); |
505
|
|
|
$form->addElement($campo_start); |
506
|
|
|
|
507
|
|
|
$form->addElement($botao_enviar); |
508
|
|
|
|
509
|
|
|
//$form->display(); |
|
|
|
|
510
|
|
|
return $form; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* @param $db |
515
|
|
|
* |
516
|
|
|
* @return mixed |
517
|
|
|
*/ |
518
|
|
|
public function pegarultimocodigo(&$db) |
519
|
|
|
{ |
520
|
|
|
return $db->getInsertId(); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Copia as perguntas e salva elas ligadas � prova clone |
525
|
|
|
* |
526
|
|
|
* @param object $criteria {@link CriteriaElement} to match |
527
|
|
|
* |
528
|
|
|
* @param $cod_prova |
529
|
|
|
* @return int count of assessment_perguntass |
|
|
|
|
530
|
|
|
*/ |
531
|
|
|
public function clonarPerguntas($criteria, $cod_prova) |
532
|
|
|
{ |
533
|
|
|
global $xoopsDB; |
|
|
|
|
534
|
|
|
$fabrica_de_respostas = new Xoopsassessment_respostasHandler($xoopsDB); |
535
|
|
|
$perguntas = $this->getObjects($criteria); |
536
|
|
|
foreach ($perguntas as $pergunta) { |
537
|
|
|
$cod_pergunta = $pergunta->getVar('cod_pergunta'); |
538
|
|
|
$pergunta->setVar('cod_prova', $cod_prova); |
539
|
|
|
$pergunta->setVar('cod_pergunta', 0); |
540
|
|
|
$pergunta->setNew(); |
541
|
|
|
$this->insert($pergunta); |
542
|
|
|
$cod_pergunta_clone = $xoopsDB->getInsertId(); |
543
|
|
|
|
544
|
|
|
$criteria_pergunta = new Criteria('cod_pergunta', $cod_pergunta); |
545
|
|
|
$respostas = $fabrica_de_respostas->getObjects($criteria_pergunta); |
546
|
|
|
|
547
|
|
|
foreach ($respostas as $resposta) { |
548
|
|
|
$resposta->setVar('cod_pergunta', $cod_pergunta_clone); |
549
|
|
|
$resposta->setVar('cod_resposta', 0); |
550
|
|
|
$resposta->setNew(); |
551
|
|
|
$fabrica_de_respostas->insert($resposta); |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
|
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.