73 $this->isRandomTest = $randomtest;
74 $this->sequencedata = array(
75 "sequence" => array(),
76 "postponed" => array(),
80 $this->alreadyCheckedQuestions = array();
81 $this->newlyCheckedQuestion = null;
91 $newsequence = array();
94 for ($i = 1; $i <= $max; $i++)
96 array_push($newsequence, $i);
100 $this->sequencedata[
"sequence"] = $newsequence;
110 $this->questions = array();
112 $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",
114 array($this->active_id)
119 while ($data = $ilDB->fetchAssoc(
$result))
121 $this->questions[$index++] = $data[
"question_fi"];
139 $result = $ilDB->queryF(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
140 array(
'integer',
'integer'),
141 array($this->active_id, $this->pass)
146 $this->sequencedata = array(
147 "sequence" => unserialize(
$row[
"sequence"]),
148 "postponed" => unserialize(
$row[
"postponed"]),
149 "hidden" => unserialize(
$row[
"hidden"])
151 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] = array();
152 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
153 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
161 $res = $ilDB->queryF(
"SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
162 array(
'integer',
'integer'), array($this->active_id, $this->pass)
165 while(
$row = $ilDB->fetchAssoc(
$res) )
167 $this->alreadyCheckedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
187 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
189 $postponed = serialize($this->sequencedata[
"postponed"]);
192 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
194 $hidden = serialize($this->sequencedata[
"hidden"]);
197 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
198 array(
'integer',
'integer'),
199 array($this->active_id, $this->pass)
202 $affectedRows = $ilDB->insert(
"tst_sequence", array(
203 "active_fi" => array(
"integer", $this->active_id),
204 "pass" => array(
"integer", $this->pass),
205 "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
206 "postponed" => array(
"text", $postponed),
207 "hidden" => array(
"text", $hidden),
208 "tstamp" => array(
"integer", time())
217 if( (
int)$this->newlyCheckedQuestion )
221 $ilDB->replace(
'tst_seq_qst_checked', array(
222 'active_fi' => array(
'integer', (
int)$this->active_id),
223 'pass' => array(
'integer', (
int)$this->pass),
224 'question_fi' => array(
'integer', (
int)$this->newlyCheckedQuestion)
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]));
325 $this->newlyCheckedQuestion = $questionId;
330 return isset($this->alreadyCheckedQuestions[$questionId]);
336 $sequencekey = array_search($sequence, $correctedsequence);
337 if ($sequencekey !== FALSE)
339 return $sequencekey + 1;
354 return array_keys($this->questions);
371 foreach ($seq as $sequence)
380 $correctedsequence = $this->sequencedata[
"sequence"];
381 if (!$with_hidden_questions)
383 if (is_array($this->sequencedata[
"hidden"]))
385 foreach ($this->sequencedata[
"hidden"] as $question_id)
387 $foundsequence = array_search($question_id, $this->questions);
388 if ($foundsequence !== FALSE)
390 $sequencekey = array_search($foundsequence, $correctedsequence);
391 if ($sequencekey !== FALSE)
393 unset($correctedsequence[$sequencekey]);
399 if (is_array($this->sequencedata[
"postponed"]))
401 foreach ($this->sequencedata[
"postponed"] as $question_id)
403 $foundsequence = array_search($question_id, $this->questions);
404 if ($foundsequence !== FALSE)
406 $sequencekey = array_search($foundsequence, $correctedsequence);
407 if ($sequencekey !== FALSE)
409 unset($correctedsequence[$sequencekey]);
410 array_push($correctedsequence, $foundsequence);
415 return array_values($correctedsequence);
420 return array_search($question_id, $this->questions);
426 if (count($correctedsequence))
428 return reset($correctedsequence);
439 if (count($correctedsequence))
441 return end($correctedsequence);
452 $sequencekey = array_search($sequence, $correctedsequence);
453 if ($sequencekey !== FALSE)
455 $nextsequencekey = $sequencekey + 1;
456 if (array_key_exists($nextsequencekey, $correctedsequence))
458 return $correctedsequence[$nextsequencekey];
467 $sequencekey = array_search($sequence, $correctedsequence);
468 if ($sequencekey !== FALSE)
470 $prevsequencekey = $sequencekey - 1;
471 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
473 return $correctedsequence[$prevsequencekey];
489 $keys = array_keys($array);
492 foreach ($keys as $key)
501 if ($sequence < 1)
return FALSE;
502 if (array_key_exists($sequence, $this->questions))
504 return $this->questions[$sequence];
515 $result_array = array();
516 include_once
"./Modules/Test/classes/class.ilObjTest.php";
519 foreach ($correctedsequence as $sequence)
522 if (is_object($question))
524 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
526 if (array_key_exists($question->getId(), $solved_questions))
528 $solved = $solved_questions[$question->getId()][
"solved"];
534 "title" => $question->getTitle(),
535 "qid" => $question->getId(),
536 "visited" => $worked_through,
537 "solved" => (($solved)?
"1":
"0"),
538 "description" => $question->getComment(),
539 "points" => $question->getMaximumPoints(),
540 "worked_through" => $worked_through,
541 "postponed" => $is_postponed,
542 "sequence" => $sequence,
544 'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
547 if( !$obligationsFilter || $row[
'obligatory'] )
549 array_push($result_array, $row);
555 return $result_array;
570 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
582 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
594 $this->sequencedata[
"hidden"] = array();
603 foreach(
$result as $sequence => $question )
605 if( is_numeric($sequence) )
607 if( $question[
'reached'] == $question[
'max'] )
641 return array_values($this->questions);
646 return in_array($questionId, $this->questions);