4require_once 
'Modules/Test/interfaces/interface.ilTestQuestionSequence.php';
 
    5require_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();
 
  122            for (
$i = 1; 
$i <= $max; 
$i++) {
 
  123                array_push($newsequence, 
$i);
 
  129        $this->sequencedata[
"sequence"] = $newsequence;
 
  139        $this->questions = array();
 
  142            "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",
 
  144            array($this->active_id)
 
  171            "SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
 
  172            array(
'integer',
'integer'),
 
  173            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"])) {
 
  183                $this->sequencedata[
"sequence"] = array();
 
  185            if (!is_array($this->sequencedata[
"postponed"])) {
 
  186                $this->sequencedata[
"postponed"] = array();
 
  188            if (!is_array($this->sequencedata[
"hidden"])) {
 
  189                $this->sequencedata[
"hidden"] = array();
 
  201            "SELECT question_fi FROM tst_seq_qst_checked WHERE active_fi = %s AND pass = %s",
 
  202            array(
'integer',
'integer'),
 
  203            array($this->active_id, $this->pass)
 
  207            $this->alreadyCheckedQuestions[ 
$row[
'question_fi'] ] = 
$row[
'question_fi'];
 
  216            "SELECT question_fi FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s",
 
  217            array(
'integer',
'integer'),
 
  218            array($this->active_id, $this->pass)
 
  222            $this->optionalQuestions[ 
$row[
'question_fi'] ] = 
$row[
'question_fi'];
 
  243        if ((is_array($this->sequencedata[
"postponed"])) && (count($this->sequencedata[
"postponed"]))) {
 
  244            $postponed = serialize($this->sequencedata[
"postponed"]);
 
  247        if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]))) {
 
  248            $hidden = serialize($this->sequencedata[
"hidden"]);
 
  251        $affectedRows = 
$ilDB->manipulateF(
 
  252            "DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
 
  253            array(
'integer',
'integer'),
 
  254            array($this->active_id, $this->pass)
 
  257        $affectedRows = 
$ilDB->insert(
"tst_sequence", array(
 
  258            "active_fi" => array(
"integer", $this->active_id),
 
  259            "pass" => array(
"integer", $this->pass),
 
  260            "sequence" => array(
"clob", serialize($this->sequencedata[
"sequence"])),
 
  261            "postponed" => array(
"text", $postponed),
 
  262            "hidden" => array(
"text", $hidden),
 
  263            "tstamp" => array(
"integer", time()),
 
  273        if ((
int) $this->newlyCheckedQuestion) {
 
  276            $ilDB->replace(
'tst_seq_qst_checked', array(
 
  277                'active_fi' => array(
'integer', (
int) $this->active_id),
 
  278                'pass' => array(
'integer', (
int) $this->pass),
 
  279                'question_fi' => array(
'integer', (
int) $this->newlyCheckedQuestion)
 
  291        $NOT_IN_questions = 
$ilDB->in(
'question_fi', $this->optionalQuestions, 
true, 
'integer');
 
  294            "DELETE FROM tst_seq_qst_optional WHERE active_fi = %s AND pass = %s AND $NOT_IN_questions",
 
  295            array(
'integer', 
'integer'),
 
  296            array($this->active_id, $this->pass)
 
  299        foreach ($this->optionalQuestions as $questionId) {
 
  300            $ilDB->replace(
'tst_seq_qst_optional', array(
 
  301                'active_fi' => array(
'integer', (
int) $this->active_id),
 
  302                'pass' => array(
'integer', (
int) $this->pass),
 
  303                'question_fi' => array(
'integer', (
int) $questionId)
 
  311            array_push($this->sequencedata[
"postponed"], intval($question_id));
 
  318            array_push($this->sequencedata[
"hidden"], intval($question_id));
 
  324        if (!is_array($this->sequencedata[
"postponed"])) {
 
  327        if (!in_array($question_id, $this->sequencedata[
"postponed"])) {
 
  336        if (!is_array($this->sequencedata[
"hidden"])) {
 
  339        if (!in_array($question_id, $this->sequencedata[
"hidden"])) {
 
  348        if (!array_key_exists($sequence, $this->questions)) {
 
  351        if (!is_array($this->sequencedata[
"postponed"])) {
 
  354        if (!in_array($this->questions[$sequence], $this->sequencedata[
"postponed"])) {
 
  363        if (!array_key_exists($sequence, $this->questions)) {
 
  366        if (!is_array($this->sequencedata[
"hidden"])) {
 
  369        if (!in_array($this->questions[$sequence], $this->sequencedata[
"hidden"])) {
 
  379            if (array_key_exists($sequence, $this->questions)) {
 
  380                if (!is_array($this->sequencedata[
"postponed"])) {
 
  381                    $this->sequencedata[
"postponed"] = array();
 
  383                array_push($this->sequencedata[
"postponed"], intval($this->questions[$sequence]));
 
  391            if (array_key_exists($sequence, $this->questions)) {
 
  392                if (!is_array($this->sequencedata[
"hidden"])) {
 
  393                    $this->sequencedata[
"hidden"] = array();
 
  395                array_push($this->sequencedata[
"hidden"], intval($this->questions[$sequence]));
 
  402        $this->newlyCheckedQuestion = $questionId;
 
  407        return isset($this->alreadyCheckedQuestions[$questionId]);
 
  413        $sequencekey = array_search($sequence, $correctedsequence);
 
  414        if ($sequencekey !== 
false) {
 
  415            return $sequencekey + 1;
 
  428        $sequenceKeys = array();
 
  430        foreach (array_keys($this->questions) as $sequenceKey) {
 
  439            $sequenceKeys[] = $sequenceKey;
 
  442        return $sequenceKeys;
 
  449        foreach ($this->questions as $questionId) {
 
  473        foreach ($seq as $sequence) {
 
  481        $questionKey = array_search($questionId, $this->questions);
 
  483        if ($questionKey === 
false) {
 
  487        $sequenceKey = array_search($questionKey, $sequence);
 
  489        if ($sequenceKey === 
false) {
 
  493        unset($sequence[$sequenceKey]);
 
  500        $correctedsequence = $this->sequencedata[
"sequence"];
 
  502            if (is_array($this->sequencedata[
"hidden"])) {
 
  503                foreach ($this->sequencedata[
"hidden"] as $question_id) {
 
  509            foreach ($this->optionalQuestions as $questionId) {
 
  513        if (is_array($this->sequencedata[
"postponed"])) {
 
  514            foreach ($this->sequencedata[
"postponed"] as $question_id) {
 
  515                $foundsequence = array_search($question_id, $this->questions);
 
  516                if ($foundsequence !== 
false) {
 
  517                    $sequencekey = array_search($foundsequence, $correctedsequence);
 
  518                    if ($sequencekey !== 
false) {
 
  519                        unset($correctedsequence[$sequencekey]);
 
  520                        array_push($correctedsequence, $foundsequence);
 
  525        return array_values($correctedsequence);
 
  530        return array_search($question_id, $this->questions);
 
  536        if (count($correctedsequence)) {
 
  537            return reset($correctedsequence);
 
  546        if (count($correctedsequence)) {
 
  547            return end($correctedsequence);
 
  556        $sequencekey = array_search($sequence, $correctedsequence);
 
  557        if ($sequencekey !== 
false) {
 
  558            $nextsequencekey = $sequencekey + 1;
 
  559            if (array_key_exists($nextsequencekey, $correctedsequence)) {
 
  560                return $correctedsequence[$nextsequencekey];
 
  569        $sequencekey = array_search($sequence, $correctedsequence);
 
  570        if ($sequencekey !== 
false) {
 
  571            $prevsequencekey = $sequencekey - 1;
 
  572            if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence))) {
 
  573                return $correctedsequence[$prevsequencekey];
 
  589        $keys = array_keys($array);
 
  603        if (array_key_exists($sequence, $this->questions)) {
 
  604            return $this->questions[$sequence];
 
  613        $result_array = array();
 
  614        include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  617        foreach ($correctedsequence as $sequence) {
 
  619            if (is_object($question)) {
 
  620                $worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(), $this->pass);
 
  622                if (array_key_exists($question->getId(), $solved_questions)) {
 
  623                    $solved =  $solved_questions[$question->getId()][
"solved"];
 
  629                    "title" => $question->getTitle(),
 
  630                    "qid" => $question->getId(),
 
  631                    "visited" => $worked_through,
 
  632                    "solved" => (($solved)?
"1":
"0"),
 
  633                    "description" => $question->getComment(),
 
  634                    "points" => $question->getMaximumPoints(),
 
  635                    "worked_through" => $worked_through,
 
  636                    "postponed" => $is_postponed,
 
  637                    "sequence" => $sequence,
 
  639                    'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
 
  642                if (!$obligationsFilterEnabled || 
$row[
'obligatory']) {
 
  643                    array_push($result_array, 
$row);
 
  649        return $result_array;
 
  664        if ((is_array($this->sequencedata[
"sequence"])) && (count($this->sequencedata[
"sequence"]) > 0)) {
 
  673        if ((is_array($this->sequencedata[
"hidden"])) && (count($this->sequencedata[
"hidden"]) > 0)) {
 
  682        $this->sequencedata[
"hidden"] = array();
 
  690            foreach (
$result as $sequence => $question) {
 
  691                if (is_numeric($sequence)) {
 
  692                    if ($question[
'reached'] == $question[
'max']) {
 
  723        return array_values($this->questions);
 
  728        return in_array($questionId, $this->questions);
 
  733        $this->optionalQuestions[$questionId] = $questionId;
 
  738        return isset($this->optionalQuestions[$questionId]);
 
  743        return (
bool) count($this->optionalQuestions);
 
  753        $this->optionalQuestions = array();
 
  758        $optionalSequenceKeys = array();
 
  760        foreach ($this->sequencedata[
'sequence'] as 
$index => $sequenceKey) {
 
  762                $optionalSequenceKeys[
$index] = $sequenceKey;
 
  763                unset($this->sequencedata[
'sequence'][
$index]);
 
  767        foreach ($optionalSequenceKeys as 
$index => $sequenceKey) {
 
  768            $this->sequencedata[
'sequence'][
$index] = $sequenceKey;
 
An exception for terminatinating execution or to throw for unit testing.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
& 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.
static _getSolvedQuestions($active_id, $question_fi=null)
get solved questions
static isQuestionObligatory($question_id)
checks wether the question with given id is marked as obligatory or not
questionExists($questionId)
isHiddenQuestion($question_id)
setAnsweringOptionalQuestionsConfirmed($answeringOptionalQuestionsConfirmed)
isPostponedSequence($sequence)
pcArrayShuffle($array)
Shuffles the values of a given array.
$answeringOptionalQuestionsConfirmed
getUserSequenceQuestions()
getQuestionForSequence($sequence)
hideQuestion($question_id)
getSequenceSummary($obligationsFilterEnabled=false)
setQuestionChecked($questionId)
isQuestionChecked($questionId)
reorderOptionalQuestionsToSequenceEnd()
isHiddenSequence($sequence)
isConsiderOptionalQuestionsEnabled()
$considerOptionalQuestionsEnabled
postponeQuestion($question_id)
getOrderedSequenceQuestions()
postponeSequence($sequence)
loadQuestions(ilTestQuestionSetConfig $testQuestionSetConfig=null, $taxonomyFilterSelection=array())
Loads the question mapping.
saveToDb()
Saves the sequence data for a given pass to the database.
saveNewlyCheckedQuestion()
@global ilDBInterface $ilDB
isConsiderHiddenQuestionsEnabled()
isQuestionOptional($questionId)
saveOptionalQuestions()
@global ilDBInterface $ilDB
hasStarted(ilTestSession $testSession)
__construct($active_id, $pass, $randomtest)
ilTestSequence constructor
hideCorrectAnsweredQuestions(ilObjTest $testOBJ, $activeId, $pass)
getPositionOfSequence($sequence)
createNewSequence($max, $shuffle)
getNextSequence($sequence)
getPreviousSequence($sequence)
setQuestionOptional($questionId)
setConsiderOptionalQuestionsEnabled($considerOptionalQuestionsEnabled)
$considerHiddenQuestionsEnabled
loadFromDb()
Loads the sequence data for a given active id.
getSequenceForQuestion($question_id)
ensureQuestionNotInSequence($sequence, $questionId)
isPostponedQuestion($question_id)
isAnsweringOptionalQuestionsConfirmed()
setConsiderHiddenQuestionsEnabled($considerHiddenQuestionsEnabled)
foreach($_POST as $key=> $value) $res