93 $this->isRandomTest = $randomtest;
94 $this->sequencedata = array(
95 "sequence" => array(),
96 "postponed" => array(),
110 $newsequence = array();
113 for ($i = 1; $i <= $max; $i++)
115 array_push($newsequence, $i);
119 $this->sequencedata[
"sequence"] = $newsequence;
133 $this->questions = array();
134 if ($this->isRandomTest)
136 $query = sprintf(
"SELECT tst_test_random_question.* FROM tst_test_random_question, qpl_questions WHERE tst_test_random_question.active_fi = %s AND qpl_questions.question_id = tst_test_random_question.question_fi AND tst_test_random_question.pass = %s ORDER BY sequence",
137 $ilDB->quote($this->active_id .
""),
138 $ilDB->quote($this->pass .
"")
140 $result = $ilDB->query($query);
145 if ($result->numRows() == 0)
147 $query = sprintf(
"SELECT tst_test_random_question.* FROM tst_test_random_question, qpl_questions WHERE tst_test_random_question.active_fi = %s AND qpl_questions.question_id = tst_test_random_question.question_fi AND tst_test_random_question.pass = 0 ORDER BY sequence",
148 $ilDB->quote($this->active_id .
"")
150 $result = $ilDB->query($query);
155 $query = sprintf(
"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",
156 $ilDB->quote($this->active_id .
"")
158 $result = $ilDB->query($query);
163 $this->questions[$index++] =
$data[
"question_fi"];
178 $query = sprintf(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
179 $ilDB->quote($this->active_id .
""),
180 $ilDB->quote($this->pass .
"")
182 $result = $ilDB->query($query);
183 if ($result->numRows())
185 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
186 $this->sequencedata = array(
187 "sequence" => unserialize($row[
"sequence"]),
188 "postponed" => unserialize($row[
"postponed"]),
189 "hidden" => unserialize($row[
"hidden"])
191 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] = array();
192 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
193 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
209 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
211 $postponed = $ilDB->quote(serialize($this->sequencedata[
"postponed"]));
214 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
216 $hidden = $ilDB->quote(serialize($this->sequencedata[
"hidden"]));
219 $query = sprintf(
"REPLACE INTO tst_sequence (active_fi, pass, sequence, postponed, hidden) VALUES (%s, %s, %s, %s, %s)",
220 $ilDB->quote($this->active_id .
""),
221 $ilDB->quote($this->pass .
""),
222 $ilDB->quote(serialize($this->sequencedata[
"sequence"])),
226 $result = $ilDB->query($query);
233 array_push($this->sequencedata[
"postponed"], intval($question_id));
241 array_push($this->sequencedata[
"hidden"], intval($question_id));
247 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
248 if (!in_array($question_id, $this->sequencedata[
"postponed"]))
260 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
261 if (!in_array($question_id, $this->sequencedata[
"hidden"]))
273 if (!array_key_exists($sequence, $this->questions))
return FALSE;
274 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
275 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"]))
287 if (!array_key_exists($sequence, $this->questions))
return FALSE;
288 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
289 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"]))
303 if (array_key_exists($sequence, $this->questions))
305 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
306 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
315 if (array_key_exists($sequence, $this->questions))
317 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
318 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
326 $sequencekey = array_search($sequence, $correctedsequence);
327 if ($sequencekey !== FALSE)
329 return $sequencekey + 1;
344 return array_keys($this->questions);
354 $correctedsequence = $this->sequencedata[
"sequence"];
355 if (!$with_hidden_questions)
357 if (is_array($this->sequencedata[
"hidden"]))
359 foreach ($this->sequencedata[
"hidden"] as $question_id)
361 $foundsequence = array_search($question_id, $this->questions);
362 if ($foundsequence !== FALSE)
364 $sequencekey = array_search($foundsequence, $correctedsequence);
365 if ($sequencekey !== FALSE)
367 unset($correctedsequence[$sequencekey]);
373 if (is_array($this->sequencedata[
"postponed"]))
375 foreach ($this->sequencedata[
"postponed"] as $question_id)
377 $foundsequence = array_search($question_id, $this->questions);
378 if ($foundsequence !== FALSE)
380 $sequencekey = array_search($foundsequence, $correctedsequence);
381 if ($sequencekey !== FALSE)
383 unset($correctedsequence[$sequencekey]);
384 array_push($correctedsequence, $foundsequence);
389 return array_values($correctedsequence);
394 return array_search($question_id, $this->questions);
400 if (count($correctedsequence))
402 return reset($correctedsequence);
413 if (count($correctedsequence))
415 return end($correctedsequence);
426 $sequencekey = array_search($sequence, $correctedsequence);
427 if ($sequencekey !== FALSE)
429 $nextsequencekey = $sequencekey + 1;
430 if (array_key_exists($nextsequencekey, $correctedsequence))
432 return $correctedsequence[$nextsequencekey];
441 $sequencekey = array_search($sequence, $correctedsequence);
442 if ($sequencekey !== FALSE)
444 $prevsequencekey = $sequencekey - 1;
445 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
447 return $correctedsequence[$prevsequencekey];
463 mt_srand((
double)microtime()*1000000);
474 $array[$j] = $array[$i];
484 if ($sequence < 1)
return FALSE;
485 if (array_key_exists($sequence, $this->questions))
487 return $this->questions[$sequence];
498 $result_array = array();
499 include_once
"./Modules/Test/classes/class.ilObjTest.php";
502 foreach ($correctedsequence as $sequence)
505 if (is_object($question))
507 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
509 if (array_key_exists($question->getId(), $solved_questions))
511 $solved = $solved_questions[$question->getId()]->solved;
517 "title" => $question->getTitle(),
518 "qid" => $question->getId(),
519 "visited" => $worked_through,
520 "solved" => (($solved)?
"1":
"0"),
521 "description" => $question->getComment(),
522 "points" => $question->getMaximumPoints(),
523 "worked_through" => $worked_through,
524 "postponed" => $is_postponed,
525 "sequence" => $sequence
527 array_push($result_array, $row);
531 return $result_array;
546 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
558 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
570 $this->sequencedata[
"hidden"] = array();