63 $this->isRandomTest = $randomtest;
64 $this->sequencedata = array(
65 "sequence" => array(),
66 "postponed" => array(),
78 $newsequence = array();
81 for ($i = 1; $i <= $max; $i++)
83 array_push($newsequence, $i);
87 $this->sequencedata[
"sequence"] = $newsequence;
97 $this->questions = array();
98 if ($this->isRandomTest)
100 $result = $ilDB->queryF(
"SELECT tst_test_rnd_qst.* FROM tst_test_rnd_qst, qpl_questions WHERE tst_test_rnd_qst.active_fi = %s AND qpl_questions.question_id = tst_test_rnd_qst.question_fi AND tst_test_rnd_qst.pass = %s ORDER BY sequence",
101 array(
'integer',
'integer'),
102 array($this->active_id, $this->pass)
110 $result = $ilDB->queryF(
"SELECT tst_test_rnd_qst.* FROM tst_test_rnd_qst, qpl_questions WHERE tst_test_rnd_qst.active_fi = %s AND qpl_questions.question_id = tst_test_rnd_qst.question_fi AND tst_test_rnd_qst.pass = 0 ORDER BY sequence",
112 array($this->active_id)
118 $result = $ilDB->queryF(
"SELECT tst_test_question.* FROM tst_test_question, qpl_questions, tst_active WHERE tst_active.active_id = %s AND tst_test_question.test_fi = tst_active.test_fi AND qpl_questions.question_id = tst_test_question.question_fi ORDER BY tst_test_question.sequence",
120 array($this->active_id)
124 while ($data = $ilDB->fetchAssoc(
$result))
126 $this->questions[$index++] = $data[
"question_fi"];
138 $result = $ilDB->queryF(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
139 array(
'integer',
'integer'),
140 array($this->active_id, $this->pass)
145 $this->sequencedata = array(
146 "sequence" => unserialize(
$row[
"sequence"]),
147 "postponed" => unserialize(
$row[
"postponed"]),
148 "hidden" => unserialize(
$row[
"hidden"])
150 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] = array();
151 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
152 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
166 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
168 $postponed = serialize($this->sequencedata[
"postponed"]);
171 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
173 $hidden = serialize($this->sequencedata[
"hidden"]);
176 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
177 array(
'integer',
'integer'),
178 array($this->active_id, $this->pass)
181 $affectedRows = $ilDB->insert(
"tst_sequence", array(
182 "active_fi" => array(
"integer", $this->active_id),
183 "pass" => array(
"integer", $this->pass),
184 "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
185 "postponed" => array(
"text", $postponed),
186 "hidden" => array(
"text", $hidden),
187 "tstamp" => array(
"integer", time())
195 array_push($this->sequencedata[
"postponed"], intval($question_id));
203 array_push($this->sequencedata[
"hidden"], intval($question_id));
209 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
210 if (!in_array($question_id, $this->sequencedata[
"postponed"]))
222 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
223 if (!in_array($question_id, $this->sequencedata[
"hidden"]))
235 if (!array_key_exists($sequence, $this->questions))
return FALSE;
236 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
237 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"]))
249 if (!array_key_exists($sequence, $this->questions))
return FALSE;
250 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
251 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"]))
265 if (array_key_exists($sequence, $this->questions))
267 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
268 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
277 if (array_key_exists($sequence, $this->questions))
279 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
280 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
288 $sequencekey = array_search($sequence, $correctedsequence);
289 if ($sequencekey !== FALSE)
291 return $sequencekey + 1;
306 return array_keys($this->questions);
323 foreach ($seq as $sequence)
332 $correctedsequence = $this->sequencedata[
"sequence"];
333 if (!$with_hidden_questions)
335 if (is_array($this->sequencedata[
"hidden"]))
337 foreach ($this->sequencedata[
"hidden"] as $question_id)
339 $foundsequence = array_search($question_id, $this->questions);
340 if ($foundsequence !== FALSE)
342 $sequencekey = array_search($foundsequence, $correctedsequence);
343 if ($sequencekey !== FALSE)
345 unset($correctedsequence[$sequencekey]);
351 if (is_array($this->sequencedata[
"postponed"]))
353 foreach ($this->sequencedata[
"postponed"] as $question_id)
355 $foundsequence = array_search($question_id, $this->questions);
356 if ($foundsequence !== FALSE)
358 $sequencekey = array_search($foundsequence, $correctedsequence);
359 if ($sequencekey !== FALSE)
361 unset($correctedsequence[$sequencekey]);
362 array_push($correctedsequence, $foundsequence);
367 return array_values($correctedsequence);
372 return array_search($question_id, $this->questions);
378 if (count($correctedsequence))
380 return reset($correctedsequence);
391 if (count($correctedsequence))
393 return end($correctedsequence);
404 $sequencekey = array_search($sequence, $correctedsequence);
405 if ($sequencekey !== FALSE)
407 $nextsequencekey = $sequencekey + 1;
408 if (array_key_exists($nextsequencekey, $correctedsequence))
410 return $correctedsequence[$nextsequencekey];
419 $sequencekey = array_search($sequence, $correctedsequence);
420 if ($sequencekey !== FALSE)
422 $prevsequencekey = $sequencekey - 1;
423 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
425 return $correctedsequence[$prevsequencekey];
441 $keys = array_keys($array);
444 foreach ($keys as $key)
453 if ($sequence < 1)
return FALSE;
454 if (array_key_exists($sequence, $this->questions))
456 return $this->questions[$sequence];
467 $result_array = array();
468 include_once
"./Modules/Test/classes/class.ilObjTest.php";
471 foreach ($correctedsequence as $sequence)
474 if (is_object($question))
476 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
478 if (array_key_exists($question->getId(), $solved_questions))
480 $solved = $solved_questions[$question->getId()][
"solved"];
486 "title" => $question->getTitle(),
487 "qid" => $question->getId(),
488 "visited" => $worked_through,
489 "solved" => (($solved)?
"1":
"0"),
490 "description" => $question->getComment(),
491 "points" => $question->getMaximumPoints(),
492 "worked_through" => $worked_through,
493 "postponed" => $is_postponed,
494 "sequence" => $sequence,
496 'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
499 if( !$obligationsFilter || $row[
'obligatory'] )
501 array_push($result_array, $row);
507 return $result_array;
522 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
534 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
546 $this->sequencedata[
"hidden"] = array();
555 foreach(
$result as $sequence => $question )
557 if( is_numeric($sequence) )
559 if( $question[
'reached'] == $question[
'max'] )
593 return in_array($questionId, $this->questions);