ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLORandomTestQuestionPools.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
6
16{
17 protected $container_id = 0;
18 protected $objective_id = 0;
19 protected $test_type = 0;
20 protected $test_id = 0;
21 protected $qpl_seq = 0;
22 protected $limit = 50;
23
24
30 public function __construct($a_container_id, $a_objective_id, $a_test_type, $a_qpl_sequence)
31 {
32 $this->container_id = $a_container_id;
33 $this->objective_id = $a_objective_id;
34 $this->test_type = $a_test_type;
35 $this->qpl_seq = $a_qpl_sequence;
36
37 $this->read();
38 }
39
48 public static function lookupLimit($a_container_id, $a_objective_id, $a_test_type)
49 {
50 global $ilDB;
51
52 $query = 'SELECT * FROM loc_rnd_qpl ' .
53 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
54 'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
55 'AND tst_type = ' . $ilDB->quote($a_test_type, 'integer');
56 $res = $ilDB->query($query);
57 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
58 return $row->percentage;
59 }
60 return 0;
61 }
62
71 public static function lookupSequences($a_container_id, $a_objective_id, $a_test_id)
72 {
73 global $ilDB;
74
75 $query = 'SELECT * FROM loc_rnd_qpl ' .
76 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
77 'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
78 'AND tst_id = ' . $ilDB->quote($a_test_id, 'integer');
79
80 $res = $ilDB->query($query);
81 $sequences = [];
82 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
83 $sequences[] = $row->qp_seq;
84 }
85 return (array) $sequences;
86 }
87
97 public static function lookupSequencesByType($a_container_id, $a_objective_id, $a_test_id, $a_test_type)
98 {
99 global $ilDB;
100
101 $query = 'SELECT * FROM loc_rnd_qpl ' .
102 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
103 'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
104 'AND tst_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ' .
105 'AND tst_type = ' . $ilDB->quote($a_test_type, 'integer');
106
107 $res = $ilDB->query($query);
108 $sequences = [];
109 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
110 $sequences[] = $row->qp_seq;
111 }
112 return (array) $sequences;
113 }
114
115
123 public static function lookupObjectiveIdsBySequence($a_container_id, $a_seq_id)
124 {
125 global $ilDB;
126
127 $query = 'SELECT objective_id FROM loc_rnd_qpl ' .
128 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
129 'AND qp_seq = ' . $ilDB->quote($a_seq_id, 'integer');
130 $res = $ilDB->query($query);
131 $objectiveIds = array();
132 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
133 $objectiveIds[] = $row->objective_id;
134 }
135 return $objectiveIds;
136 }
137
138
139 public function setContainerId($a_id)
140 {
141 $this->container_id = $a_id;
142 }
143
144 public function getContainerId()
145 {
146 return $this->container_id;
147 }
148
149 public function setObjectiveId($a_id)
150 {
151 $this->objective_id = $a_id;
152 }
153
154 public function getObjectiveId()
155 {
156 return $this->objective_id;
157 }
158
159 public function setTestType($a_type)
160 {
161 $this->test_type = $a_type;
162 }
163
164 public function getTestType()
165 {
166 return $this->test_type;
167 }
168
169 public function setTestId($a_id)
170 {
171 $this->test_id = $a_id;
172 }
173
174 public function getTestId()
175 {
176 return $this->test_id;
177 }
178
179 public function setQplSequence($a_id)
180 {
181 $this->qpl_seq = $a_id;
182 }
183
184 public function getQplSequence()
185 {
186 return $this->qpl_seq;
187 }
188
189 public function setLimit($a_id)
190 {
191 $this->limit = $a_id;
192 }
193
194 public function getLimit()
195 {
196 return $this->limit;
197 }
198
204 public function copy($a_copy_id, $a_new_course_id, $a_new_objective_id)
205 {
206 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
208 $mappings = $options->getMappings();
209
210 foreach (self::lookupSequences($this->getContainerId(), $this->getContainerId(), $this->getTestId()) as $sequence) {
211 // not nice
212 $this->setQplSequence($sequence);
213 $this->read();
214
215
216 $mapped_id = 0;
217 $test_ref_id = 0;
218 foreach ((array) ilObject::_getAllReferences($this->getTestId()) as $tmp => $ref_id) {
219 $test_ref_id = $ref_id;
220 $mapped_id = $mappings[$ref_id];
221 if ($mapped_id) {
222 continue;
223 }
224 }
225 if (!$mapped_id) {
226 ilLoggerFactory::getLogger('crs')->debug('No test mapping found for random question pool assignment: ' . $this->getTestId() . ' ' . $sequence);
227 continue;
228 }
229
230 // Mapping for sequence
231 $new_question_info = $mappings[$test_ref_id . '_rndSelDef_' . $this->getQplSequence()];
232 $new_question_arr = explode('_', $new_question_info);
233 if (!isset($new_question_arr[2]) or !$new_question_arr[2]) {
234 //ilLoggerFactory::getLogger('crs')->debug(print_r($mappings,TRUE));
235 ilLoggerFactory::getLogger('crs')->debug('Found invalid or no mapping format of random question id mapping: ' . print_r($new_question_arr, true));
236 continue;
237 }
238
239 $new_ass = new self(
240 $a_new_course_id,
241 $a_new_objective_id,
242 $this->getTestType(),
243 $new_question_arr[2]
244 );
245 $new_ass->setTestId($mapped_id);
246 $new_ass->setLimit($this->getLimit());
247 $new_ass->create();
248 }
249 }
250
251
257 public function read()
258 {
259 global $ilDB;
260
261 $query = 'SELECT * FROM loc_rnd_qpl ' .
262 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer') . ' ' .
263 'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
264 'AND tst_type = ' . $ilDB->quote($this->getTestType(), 'integer') . ' ' .
265 'AND qp_seq = ' . $ilDB->quote($this->getQplSequence(), 'integer');
266
267 $res = $ilDB->query($query);
268 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
269 $this->setLimit($row->percentage);
270 $this->setTestId($row->tst_id);
271 }
272 return true;
273 }
274
275 public function delete()
276 {
277 global $ilDB;
278
279 $query = 'DELETE FROM loc_rnd_qpl ' .
280 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer') . ' ' .
281 'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ' .
282 'AND tst_type = ' . $ilDB->quote($this->getTestType(), 'integer') . ' ' .
283 'AND qp_seq = ' . $ilDB->quote($this->getQplSequence(), 'integer');
284 $ilDB->manipulate($query);
285 }
286
293 public function deleteForObjectiveAndTestType($a_course_id, $a_objective_id, $a_tst_type)
294 {
295 $db = $GLOBALS['DIC']->database();
296
297 $query = 'DELETE FROM loc_rnd_qpl ' .
298 'WHERE container_id = ' . $db->quote($a_course_id, 'integer') . ' ' .
299 'AND objective_id = ' . $db->quote($a_objective_id, 'integer') . ' ' .
300 'AND tst_type = ' . $db->quote($a_tst_type, 'integer');
301 $db->manipulate($query);
302 }
303
304 public function create()
305 {
306 global $ilDB;
307
308 $query = 'INSERT INTO loc_rnd_qpl ' .
309 '(container_id, objective_id, tst_type, tst_id, qp_seq, percentage) ' .
310 'VALUES ( ' .
311 $ilDB->quote($this->getContainerId(), 'integer') . ', ' .
312 $ilDB->quote($this->getObjectiveId(), 'integer') . ', ' .
313 $ilDB->quote($this->getTestType(), 'integer') . ', ' .
314 $ilDB->quote($this->getTestId(), 'integer') . ', ' .
315 $ilDB->quote($this->getQplSequence(), 'integer') . ', ' .
316 $ilDB->quote($this->getLimit()) . ' ' .
317 ')';
318 $ilDB->manipulate($query);
319 }
320
321 // begin-patch optes_lok_export
322 public static function toXml(ilXmlWriter $writer, $a_objective_id)
323 {
324 global $ilDB;
325
326 $query = 'SELECT * FROM loc_rnd_qpl ' .
327 'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer');
328 $res = $ilDB->query($query);
329 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
330 include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
331 $writer->xmlElement(
332 'Test',
333 array(
335 'objId' => $row->tst_id,
336 'testType' => $row->tst_type,
337 'limit' => $row->percentage,
338 'poolId' => $row->qp_seq
339 )
340 );
341 }
342 }
343 // end-patch optes_lok_export
344}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static lookupSequencesByType($a_container_id, $a_objective_id, $a_test_id, $a_test_type)
Lookup sequence ids @global type $ilDB.
deleteForObjectiveAndTestType($a_course_id, $a_objective_id, $a_tst_type)
Delete assignment for objective id and test type.
static lookupLimit($a_container_id, $a_objective_id, $a_test_type)
lookup limit @global type $ilDB
static toXml(ilXmlWriter $writer, $a_objective_id)
__construct($a_container_id, $a_objective_id, $a_test_type, $a_qpl_sequence)
Constructor.
static lookupSequences($a_container_id, $a_objective_id, $a_test_id)
Lookup sequence ids @global type $ilDB.
static lookupObjectiveIdsBySequence($a_container_id, $a_seq_id)
Lookup objective ids by sequence_id @global type $ilDB.
read()
read settings @global type $ilDB
copy($a_copy_id, $a_new_course_id, $a_new_objective_id)
Copy assignment.
static getLogger($a_component_id)
Get component logger.
static _getAllReferences($a_id)
get all reference ids of object
XML writer class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92