4 require_once
'Modules/Test/interfaces/interface.ilTestQuestionSequence.php';
5 require_once
'Modules/Test/interfaces/interface.ilTestSequenceSummaryProvider.php';
96 $this->isRandomTest = $randomtest;
97 $this->sequencedata = array(
98 "sequence" => array(),
99 "postponed" => array(),
103 $this->alreadyCheckedQuestions = array();
104 $this->newlyCheckedQuestion = null;
106 $this->optionalQuestions = array();
107 $this->answeringOptionalQuestionsConfirmed =
false;
109 $this->considerHiddenQuestionsEnabled =
false;
110 $this->considerOptionalQuestionsEnabled =
true;
120 $newsequence = array();
123 for ($i = 1; $i <= $max; $i++)
125 array_push($newsequence, $i);
129 $this->sequencedata[
"sequence"] = $newsequence;
139 $this->questions = array();
141 $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",
143 array($this->active_id)
150 $this->questions[$index++] =
$data[
"question_fi"];
169 $result = $ilDB->queryF(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
170 array(
'integer',
'integer'),
171 array($this->active_id, $this->pass)
176 $this->sequencedata = array(
177 "sequence" => unserialize(
$row[
"sequence"]),
178 "postponed" => unserialize(
$row[
"postponed"]),
179 "hidden" => unserialize(
$row[
"hidden"])
181 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] = array();
182 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
183 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
193 $res = $ilDB->queryF(
"SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
194 array(
'integer',
'integer'), array($this->active_id, $this->pass)
197 while(
$row = $ilDB->fetchAssoc(
$res) )
199 $this->alreadyCheckedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
207 $res = $ilDB->queryF(
"SELECT question_fi FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s",
208 array(
'integer',
'integer'), array($this->active_id, $this->pass)
211 while(
$row = $ilDB->fetchAssoc(
$res) )
213 $this->optionalQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
234 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
236 $postponed = serialize($this->sequencedata[
"postponed"]);
239 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
241 $hidden = serialize($this->sequencedata[
"hidden"]);
244 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
245 array(
'integer',
'integer'),
246 array($this->active_id, $this->pass)
249 $affectedRows = $ilDB->insert(
"tst_sequence", array(
250 "active_fi" => array(
"integer", $this->active_id),
251 "pass" => array(
"integer", $this->pass),
252 "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
253 "postponed" => array(
"text", $postponed),
254 "hidden" => array(
"text", $hidden),
255 "tstamp" => array(
"integer", time()),
265 if( (
int)$this->newlyCheckedQuestion )
269 $ilDB->replace(
'tst_seq_qst_checked', array(
270 'active_fi' => array(
'integer', (
int)$this->active_id),
271 'pass' => array(
'integer', (
int)$this->pass),
272 'question_fi' => array(
'integer', (
int)$this->newlyCheckedQuestion)
284 $NOT_IN_questions = $ilDB->in(
'question_fi', $this->optionalQuestions,
true,
'integer');
287 "DELETE FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s AND $NOT_IN_questions",
288 array(
'integer',
'integer'), array($this->active_id, $this->pass)
291 foreach($this->optionalQuestions as $questionId)
293 $ilDB->replace(
'tst_seq_qst_optional', array(
294 'active_fi' => array(
'integer', (
int)$this->active_id),
295 'pass' => array(
'integer', (
int)$this->pass),
296 'question_fi' => array(
'integer', (
int)$questionId)
305 array_push($this->sequencedata[
"postponed"], intval($question_id));
313 array_push($this->sequencedata[
"hidden"], intval($question_id));
319 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
320 if (!in_array($question_id, $this->sequencedata[
"postponed"]))
332 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
333 if (!in_array($question_id, $this->sequencedata[
"hidden"]))
345 if (!array_key_exists($sequence, $this->questions))
return FALSE;
346 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
347 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"]))
359 if (!array_key_exists($sequence, $this->questions))
return FALSE;
360 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
361 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"]))
375 if (array_key_exists($sequence, $this->questions))
377 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] = array();
378 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
387 if (array_key_exists($sequence, $this->questions))
389 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] = array();
390 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
397 $this->newlyCheckedQuestion = $questionId;
402 return isset($this->alreadyCheckedQuestions[$questionId]);
408 $sequencekey = array_search($sequence, $correctedsequence);
409 if ($sequencekey !== FALSE)
411 return $sequencekey + 1;
426 $sequenceKeys = array();
428 foreach(array_keys($this->questions) as $sequenceKey)
440 $sequenceKeys[] = $sequenceKey;
443 return $sequenceKeys;
448 $questions = array();
450 foreach($this->questions as $questionId)
462 $questions[] = $questionId;
477 foreach ($seq as $sequence)
486 $questionKey = array_search($questionId, $this->questions);
488 if( $questionKey ===
false )
493 $sequenceKey = array_search($questionKey, $sequence);
495 if( $sequenceKey === FALSE )
500 unset($sequence[$sequenceKey]);
507 $correctedsequence = $this->sequencedata[
"sequence"];
510 if (is_array($this->sequencedata[
"hidden"]))
512 foreach ($this->sequencedata[
"hidden"] as $question_id)
520 foreach($this->optionalQuestions as $questionId)
525 if (is_array($this->sequencedata[
"postponed"]))
527 foreach ($this->sequencedata[
"postponed"] as $question_id)
529 $foundsequence = array_search($question_id, $this->questions);
530 if ($foundsequence !== FALSE)
532 $sequencekey = array_search($foundsequence, $correctedsequence);
533 if ($sequencekey !== FALSE)
535 unset($correctedsequence[$sequencekey]);
536 array_push($correctedsequence, $foundsequence);
541 return array_values($correctedsequence);
546 return array_search($question_id, $this->questions);
552 if (count($correctedsequence))
554 return reset($correctedsequence);
565 if (count($correctedsequence))
567 return end($correctedsequence);
578 $sequencekey = array_search($sequence, $correctedsequence);
579 if ($sequencekey !== FALSE)
581 $nextsequencekey = $sequencekey + 1;
582 if (array_key_exists($nextsequencekey, $correctedsequence))
584 return $correctedsequence[$nextsequencekey];
593 $sequencekey = array_search($sequence, $correctedsequence);
594 if ($sequencekey !== FALSE)
596 $prevsequencekey = $sequencekey - 1;
597 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
599 return $correctedsequence[$prevsequencekey];
615 $keys = array_keys($array);
618 foreach ($keys as $key)
627 if ($sequence < 1)
return FALSE;
628 if (array_key_exists($sequence, $this->questions))
630 return $this->questions[$sequence];
641 $result_array = array();
642 include_once
"./Modules/Test/classes/class.ilObjTest.php";
645 foreach ($correctedsequence as $sequence)
648 if (is_object($question))
650 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
652 if (array_key_exists($question->getId(), $solved_questions))
654 $solved = $solved_questions[$question->getId()][
"solved"];
660 "title" => $question->getTitle(),
661 "qid" => $question->getId(),
662 "visited" => $worked_through,
663 "solved" => (($solved)?
"1":
"0"),
664 "description" => $question->getComment(),
665 "points" => $question->getMaximumPoints(),
666 "worked_through" => $worked_through,
667 "postponed" => $is_postponed,
668 "sequence" => $sequence,
670 'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
673 if( !$obligationsFilter || $row[
'obligatory'] )
675 array_push($result_array, $row);
681 return $result_array;
696 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
708 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
720 $this->sequencedata[
"hidden"] = array();
729 foreach(
$result as $sequence => $question )
731 if( is_numeric($sequence) )
733 if( $question[
'reached'] == $question[
'max'] )
767 return array_values($this->questions);
772 return in_array($questionId, $this->questions);
777 $this->optionalQuestions[$questionId] = $questionId;
782 return isset($this->optionalQuestions[$questionId]);
787 return (
bool)count($this->optionalQuestions);
797 $this->optionalQuestions = array();
802 $optionalSequenceKeys = array();
804 foreach($this->sequencedata[
'sequence'] as $index => $sequenceKey)
808 $optionalSequenceKeys[$index] = $sequenceKey;
809 unset($this->sequencedata[
'sequence'][$index]);
813 foreach($optionalSequenceKeys as $index => $sequenceKey)
815 $this->sequencedata[
'sequence'][$index] = $sequenceKey;
loadFromDb()
Loads the sequence data for a given active id.
isPostponedQuestion($question_id)
loadQuestions(ilTestQuestionSetConfig $testQuestionSetConfig=null, $taxonomyFilterSelection=array())
Loads the question mapping.
getNextSequence($sequence)
setConsiderHiddenQuestionsEnabled($considerHiddenQuestionsEnabled)
isConsiderOptionalQuestionsEnabled()
getSequenceForQuestion($question_id)
isQuestionChecked($questionId)
isQuestionOptional($questionId)
& _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
setAnsweringOptionalQuestionsConfirmed($answeringOptionalQuestionsConfirmed)
_getSolvedQuestions($active_id, $question_fi=null)
get solved questions
ilTestSequence($active_id, $pass, $randomtest)
ilTestSequence constructor
hideQuestion($question_id)
postponeQuestion($question_id)
getQuestionForSequence($sequence)
getUserSequenceQuestions()
getPositionOfSequence($sequence)
static isQuestionObligatory($question_id)
checks wether the question with given id is marked as obligatory or not
saveToDb()
Saves the sequence data for a given pass to the database.
saveOptionalQuestions()
ilDB $ilDB
setConsiderOptionalQuestionsEnabled($considerOptionalQuestionsEnabled)
hasStarted(ilTestSession $testSession)
$answeringOptionalQuestionsConfirmed
isConsiderHiddenQuestionsEnabled()
postponeSequence($sequence)
$considerHiddenQuestionsEnabled
getOrderedSequenceQuestions()
getPreviousSequence($sequence)
reorderOptionalQuestionsToSequenceEnd()
isHiddenQuestion($question_id)
createNewSequence($max, $shuffle)
setQuestionOptional($questionId)
isHiddenSequence($sequence)
questionExists($questionId)
saveNewlyCheckedQuestion()
ilDB $ilDB
isPostponedSequence($sequence)
setQuestionChecked($questionId)
hideCorrectAnsweredQuestions(ilObjTest $testOBJ, $activeId, $pass)
isAnsweringOptionalQuestionsConfirmed()
ensureQuestionNotInSequence($sequence, $questionId)
getSequenceSummary($obligationsFilterEnabled=false)
pcArrayShuffle($array)
Shuffles the values of a given array.
& getTestResult($active_id, $pass=NULL, $ordered_sequence=FALSE, $considerHiddenQuestions=true, $considerOptionalQuestions=true)
Calculates the results of a test for a given user and returns an array with all test results...
$considerOptionalQuestionsEnabled