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)
151 $this->questions[$index++] =
$data[
"question_fi"];
170 $result = $ilDB->queryF(
"SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
171 array(
'integer',
'integer'),
172 array($this->active_id, $this->pass)
177 $this->sequencedata =
array(
178 "sequence" => unserialize(
$row[
"sequence"]),
179 "postponed" => unserialize(
$row[
"postponed"]),
180 "hidden" => unserialize(
$row[
"hidden"])
182 if (!is_array($this->sequencedata[
"sequence"])) $this->sequencedata[
"sequence"] =
array();
183 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] =
array();
184 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] =
array();
194 $res = $ilDB->queryF(
"SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
195 array(
'integer',
'integer'),
array($this->active_id, $this->pass)
198 while(
$row = $ilDB->fetchAssoc(
$res) )
200 $this->alreadyCheckedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
208 $res = $ilDB->queryF(
"SELECT question_fi FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s",
209 array(
'integer',
'integer'),
array($this->active_id, $this->pass)
212 while(
$row = $ilDB->fetchAssoc(
$res) )
214 $this->optionalQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
235 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"])))
237 $postponed = serialize($this->sequencedata[
"postponed"]);
240 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"])))
242 $hidden = serialize($this->sequencedata[
"hidden"]);
245 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
246 array(
'integer',
'integer'),
247 array($this->active_id, $this->pass)
250 $affectedRows = $ilDB->insert(
"tst_sequence",
array(
251 "active_fi" =>
array(
"integer", $this->active_id),
252 "pass" =>
array(
"integer", $this->pass),
253 "sequence" =>
array(
"clob", serialize($this->sequencedata[
"sequence"])),
254 "postponed" =>
array(
"text", $postponed),
255 "hidden" =>
array(
"text", $hidden),
266 if( (
int)$this->newlyCheckedQuestion )
270 $ilDB->replace(
'tst_seq_qst_checked',
array(
271 'active_fi' =>
array(
'integer', (
int)$this->active_id),
272 'pass' =>
array(
'integer', (
int)$this->pass),
273 'question_fi' =>
array(
'integer', (
int)$this->newlyCheckedQuestion)
285 $NOT_IN_questions = $ilDB->in(
'question_fi', $this->optionalQuestions,
true,
'integer');
288 "DELETE FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s AND $NOT_IN_questions",
289 array(
'integer',
'integer'),
array($this->active_id, $this->pass)
292 foreach($this->optionalQuestions as $questionId)
294 $ilDB->replace(
'tst_seq_qst_optional',
array(
295 'active_fi' =>
array(
'integer', (
int)$this->active_id),
296 'pass' =>
array(
'integer', (
int)$this->pass),
297 'question_fi' =>
array(
'integer', (
int)$questionId)
306 array_push($this->sequencedata[
"postponed"], intval($question_id));
314 array_push($this->sequencedata[
"hidden"], intval($question_id));
320 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
321 if (!in_array($question_id, $this->sequencedata[
"postponed"]))
333 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
334 if (!in_array($question_id, $this->sequencedata[
"hidden"]))
346 if (!array_key_exists($sequence, $this->questions))
return FALSE;
347 if (!is_array($this->sequencedata[
"postponed"]))
return FALSE;
348 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"]))
360 if (!array_key_exists($sequence, $this->questions))
return FALSE;
361 if (!is_array($this->sequencedata[
"hidden"]))
return FALSE;
362 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"]))
376 if (array_key_exists($sequence, $this->questions))
378 if (!is_array($this->sequencedata[
"postponed"])) $this->sequencedata[
"postponed"] =
array();
379 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
388 if (array_key_exists($sequence, $this->questions))
390 if (!is_array($this->sequencedata[
"hidden"])) $this->sequencedata[
"hidden"] =
array();
391 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
398 $this->newlyCheckedQuestion = $questionId;
403 return isset($this->alreadyCheckedQuestions[$questionId]);
409 $sequencekey = array_search($sequence, $correctedsequence);
410 if ($sequencekey !== FALSE)
412 return $sequencekey + 1;
427 $sequenceKeys =
array();
429 foreach(array_keys($this->questions) as $sequenceKey)
441 $sequenceKeys[] = $sequenceKey;
444 return $sequenceKeys;
449 $questions =
array();
451 foreach($this->questions as $questionId)
463 $questions[] = $questionId;
478 foreach ($seq as $sequence)
487 $questionKey = array_search($questionId, $this->questions);
489 if( $questionKey ===
false )
494 $sequenceKey = array_search($questionKey, $sequence);
496 if( $sequenceKey === FALSE )
501 unset($sequence[$sequenceKey]);
508 $correctedsequence = $this->sequencedata[
"sequence"];
511 if (is_array($this->sequencedata[
"hidden"]))
513 foreach ($this->sequencedata[
"hidden"] as $question_id)
521 foreach($this->optionalQuestions as $questionId)
526 if (is_array($this->sequencedata[
"postponed"]))
528 foreach ($this->sequencedata[
"postponed"] as $question_id)
530 $foundsequence = array_search($question_id, $this->questions);
531 if ($foundsequence !== FALSE)
533 $sequencekey = array_search($foundsequence, $correctedsequence);
534 if ($sequencekey !== FALSE)
536 unset($correctedsequence[$sequencekey]);
537 array_push($correctedsequence, $foundsequence);
542 return array_values($correctedsequence);
547 return array_search($question_id, $this->questions);
553 if (count($correctedsequence))
555 return reset($correctedsequence);
566 if (count($correctedsequence))
568 return end($correctedsequence);
579 $sequencekey = array_search($sequence, $correctedsequence);
580 if ($sequencekey !== FALSE)
582 $nextsequencekey = $sequencekey + 1;
583 if (array_key_exists($nextsequencekey, $correctedsequence))
585 return $correctedsequence[$nextsequencekey];
594 $sequencekey = array_search($sequence, $correctedsequence);
595 if ($sequencekey !== FALSE)
597 $prevsequencekey = $sequencekey - 1;
598 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
600 return $correctedsequence[$prevsequencekey];
616 $keys = array_keys($array);
619 foreach ($keys as $key)
628 if ($sequence < 1)
return FALSE;
629 if (array_key_exists($sequence, $this->questions))
631 return $this->questions[$sequence];
642 $result_array =
array();
643 include_once
"./Modules/Test/classes/class.ilObjTest.php";
646 foreach ($correctedsequence as $sequence)
649 if (is_object($question))
651 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
653 if (array_key_exists($question->getId(), $solved_questions))
655 $solved = $solved_questions[$question->getId()][
"solved"];
661 "title" => $question->getTitle(),
662 "qid" => $question->getId(),
663 "visited" => $worked_through,
664 "solved" => (($solved)?
"1":
"0"),
665 "description" => $question->getComment(),
666 "points" => $question->getMaximumPoints(),
667 "worked_through" => $worked_through,
668 "postponed" => $is_postponed,
669 "sequence" => $sequence,
671 'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
674 if( !$obligationsFilterEnabled || $row[
'obligatory'] )
676 array_push($result_array, $row);
682 return $result_array;
697 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0))
709 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0))
721 $this->sequencedata[
"hidden"] =
array();
730 foreach(
$result as $sequence => $question )
732 if( is_numeric($sequence) )
734 if( $question[
'reached'] == $question[
'max'] )
768 return array_values($this->questions);
773 return in_array($questionId, $this->questions);
778 $this->optionalQuestions[$questionId] = $questionId;
783 return isset($this->optionalQuestions[$questionId]);
788 return (
bool)count($this->optionalQuestions);
798 $this->optionalQuestions =
array();
803 $optionalSequenceKeys =
array();
805 foreach($this->sequencedata[
'sequence'] as $index => $sequenceKey)
809 $optionalSequenceKeys[$index] = $sequenceKey;
810 unset($this->sequencedata[
'sequence'][$index]);
814 foreach($optionalSequenceKeys as $index => $sequenceKey)
816 $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)
setAnsweringOptionalQuestionsConfirmed($answeringOptionalQuestionsConfirmed)
hideQuestion($question_id)
postponeQuestion($question_id)
getQuestionForSequence($sequence)
getUserSequenceQuestions()
getPositionOfSequence($sequence)
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
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()
ilDBInterface $ilDB
setConsiderOptionalQuestionsEnabled($considerOptionalQuestionsEnabled)
hasStarted(ilTestSession $testSession)
$answeringOptionalQuestionsConfirmed
isConsiderHiddenQuestionsEnabled()
postponeSequence($sequence)
static _getSolvedQuestions($active_id, $question_fi=null)
get solved questions
$considerHiddenQuestionsEnabled
getOrderedSequenceQuestions()
__construct($active_id, $pass, $randomtest)
ilTestSequence constructor
getPreviousSequence($sequence)
reorderOptionalQuestionsToSequenceEnd()
Create styles array
The data for the language used.
isHiddenQuestion($question_id)
createNewSequence($max, $shuffle)
setQuestionOptional($questionId)
isHiddenSequence($sequence)
questionExists($questionId)
saveNewlyCheckedQuestion()
ilDBInterface $ilDB
isPostponedSequence($sequence)
setQuestionChecked($questionId)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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