4 require_once
'Modules/Test/interfaces/interface.ilTestQuestionSequence.php';
5 require_once
'Modules/Test/interfaces/interface.ilTestSequenceSummaryProvider.php';
106 $this->isRandomTest = $randomtest;
107 $this->sequencedata = array(
108 "sequence" => array(),
109 "postponed" => array(),
113 $this->alreadyCheckedQuestions = array();
114 $this->newlyCheckedQuestion = null;
116 $this->optionalQuestions = array();
117 $this->answeringOptionalQuestionsConfirmed =
false;
119 $this->considerHiddenQuestionsEnabled =
false;
120 $this->considerOptionalQuestionsEnabled =
true;
130 $newsequence = array();
132 for (
$i = 1;
$i <= $max;
$i++) {
133 array_push($newsequence,
$i);
139 $this->sequencedata[
"sequence"] = $newsequence;
148 $ilDB = $DIC[
'ilDB'];
150 $this->questions = array();
153 "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",
155 array($this->active_id)
182 $ilDB = $DIC[
'ilDB'];
184 "SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
185 array(
'integer',
'integer'),
186 array($this->active_id, $this->pass)
190 $this->sequencedata = array(
191 "sequence" => unserialize(
$row[
"sequence"]),
192 "postponed" => unserialize(
$row[
"postponed"]),
193 "hidden" => unserialize(
$row[
"hidden"])
195 if (!is_array($this->sequencedata[
"sequence"])) {
196 $this->sequencedata[
"sequence"] = array();
198 if (!is_array($this->sequencedata[
"postponed"])) {
199 $this->sequencedata[
"postponed"] = array();
201 if (!is_array($this->sequencedata[
"hidden"])) {
202 $this->sequencedata[
"hidden"] = array();
213 $res = $DIC->database()->queryF(
214 "SELECT question_fi FROM tst_seq_qst_presented WHERE active_fi = %s AND pass = %s",
215 array(
'integer',
'integer'),
216 array($this->active_id, $this->pass)
219 while (
$row = $DIC->database()->fetchAssoc(
$res)) {
220 $this->alreadyPresentedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
227 $ilDB = $DIC[
'ilDB'];
230 "SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
231 array(
'integer',
'integer'),
232 array($this->active_id, $this->pass)
236 $this->alreadyCheckedQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
243 $ilDB = $DIC[
'ilDB'];
246 "SELECT question_fi FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s",
247 array(
'integer',
'integer'),
248 array($this->active_id, $this->pass)
252 $this->optionalQuestions[
$row[
'question_fi'] ] = $row[
'question_fi'];
272 $ilDB = $DIC[
'ilDB'];
275 if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"]))) {
276 $postponed = serialize($this->sequencedata[
"postponed"]);
279 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]))) {
280 $hidden = serialize($this->sequencedata[
"hidden"]);
283 $affectedRows =
$ilDB->manipulateF(
284 "DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
285 array(
'integer',
'integer'),
286 array($this->active_id, $this->pass)
289 $affectedRows =
$ilDB->insert(
"tst_sequence", array(
290 "active_fi" => array(
"integer", $this->active_id),
291 "pass" => array(
"integer", $this->pass),
292 "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
293 "postponed" => array(
"text", $postponed),
294 "hidden" => array(
"text", $hidden),
295 "tstamp" => array(
"integer", time()),
302 if ((
int) $this->newlyPresentedQuestion) {
305 $DIC->database()->replace(
'tst_seq_qst_presented', array(
306 'active_fi' => array(
'integer', (
int) $this->active_id),
307 'pass' => array(
'integer', (
int) $this->pass),
308 'question_fi' => array(
'integer', (
int) $this->newlyPresentedQuestion)
318 if ((
int) $this->newlyCheckedQuestion) {
320 $ilDB = $DIC[
'ilDB'];
322 $ilDB->replace(
'tst_seq_qst_checked', array(
323 'active_fi' => array(
'integer', (
int) $this->active_id),
324 'pass' => array(
'integer', (
int) $this->pass),
325 'question_fi' => array(
'integer', (
int) $this->newlyCheckedQuestion)
336 $ilDB = $DIC[
'ilDB'];
338 $NOT_IN_questions =
$ilDB->in(
'question_fi', $this->optionalQuestions,
true,
'integer');
341 "DELETE FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s AND $NOT_IN_questions",
342 array(
'integer',
'integer'),
343 array($this->active_id, $this->pass)
346 foreach ($this->optionalQuestions as $questionId) {
347 $ilDB->replace(
'tst_seq_qst_optional', array(
348 'active_fi' => array(
'integer', (
int) $this->active_id),
349 'pass' => array(
'integer', (
int) $this->pass),
350 'question_fi' => array(
'integer', (
int) $questionId)
358 array_push($this->sequencedata[
"postponed"], intval($question_id));
365 array_push($this->sequencedata[
"hidden"], intval($question_id));
371 if (!is_array($this->sequencedata[
"postponed"])) {
374 if (!in_array($question_id, $this->sequencedata[
"postponed"])) {
383 if (!is_array($this->sequencedata[
"hidden"])) {
386 if (!in_array($question_id, $this->sequencedata[
"hidden"])) {
395 if (!array_key_exists($sequence, $this->questions)) {
398 if (!is_array($this->sequencedata[
"postponed"])) {
401 if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"])) {
410 if (!array_key_exists($sequence, $this->questions)) {
413 if (!is_array($this->sequencedata[
"hidden"])) {
416 if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"])) {
426 if (array_key_exists($sequence, $this->questions)) {
427 if (!is_array($this->sequencedata[
"postponed"])) {
428 $this->sequencedata[
"postponed"] = array();
430 array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
438 if (array_key_exists($sequence, $this->questions)) {
439 if (!is_array($this->sequencedata[
"hidden"])) {
440 $this->sequencedata[
"hidden"] = array();
442 array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
449 $this->newlyPresentedQuestion = $questionId;
455 $this->newlyPresentedQuestion == $questionId || in_array($questionId, $this->alreadyPresentedQuestions)
469 if ($this->newlyPresentedQuestion == $nextQstId) {
473 if (in_array($nextQstId, $this->alreadyPresentedQuestions)) {
482 $this->newlyCheckedQuestion = $questionId;
487 return isset($this->alreadyCheckedQuestions[$questionId]);
493 $sequencekey = array_search($sequence, $correctedsequence);
494 if ($sequencekey !==
false) {
495 return $sequencekey + 1;
508 $sequenceKeys = array();
510 foreach (array_keys($this->questions) as $sequenceKey) {
519 $sequenceKeys[] = $sequenceKey;
522 return $sequenceKeys;
529 foreach ($this->questions as $questionId) {
553 foreach ($seq as $sequence) {
561 $questionKey = array_search($questionId, $this->questions);
563 if ($questionKey ===
false) {
567 $sequenceKey = array_search($questionKey, $sequence);
569 if ($sequenceKey ===
false) {
573 unset($sequence[$sequenceKey]);
580 $correctedsequence = $this->sequencedata[
"sequence"];
582 if (is_array($this->sequencedata[
"hidden"])) {
583 foreach ($this->sequencedata[
"hidden"] as $question_id) {
589 foreach ($this->optionalQuestions as $questionId) {
593 if (is_array($this->sequencedata[
"postponed"])) {
594 foreach ($this->sequencedata[
"postponed"] as $question_id) {
595 $foundsequence = array_search($question_id, $this->questions);
596 if ($foundsequence !==
false) {
597 $sequencekey = array_search($foundsequence, $correctedsequence);
598 if ($sequencekey !==
false) {
599 unset($correctedsequence[$sequencekey]);
600 array_push($correctedsequence, $foundsequence);
605 return array_values($correctedsequence);
610 return array_search($question_id, $this->questions);
616 if (count($correctedsequence)) {
617 return reset($correctedsequence);
626 if (count($correctedsequence)) {
627 return end($correctedsequence);
636 $sequencekey = array_search($sequence, $correctedsequence);
637 if ($sequencekey !==
false) {
638 $nextsequencekey = $sequencekey + 1;
639 if (array_key_exists($nextsequencekey, $correctedsequence)) {
640 return $correctedsequence[$nextsequencekey];
649 $sequencekey = array_search($sequence, $correctedsequence);
650 if ($sequencekey !==
false) {
651 $prevsequencekey = $sequencekey - 1;
652 if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence))) {
653 return $correctedsequence[$prevsequencekey];
669 $keys = array_keys($array);
683 if (array_key_exists($sequence, $this->questions)) {
684 return $this->questions[$sequence];
693 $result_array = array();
694 include_once
"./Modules/Test/classes/class.ilObjTest.php";
697 foreach ($correctedsequence as $sequence) {
699 if (is_object($question)) {
700 $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(),
$this->pass);
702 if (array_key_exists($question->getId(), $solved_questions)) {
703 $solved = $solved_questions[$question->getId()][
"solved"];
709 "title" => $question->getTitle(),
710 "qid" => $question->getId(),
712 "visited" => $worked_through,
713 "solved" => (($solved)?
"1":
"0"),
714 "description" => $question->getComment(),
715 "points" => $question->getMaximumPoints(),
716 "worked_through" => $worked_through,
717 "postponed" => $is_postponed,
718 "sequence" => $sequence,
720 'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
723 if (!$obligationsFilterEnabled || $row[
'obligatory']) {
724 array_push($result_array, $row);
730 return $result_array;
745 if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0)) {
754 if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0)) {
763 $this->sequencedata[
"hidden"] = array();
771 foreach (
$result as $sequence => $question) {
772 if (is_numeric($sequence)) {
773 if ($question[
'reached'] == $question[
'max']) {
804 return array_values($this->questions);
809 return in_array($questionId, $this->questions);
814 $this->optionalQuestions[$questionId] = $questionId;
819 return isset($this->optionalQuestions[$questionId]);
824 return (
bool) count($this->optionalQuestions);
834 $this->optionalQuestions = array();
839 $optionalSequenceKeys = array();
841 foreach ($this->sequencedata[
'sequence'] as
$index => $sequenceKey) {
843 $optionalSequenceKeys[
$index] = $sequenceKey;
844 unset($this->sequencedata[
'sequence'][
$index]);
848 foreach ($optionalSequenceKeys as
$index => $sequenceKey) {
849 $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)
isQuestionPresented($questionId)
hideQuestion($question_id)
postponeQuestion($question_id)
getQuestionForSequence($sequence)
saveNewlyPresentedQuestion()
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)
foreach($_POST as $key=> $value) $res
setQuestionPresented($questionId)
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
$alreadyPresentedQuestions
getPreviousSequence($sequence)
reorderOptionalQuestionsToSequenceEnd()
isHiddenQuestion($question_id)
createNewSequence($max, $shuffle)
setQuestionOptional($questionId)
isHiddenSequence($sequence)
isNextQuestionPresented($questionId)
questionExists($questionId)
saveNewlyCheckedQuestion()
ilDBInterface $ilDB
isPostponedSequence($sequence)
& 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...
setQuestionChecked($questionId)
hideCorrectAnsweredQuestions(ilObjTest $testOBJ, $activeId, $pass)
isAnsweringOptionalQuestionsConfirmed()
ensureQuestionNotInSequence($sequence, $questionId)
getSequenceSummary($obligationsFilterEnabled=false)
pcArrayShuffle($array)
Shuffles the values of a given array.
$considerOptionalQuestionsEnabled