83 $this->isRandomTest = $randomtest;
84 $this->sequencedata = array(
85 "sequence" => array(),
86 "postponed" => array(),
100 $newsequence = array();
103 for ($i = 1; $i <= $max; $i++)
105 array_push($newsequence, $i);
109 $this->sequencedata[
"sequence"] = $newsequence;
121 $this->questions = array();
122 if ($this->isRandomTest)
124 $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",
125 array(
'integer',
'integer'),
126 array($this->active_id, $this->pass)
134 $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",
136 array($this->active_id)
142 $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",
144 array($this->active_id)
150 $this->questions[$index++] =
$data[
"question_fi"];
163 $result = $ilDB->queryF(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
164 array(
'integer',
'integer'),
165 array($this->active_id, $this->pass)
170 $this->sequencedata = array(
171 "sequence" => unserialize(
$row[
"sequence"]),
172 "postponed" => unserialize(
$row[
"postponed"]),
173 "hidden" => unserialize(
$row[
"hidden"])
175 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] = array();
176 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
177 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
191 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
193 $postponed = serialize($this->sequencedata[
"postponed"]);
196 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
198 $hidden = serialize($this->sequencedata[
"hidden"]);
201 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
202 array(
'integer',
'integer'),
203 array($this->active_id, $this->pass)
206 $affectedRows = $ilDB->insert(
"tst_sequence", array(
207 "active_fi" => array(
"integer", $this->active_id),
208 "pass" => array(
"integer", $this->pass),
209 "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
210 "postponed" => array(
"text", $postponed),
211 "hidden" => array(
"text", $hidden),
212 "tstamp" => array(
"integer", time())
220 array_push($this->sequencedata[
"postponed"], intval($question_id));
228 array_push($this->sequencedata[
"hidden"], intval($question_id));
234 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
235 if (!in_array($question_id, $this->sequencedata[
"postponed"]))
247 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
248 if (!in_array($question_id, $this->sequencedata[
"hidden"]))
260 if (!array_key_exists($sequence, $this->questions))
return FALSE;
261 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
262 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"]))
274 if (!array_key_exists($sequence, $this->questions))
return FALSE;
275 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
276 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"]))
290 if (array_key_exists($sequence, $this->questions))
292 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
293 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
302 if (array_key_exists($sequence, $this->questions))
304 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
305 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
313 $sequencekey = array_search($sequence, $correctedsequence);
314 if ($sequencekey !== FALSE)
316 return $sequencekey + 1;
331 return array_keys($this->questions);
348 foreach ($seq as $sequence)
357 $correctedsequence = $this->sequencedata[
"sequence"];
358 if (!$with_hidden_questions)
360 if (is_array($this->sequencedata[
"hidden"]))
362 foreach ($this->sequencedata[
"hidden"] as $question_id)
364 $foundsequence = array_search($question_id, $this->questions);
365 if ($foundsequence !== FALSE)
367 $sequencekey = array_search($foundsequence, $correctedsequence);
368 if ($sequencekey !== FALSE)
370 unset($correctedsequence[$sequencekey]);
376 if (is_array($this->sequencedata[
"postponed"]))
378 foreach ($this->sequencedata[
"postponed"] as $question_id)
380 $foundsequence = array_search($question_id, $this->questions);
381 if ($foundsequence !== FALSE)
383 $sequencekey = array_search($foundsequence, $correctedsequence);
384 if ($sequencekey !== FALSE)
386 unset($correctedsequence[$sequencekey]);
387 array_push($correctedsequence, $foundsequence);
392 return array_values($correctedsequence);
397 return array_search($question_id, $this->questions);
403 if (count($correctedsequence))
405 return reset($correctedsequence);
416 if (count($correctedsequence))
418 return end($correctedsequence);
429 $sequencekey = array_search($sequence, $correctedsequence);
430 if ($sequencekey !== FALSE)
432 $nextsequencekey = $sequencekey + 1;
433 if (array_key_exists($nextsequencekey, $correctedsequence))
435 return $correctedsequence[$nextsequencekey];
444 $sequencekey = array_search($sequence, $correctedsequence);
445 if ($sequencekey !== FALSE)
447 $prevsequencekey = $sequencekey - 1;
448 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
450 return $correctedsequence[$prevsequencekey];
466 $keys = array_keys($array);
469 foreach ($keys as $key)
478 if ($sequence < 1)
return FALSE;
479 if (array_key_exists($sequence, $this->questions))
481 return $this->questions[$sequence];
492 $result_array = array();
493 include_once
"./Modules/Test/classes/class.ilObjTest.php";
496 foreach ($correctedsequence as $sequence)
499 if (is_object($question))
501 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
503 if (array_key_exists($question->getId(), $solved_questions))
505 $solved = $solved_questions[$question->getId()][
"solved"];
511 "title" => $question->getTitle(),
512 "qid" => $question->getId(),
513 "visited" => $worked_through,
514 "solved" => (($solved)?
"1":
"0"),
515 "description" => $question->getComment(),
516 "points" => $question->getMaximumPoints(),
517 "worked_through" => $worked_through,
518 "postponed" => $is_postponed,
519 "sequence" => $sequence
521 array_push($result_array, $row);
525 return $result_array;
540 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
552 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
564 $this->sequencedata[
"hidden"] = array();