1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// $Id: assessment_documentos.php,v 1.10 2007/03/24 17:50:52 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_documentos.php,v 1 |
28
|
|
|
// ---------------------------------------------------------------- // |
29
|
|
|
// // |
30
|
|
|
// ----------------------------------------------------------------- // |
31
|
|
|
|
32
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
33
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
34
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
35
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.inc.php'; |
36
|
|
|
//include_once XOOPS_ROOT_PATH."/class/xoopseditor/mastop_publish/formmpublishtextarea.php"; |
|
|
|
|
37
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsform/formselecteditor.php'; |
38
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
39
|
|
|
//include_once XOOPS_ROOT_PATH."/Frameworks/art/functions.sanitizer.php"; |
|
|
|
|
40
|
|
|
//include_once XOOPS_ROOT_PATH."/Frameworks/xoops22/class/xoopsform/xoopsformloader.php"; |
41
|
|
|
|
42
|
|
|
include_once __DIR__ . '/assessment_perguntas.php'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* assessment_documentos class. |
46
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
47
|
|
|
* of XOOPS user class objects. |
48
|
|
|
*/ |
49
|
|
|
class assessment_documentos extends XoopsObject |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
public $db; |
52
|
|
|
|
53
|
|
|
// constructor |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param null $id |
57
|
|
|
* @return assessment_documentos |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
public function __construct($id = null) |
60
|
|
|
{ |
61
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
62
|
|
|
$this->initVar('cod_documento', XOBJ_DTYPE_INT, null, false, 10); |
63
|
|
|
$this->initVar('titulo', XOBJ_DTYPE_TXTBOX, null, false); |
64
|
|
|
$this->initVar('tipo', XOBJ_DTYPE_INT, null, false, 10); |
65
|
|
|
$this->initVar('cod_prova', XOBJ_DTYPE_INT, null, false, 10); |
66
|
|
|
$this->initVar('cods_perguntas', XOBJ_DTYPE_TXTBOX, null, false); |
67
|
|
|
$this->initVar('documento', XOBJ_DTYPE_TXTAREA, null, false); |
68
|
|
|
$this->initVar('uid_elaborador', XOBJ_DTYPE_INT, null, false, 10); |
69
|
|
|
$this->initVar('fonte', XOBJ_DTYPE_TXTBOX, null, false); |
70
|
|
|
$this->initVar('html', XOBJ_DTYPE_INT, null, false, 10); |
71
|
|
View Code Duplication |
if (!empty($id)) { |
|
|
|
|
72
|
|
|
if (is_array($id)) { |
73
|
|
|
$this->assignVars($id); |
74
|
|
|
} else { |
75
|
|
|
$this->load((int)$id); |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
$this->setNew(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $id |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function load($id) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_documentos') . ' WHERE cod_documento=' . $id; |
88
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
89
|
|
|
$this->assignVars($myrow); |
90
|
|
|
if (!$myrow) { |
91
|
|
|
$this->setNew(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param array $criteria |
97
|
|
|
* @param bool $asobject |
98
|
|
|
* @param string $sort |
99
|
|
|
* @param string $order |
100
|
|
|
* @param int $limit |
101
|
|
|
* @param int $start |
102
|
|
|
* |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function getAllassessment_documentoss($criteria = array(), $asobject = false, $sort = 'cod_documento', $order = 'ASC', $limit = 0, $start = 0) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
108
|
|
|
$ret = array(); |
109
|
|
|
$where_query = ''; |
110
|
|
|
if (is_array($criteria) && count($criteria) > 0) { |
111
|
|
|
$where_query = ' WHERE'; |
112
|
|
|
foreach ($criteria as $c) { |
113
|
|
|
$where_query .= " $c AND"; |
114
|
|
|
} |
115
|
|
|
$where_query = substr($where_query, 0, -4); |
116
|
|
|
} elseif (!is_array($criteria) && $criteria) { |
117
|
|
|
$where_query = ' WHERE ' . $criteria; |
118
|
|
|
} |
119
|
|
|
if (!$asobject) { |
120
|
|
|
$sql = 'SELECT cod_documento FROM ' . $db->prefix('assessment_documentos') . "$where_query ORDER BY $sort $order"; |
121
|
|
|
$result = $db->query($sql, $limit, $start); |
122
|
|
|
while ($myrow = $db->fetchArray($result)) { |
123
|
|
|
$ret[] = $myrow['assessment_documentos_id']; |
124
|
|
|
} |
125
|
|
|
} else { |
126
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('assessment_documentos') . "$where_query ORDER BY $sort $order"; |
127
|
|
|
$result = $db->query($sql, $limit, $start); |
128
|
|
|
while ($myrow = $db->fetchArray($result)) { |
129
|
|
|
$ret[] = new assessment_documentos($myrow); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $ret; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
// ------------------------------------------------------------------------- |
138
|
|
|
// ------------------assessment_documentos user handler class ------------------- |
139
|
|
|
// ------------------------------------------------------------------------- |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* assessment_documentoshandler class. |
143
|
|
|
* This class provides simple mecanisme for assessment_documentos object |
144
|
|
|
*/ |
145
|
|
|
class Xoopsassessment_documentosHandler extends XoopsPersistableObjectHandler |
|
|
|
|
146
|
|
|
{ |
147
|
|
|
/** |
148
|
|
|
* create a new assessment_documentos |
149
|
|
|
* |
150
|
|
|
* @param bool $isNew flag the new objects as "new"? |
151
|
|
|
* |
152
|
|
|
* @return object assessment_documentos |
153
|
|
|
*/ |
154
|
|
|
public function &create($isNew = true) |
155
|
|
|
{ |
156
|
|
|
$assessment_documentos = new assessment_documentos(); |
157
|
|
|
if ($isNew) { |
158
|
|
|
$assessment_documentos->setNew(); |
159
|
|
|
} else { |
160
|
|
|
$assessment_documentos->unsetNew(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $assessment_documentos; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* retrieve a assessment_documentos |
168
|
|
|
* |
169
|
|
|
* @param mixed $id ID |
170
|
|
|
* @param array $fields fields to fetch |
|
|
|
|
171
|
|
|
* @return XoopsObject {@link XoopsObject} |
|
|
|
|
172
|
|
|
*/ |
173
|
|
View Code Duplication |
public function get($id = null, $fields = null) |
|
|
|
|
174
|
|
|
{ |
175
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_documentos') . ' WHERE cod_documento=' . $id; |
176
|
|
|
if (!$result = $this->db->query($sql)) { |
177
|
|
|
return false; |
178
|
|
|
} |
179
|
|
|
$numrows = $this->db->getRowsNum($result); |
180
|
|
|
if ($numrows == 1) { |
181
|
|
|
$assessment_documentos = new assessment_documentos(); |
182
|
|
|
$assessment_documentos->assignVars($this->db->fetchArray($result)); |
183
|
|
|
|
184
|
|
|
return $assessment_documentos; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return false; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* insert a new assessment_documentos in the database |
192
|
|
|
* |
193
|
|
|
* @param XoopsObject $assessment_documentos reference to the {@link assessment_documentos} object |
194
|
|
|
* @param bool $force flag to force the query execution despite security settings |
195
|
|
|
* |
196
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
197
|
|
|
*/ |
198
|
|
|
public function insert(XoopsObject $assessment_documentos, $force = false) |
199
|
|
|
{ |
200
|
|
|
global $xoopsConfig; |
|
|
|
|
201
|
|
|
if (get_class($assessment_documentos) != 'assessment_documentos') { |
202
|
|
|
return false; |
203
|
|
|
} |
204
|
|
|
if (!$assessment_documentos->isDirty()) { |
205
|
|
|
return true; |
206
|
|
|
} |
207
|
|
|
if (!$assessment_documentos->cleanVars()) { |
208
|
|
|
return false; |
209
|
|
|
} |
210
|
|
|
foreach ($assessment_documentos->cleanVars as $k => $v) { |
211
|
|
|
${$k} = $v; |
212
|
|
|
} |
213
|
|
|
$now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
|
|
|
|
214
|
|
|
if ($assessment_documentos->isNew()) { |
215
|
|
|
// ajout/modification d'un assessment_documentos |
216
|
|
|
$assessment_documentos = new assessment_documentos(); |
217
|
|
|
$format = 'INSERT INTO %s (cod_documento, titulo, tipo, cod_prova, cods_perguntas, documento, uid_elaborador, fonte, html)'; |
218
|
|
|
$format .= 'VALUES (%u, %s, %u, %u, %s, %s, %u, %s, %u)'; |
219
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_documentos'), $cod_documento, $this->db->quoteString($titulo), $tipo, $cod_prova, $this->db->quoteString($cods_perguntas), $this->db->quoteString($documento), |
|
|
|
|
220
|
|
|
$uid_elaborador, $this->db->quoteString($fonte), $html); |
|
|
|
|
221
|
|
|
$force = true; |
222
|
|
|
} else { |
223
|
|
|
$format = 'UPDATE %s SET '; |
224
|
|
|
$format .= 'cod_documento=%u, titulo=%s, tipo=%u, cod_prova=%u, cods_perguntas=%s, documento=%s, uid_elaborador=%u, fonte=%s, html=%u'; |
225
|
|
|
$format .= ' WHERE cod_documento = %u'; |
226
|
|
|
$sql = sprintf($format, $this->db->prefix('assessment_documentos'), $cod_documento, $this->db->quoteString($titulo), $tipo, $cod_prova, $this->db->quoteString($cods_perguntas), $this->db->quoteString($documento), $uid_elaborador, |
|
|
|
|
227
|
|
|
$this->db->quoteString($fonte), $html, $cod_documento); |
|
|
|
|
228
|
|
|
} |
229
|
|
|
if (false != $force) { |
|
|
|
|
230
|
|
|
$result = $this->db->queryF($sql); |
231
|
|
|
} else { |
232
|
|
|
$result = $this->db->query($sql); |
233
|
|
|
} |
234
|
|
|
if (!$result) { |
235
|
|
|
return false; |
236
|
|
|
} |
237
|
|
|
if (empty($cod_documento)) { |
|
|
|
|
238
|
|
|
$cod_documento = $this->db->getInsertId(); |
239
|
|
|
} |
240
|
|
|
$assessment_documentos->assignVar('cod_documento', $cod_documento); |
241
|
|
|
|
242
|
|
|
return true; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* delete a assessment_documentos from the database |
247
|
|
|
* |
248
|
|
|
* @param XoopsObject $assessment_documentos reference to the assessment_documentos to delete |
249
|
|
|
* @param bool $force |
250
|
|
|
* |
251
|
|
|
* @return bool FALSE if failed. |
252
|
|
|
*/ |
253
|
|
View Code Duplication |
public function delete(XoopsObject $assessment_documentos, $force = false) |
|
|
|
|
254
|
|
|
{ |
255
|
|
|
if (get_class($assessment_documentos) != 'assessment_documentos') { |
256
|
|
|
return false; |
257
|
|
|
} |
258
|
|
|
$sql = sprintf('DELETE FROM %s WHERE cod_documento = %u', $this->db->prefix('assessment_documentos'), $assessment_documentos->getVar('cod_documento')); |
259
|
|
|
if (false != $force) { |
|
|
|
|
260
|
|
|
$result = $this->db->queryF($sql); |
261
|
|
|
} else { |
262
|
|
|
$result = $this->db->query($sql); |
263
|
|
|
} |
264
|
|
|
if (!$result) { |
265
|
|
|
return false; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
return true; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* retrieve assessment_documentoss from the database |
273
|
|
|
* |
274
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
|
|
|
275
|
|
|
* @param bool $id_as_key use the UID as key for the array? |
276
|
|
|
* |
277
|
|
|
* @param bool $as_object |
278
|
|
|
* @return array array of <a href='psi_element://$assessment_documentos'>$assessment_documentos</a> objects |
279
|
|
|
* objects |
280
|
|
|
*/ |
281
|
|
View Code Duplication |
public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true) |
|
|
|
|
282
|
|
|
{ |
283
|
|
|
$ret = array(); |
284
|
|
|
$limit = $start = 0; |
285
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('assessment_documentos'); |
286
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
287
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
288
|
|
|
if ($criteria->getSort() != '') { |
289
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
290
|
|
|
} |
291
|
|
|
$limit = $criteria->getLimit(); |
292
|
|
|
$start = $criteria->getStart(); |
293
|
|
|
} |
294
|
|
|
$result = $this->db->query($sql, $limit, $start); |
295
|
|
|
if (!$result) { |
296
|
|
|
return $ret; |
297
|
|
|
} |
298
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
299
|
|
|
$assessment_documentos = new assessment_documentos(); |
300
|
|
|
$assessment_documentos->assignVars($myrow); |
301
|
|
|
if (!$id_as_key) { |
302
|
|
|
$ret[] =& $assessment_documentos; |
303
|
|
|
} else { |
304
|
|
|
$ret[$myrow['cod_documento']] =& $assessment_documentos; |
305
|
|
|
} |
306
|
|
|
unset($assessment_documentos); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
return $ret; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* retrieve assessment_documentoss from the database |
314
|
|
|
* |
315
|
|
|
* @param $cod_prova |
316
|
|
|
* @param $cod_pergunta |
317
|
|
|
* @return array array of <a href='psi_element://assessment_documentos'>assessment_documentos</a> objects |
318
|
|
|
* objects |
319
|
|
|
* @internal param object $criteria <a href='psi_element://CriteriaElement'>CriteriaElement</a> conditions to be met conditions to be met conditions to be met conditions to be met |
320
|
|
|
* @internal param bool $id_as_key use the UID as key for the array? |
321
|
|
|
* |
322
|
|
|
*/ |
323
|
|
|
public function &getDocumentosProvaPergunta($cod_prova, $cod_pergunta) |
324
|
|
|
{ |
325
|
|
|
$criteria = new criteria('cod_prova', $cod_prova); |
326
|
|
|
$cod_documentos = array(); |
|
|
|
|
327
|
|
|
$documentos_prova = $this->getObjects($criteria); |
328
|
|
|
$i = 0; |
329
|
|
|
foreach ($documentos_prova as $documento_prova) { |
330
|
|
|
$cods_perguntas = explode(',', $documento_prova->getVar('cods_perguntas')); |
331
|
|
|
if (in_array($cod_pergunta, $cods_perguntas)) { |
332
|
|
|
$documentos[$i]['titulo'] = $documento_prova->getVar('titulo'); |
|
|
|
|
333
|
|
|
$documentos[$i]['fonte'] = $documento_prova->getVar('fonte'); |
|
|
|
|
334
|
|
|
/*if ($xoopsModuleConfig['editorpadrao']=="dhtmlext"||$xoopsModuleConfig['editorpadrao']=="textarea") { |
|
|
|
|
335
|
|
|
$documentos[$i]['documento']= text_filter($documento_prova->getVar('documento',"s"),true);} else { |
336
|
|
|
$documentos[$i]['documento']= text_filter($documento_prova->getVar('documento',"n"),true); |
337
|
|
|
}*/ |
338
|
|
|
if ($documento_prova->getVar('html') == 1) { |
339
|
|
|
//$documentos[$i]['documento']= text_filter($documento_prova->getVar('documento',"n"),true); |
|
|
|
|
340
|
|
|
$documentos[$i]['documento'] = $documento_prova->getVar('documento', 'n'); |
341
|
|
|
} else { |
342
|
|
|
$documentos[$i]['documento'] = text_filter($documento_prova->getVar('documento', 's'), true); |
343
|
|
|
} |
344
|
|
|
++$i; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
return $documentos; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* count assessment_documentoss matching a condition |
353
|
|
|
* |
354
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} to match |
|
|
|
|
355
|
|
|
* |
356
|
|
|
* @return int count of assessment_documentoss |
357
|
|
|
*/ |
358
|
|
View Code Duplication |
public function getCount(CriteriaElement $criteria = null) |
|
|
|
|
359
|
|
|
{ |
360
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('assessment_documentos'); |
361
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
362
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
363
|
|
|
} |
364
|
|
|
$result = $this->db->query($sql); |
365
|
|
|
if (!$result) { |
366
|
|
|
return 0; |
367
|
|
|
} |
368
|
|
|
list($count) = $this->db->fetchRow($result); |
369
|
|
|
|
370
|
|
|
return $count; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* delete assessment_documentoss matching a set of conditions |
375
|
|
|
* |
376
|
|
|
* @param CriteriaElement $criteria {@link CriteriaElement} |
|
|
|
|
377
|
|
|
* |
378
|
|
|
* @param bool $force |
379
|
|
|
* @param bool $asObject |
380
|
|
|
* @return bool FALSE if deletion failed |
381
|
|
|
*/ |
382
|
|
View Code Duplication |
public function deleteAll(CriteriaElement $criteria = null, $force = true, $asObject = false) |
|
|
|
|
383
|
|
|
{ |
384
|
|
|
$sql = 'DELETE FROM ' . $this->db->prefix('assessment_documentos'); |
385
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
386
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
387
|
|
|
} |
388
|
|
|
if (!$result = $this->db->query($sql)) { |
389
|
|
|
return false; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
return true; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/* cria form de inser��o e edi��o de pergunta |
396
|
|
|
* |
397
|
|
|
* @param string $action caminho para arquivo que ... |
398
|
|
|
* @param object $assessment_perguntas {@link assessment_perguntas} |
399
|
|
|
* @return bool FALSE if deletion failed |
400
|
|
|
*/ |
401
|
|
|
/** |
402
|
|
|
* @param $action |
403
|
|
|
* @param $cod_prova |
404
|
|
|
* |
405
|
|
|
* @return bool |
406
|
|
|
*/ |
407
|
|
|
public function renderFormCadastrar($action, $cod_prova) |
|
|
|
|
408
|
|
|
{ |
409
|
|
|
global $xoopsDB, $xoopsUser; |
|
|
|
|
410
|
|
|
|
411
|
|
|
$fabrica_de_perguntas = new Xoopsassessment_perguntasHandler($xoopsDB); |
412
|
|
|
$criteria = new criteria('cod_prova', $cod_prova); |
413
|
|
|
|
414
|
|
|
$vetor_perguntas = $fabrica_de_perguntas->getObjects($criteria); |
415
|
|
|
$campo_perguntas = new XoopsFormSelect(_AM_ASSESSMENT_PERGASSOC, 'campo_perguntas', null, 10, true); |
416
|
|
|
|
417
|
|
|
foreach ($vetor_perguntas as $pergunta) { |
418
|
|
|
$campo_perguntas->addOption($pergunta->getVar('cod_pergunta'), $pergunta->getVar('titulo')); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_CADASTRAR . ' ' . _AM_ASSESSMENT_DOCUMENTO, 'form_documento', $action, 'post', true); |
422
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', '', 2, 50); |
423
|
|
|
$campo_fonte = new XoopsFormText(_AM_ASSESSMENT_FONTE, 'campo_fonte', 35, 20); |
424
|
|
|
$campo_codprova = new XoopsFormHidden('campo_codprova', $cod_prova); |
425
|
|
|
|
426
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
427
|
|
|
|
428
|
|
|
if (!is_object($GLOBALS['xoopsModule']) || $GLOBALS['xoopsModule']->getVar('dirname') != 'assessment') { |
429
|
|
|
$modhandler = &xoops_getHandler('module'); |
430
|
|
|
$module = &$modhandler->getByDirname('assessment'); |
431
|
|
|
$configHandler = &xoops_getHandler('config'); |
432
|
|
|
$moduleConfig = &$configHandler->getConfigsByCat(0, $module->getVar('mid')); |
433
|
|
|
} else { |
434
|
|
|
$moduleConfig =& $GLOBALS['xoopsModuleConfig']; |
435
|
|
|
} |
436
|
|
|
$editor = $moduleConfig['editorpadrao']; |
437
|
|
|
|
438
|
|
|
// Add the editor selection box |
439
|
|
|
// If dohtml is disabled, set $noHtml = true |
440
|
|
|
//$form->addElement(new XoopsFormSelectEditor($form, "editor", $editor, $noHtml = false)); |
|
|
|
|
441
|
|
|
|
442
|
|
|
// options for the editor |
443
|
|
|
//required configs |
444
|
|
|
$options['name'] = 'campo_documento'; |
|
|
|
|
445
|
|
|
$options['value'] = empty($_REQUEST['message']) ? '' : $_REQUEST['message']; |
446
|
|
|
//optional configs |
447
|
|
|
$options['rows'] = 25; // default value = 5 |
448
|
|
|
$options['cols'] = 60; // default value = 50 |
449
|
|
|
$options['width'] = '100%'; // default value = 100% |
450
|
|
|
$options['height'] = '400px'; // default value = 400px |
451
|
|
|
|
452
|
|
|
// "textarea": if the selected editor with name of $editor can not be created, the editor "textarea" will be used |
453
|
|
|
// if no $onFailure is set, then the first available editor will be used |
454
|
|
|
// If dohtml is disabled, set $noHtml to true |
455
|
|
|
$campo_documento = new XoopsFormEditor(_AM_ASSESSMENT_DOCUMENTO, $editor, $options, $nohtml = false, $onfailure = 'textarea'); |
456
|
|
|
$botao_enviar = new XoopsFormButton(_AM_ASSESSMENT_CADASTRAR, 'botao_submit', _SUBMIT, 'submit'); |
457
|
|
|
|
458
|
|
|
$form->addElement($campo_codprova); |
459
|
|
|
$form->addElement($campo_titulo, true); |
460
|
|
|
$form->addElement($campo_documento, true); |
461
|
|
|
$form->addElement($campo_fonte, true); |
462
|
|
|
$form->addElement($campo_perguntas, true); |
463
|
|
|
$form->addElement($botao_enviar); |
464
|
|
|
$form->display(); |
465
|
|
|
|
466
|
|
|
return true; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* @param $action |
471
|
|
|
* @param $cod_documento |
472
|
|
|
* |
473
|
|
|
* @return bool |
474
|
|
|
*/ |
475
|
|
|
public function renderFormEditar($action, $cod_documento) |
|
|
|
|
476
|
|
|
{ |
477
|
|
|
global $xoopsDB, $xoopsUser, $xoopsModuleConfig; |
|
|
|
|
478
|
|
|
|
479
|
|
|
$documento = $this->get($cod_documento); |
480
|
|
|
$titulo = $documento->getVar('titulo', 's'); |
481
|
|
|
//$textodocumento = text_filter($documento->getVar('documento',"f"),true); |
|
|
|
|
482
|
|
|
$textodocumento = $documento->getVar('documento', 'f'); |
483
|
|
|
$fonte = $documento->getVar('fonte', 's'); |
484
|
|
|
$uid_elaborador = $documento->getVar('uid_elaborador', 's'); |
|
|
|
|
485
|
|
|
$cod_prova = $documento->getVar('cod_prova', 's'); |
486
|
|
|
$vetor_perguntas_selecionadas = explode(',', $documento->getVar('cods_perguntas', 's')); |
487
|
|
|
|
488
|
|
|
$fabrica_de_perguntas = new Xoopsassessment_perguntasHandler($xoopsDB); |
489
|
|
|
$criteria = new criteria('cod_prova', $cod_prova); |
490
|
|
|
|
491
|
|
|
$vetor_perguntas = $fabrica_de_perguntas->getObjects($criteria); |
492
|
|
|
$campo_perguntas = new XoopsFormSelect('Perguntas associadas', 'campo_perguntas', $vetor_perguntas_selecionadas, 10, true); |
493
|
|
|
|
494
|
|
|
foreach ($vetor_perguntas as $pergunta) { |
495
|
|
|
$campo_perguntas->addOption($pergunta->getVar('cod_pergunta'), $pergunta->getVar('titulo')); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
$form = new XoopsThemeForm(_AM_ASSESSMENT_EDITAR . ' ' . _AM_ASSESSMENT_DOCUMENTO, 'form_documento', $action, 'post', true); |
499
|
|
|
$campo_titulo = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', $titulo, 2, 50); |
500
|
|
|
$campo_fonte = new XoopsFormText(_AM_ASSESSMENT_FONTE, 'campo_fonte', 35, 20, $fonte); |
501
|
|
|
$campo_coddocumento = new XoopsFormHidden('campo_coddocumento', $cod_documento); |
502
|
|
|
$campo_codprova = new XoopsFormHidden('campo_codprova', $cod_prova); |
503
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
504
|
|
|
|
505
|
|
|
$editor = $xoopsModuleConfig['editorpadrao']; |
506
|
|
|
|
507
|
|
|
// Add the editor selection box |
508
|
|
|
// If dohtml is disabled, set $noHtml = true |
509
|
|
|
//$form->addElement(new XoopsFormSelectEditor($form, "editor", $editor, $noHtml = false)); |
|
|
|
|
510
|
|
|
|
511
|
|
|
// options for the editor |
512
|
|
|
//required configs |
513
|
|
|
$options['name'] = 'campo_documento'; |
|
|
|
|
514
|
|
|
$options['value'] = empty($_REQUEST['message']) ? $textodocumento : $_REQUEST['message']; |
515
|
|
|
//optional configs |
516
|
|
|
$options['rows'] = 25; // default value = 5 |
517
|
|
|
$options['cols'] = 60; // default value = 50 |
518
|
|
|
$options['width'] = '100%'; // default value = 100% |
519
|
|
|
$options['height'] = '400px'; // default value = 400px |
520
|
|
|
|
521
|
|
|
// "textarea": if the selected editor with name of $editor can not be created, the editor "textarea" will be used |
522
|
|
|
// if no $onFailure is set, then the first available editor will be used |
523
|
|
|
// If dohtml is disabled, set $noHtml to true |
524
|
|
|
$campo_documento = new XoopsFormEditor(_AM_ASSESSMENT_DOCUMENTO, $editor, $options, $nohtml = false, $onfailure = 'textarea'); |
525
|
|
|
$botao_enviar = new XoopsFormButton(_AM_ASSESSMENT_EDITAR, 'botao_submit', _SUBMIT, 'submit'); |
526
|
|
|
|
527
|
|
|
$form->addElement($campo_coddocumento); |
528
|
|
|
$form->addElement($campo_titulo, true); |
529
|
|
|
$form->addElement($campo_documento, true); |
530
|
|
|
$form->addElement($campo_fonte, true); |
531
|
|
|
$form->addElement($campo_perguntas, true); |
532
|
|
|
$form->addElement($campo_codprova); |
533
|
|
|
$form->addElement($botao_enviar); |
534
|
|
|
$form->display(); |
535
|
|
|
|
536
|
|
|
return true; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* Copia os documentos e salva eles ligados � prova clone |
541
|
|
|
* |
542
|
|
|
* @param object $criteria {@link CriteriaElement} to match |
543
|
|
|
* |
544
|
|
|
* @param $cod_prova |
545
|
|
|
* @return int count of assessment_perguntass |
|
|
|
|
546
|
|
|
*/ |
547
|
|
|
public function clonarDocumentos($criteria, $cod_prova) |
548
|
|
|
{ |
549
|
|
|
global $xoopsDB; |
|
|
|
|
550
|
|
|
|
551
|
|
|
$documentos = $this->getObjects($criteria); |
552
|
|
|
foreach ($documentos as $documento) { |
553
|
|
|
$documento->setVar('cod_prova', $cod_prova); |
554
|
|
|
$documento->setVar('cod_documento', 0); |
555
|
|
|
$documento->setNew(); |
556
|
|
|
$this->insert($documento); |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
} |
560
|
|
|
|
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.