ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilTestSequence Class Reference

Test sequence handler. More...

+ Inheritance diagram for ilTestSequence:
+ Collaboration diagram for ilTestSequence:

Public Member Functions

 ilTestSequence ($active_id, $pass, $randomtest)
 ilTestSequence constructor
 getActiveId ()
 createNewSequence ($max, $shuffle)
 loadQuestions (ilTestQuestionSetConfig $testQuestionSetConfig=null, $taxonomyFilterSelection=array())
 Loads the question mapping.
 loadFromDb ()
 Loads the sequence data for a given active id.
 saveToDb ()
 Saves the sequence data for a given pass to the database.
 postponeQuestion ($question_id)
 hideQuestion ($question_id)
 isPostponedQuestion ($question_id)
 isHiddenQuestion ($question_id)
 isPostponedSequence ($sequence)
 isHiddenSequence ($sequence)
 postponeSequence ($sequence)
 hideSequence ($sequence)
 getPositionOfSequence ($sequence)
 getUserQuestionCount ()
 getOrderedSequence ()
 getOrderedSequenceQuestions ()
 getUserSequence ()
 getUserSequenceQuestions ()
 getSequenceForQuestion ($question_id)
 getFirstSequence ()
 getLastSequence ()
 getNextSequence ($sequence)
 getPreviousSequence ($sequence)
 pcArrayShuffle ($array)
 Shuffles the values of a given array.
 getQuestionForSequence ($sequence)
getSequenceSummary ($obligationsFilter=false)
 getPass ()
 setPass ($pass)
 hasSequence ()
 hasHiddenQuestions ()
 clearHiddenQuestions ()
 hasStarted (ilTestSession $testSession)
 openQuestionExists ()
 questionExists ($questionId)

Data Fields

 $sequencedata
 $questions
 $active_id
 $pass
 $isRandomTest

Protected Member Functions

 getCorrectedSequence ($with_hidden_questions=FALSE)

Private Member Functions

 hideCorrectAnsweredQuestions (ilObjTest $testOBJ, $activeId, $pass)

Detailed Description

Test sequence handler.

This class manages the sequence settings for a given user

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
Id:
class.ilTestSequence.php 58241 2015-02-27 15:11:15Z gitmgr

Definition at line 13 of file class.ilTestSequence.php.

Member Function Documentation

ilTestSequence::clearHiddenQuestions ( )

Definition at line 544 of file class.ilTestSequence.php.

{
$this->sequencedata["hidden"] = array();
}
ilTestSequence::createNewSequence (   $max,
  $shuffle 
)

Definition at line 76 of file class.ilTestSequence.php.

References pcArrayShuffle().

{
$newsequence = array();
if ($max > 0)
{
for ($i = 1; $i <= $max; $i++)
{
array_push($newsequence, $i);
}
if ($shuffle) $newsequence = $this->pcArrayShuffle($newsequence);
}
$this->sequencedata["sequence"] = $newsequence;
}

+ Here is the call graph for this function:

ilTestSequence::getActiveId ( )

Definition at line 71 of file class.ilTestSequence.php.

References $active_id.

{
}
ilTestSequence::getCorrectedSequence (   $with_hidden_questions = FALSE)
protected

Definition at line 330 of file class.ilTestSequence.php.

Referenced by getFirstSequence(), getLastSequence(), getNextSequence(), getPositionOfSequence(), getPreviousSequence(), getSequenceSummary(), getUserQuestionCount(), getUserSequence(), and getUserSequenceQuestions().

{
$correctedsequence = $this->sequencedata["sequence"];
if (!$with_hidden_questions)
{
if (is_array($this->sequencedata["hidden"]))
{
foreach ($this->sequencedata["hidden"] as $question_id)
{
$foundsequence = array_search($question_id, $this->questions);
if ($foundsequence !== FALSE)
{
$sequencekey = array_search($foundsequence, $correctedsequence);
if ($sequencekey !== FALSE)
{
unset($correctedsequence[$sequencekey]);
}
}
}
}
}
if (is_array($this->sequencedata["postponed"]))
{
foreach ($this->sequencedata["postponed"] as $question_id)
{
$foundsequence = array_search($question_id, $this->questions);
if ($foundsequence !== FALSE)
{
$sequencekey = array_search($foundsequence, $correctedsequence);
if ($sequencekey !== FALSE)
{
unset($correctedsequence[$sequencekey]);
array_push($correctedsequence, $foundsequence);
}
}
}
}
return array_values($correctedsequence);
}

+ Here is the caller graph for this function:

ilTestSequence::getFirstSequence ( )

Definition at line 375 of file class.ilTestSequence.php.

References getCorrectedSequence().

Referenced by hasStarted(), and openQuestionExists().

{
$correctedsequence = $this->getCorrectedSequence();
if (count($correctedsequence))
{
return reset($correctedsequence);
}
else
{
return FALSE;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSequence::getLastSequence ( )

Definition at line 388 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
$correctedsequence = $this->getCorrectedSequence();
if (count($correctedsequence))
{
return end($correctedsequence);
}
else
{
return FALSE;
}
}

+ Here is the call graph for this function:

ilTestSequence::getNextSequence (   $sequence)

Definition at line 401 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
$correctedsequence = $this->getCorrectedSequence();
$sequencekey = array_search($sequence, $correctedsequence);
if ($sequencekey !== FALSE)
{
$nextsequencekey = $sequencekey + 1;
if (array_key_exists($nextsequencekey, $correctedsequence))
{
return $correctedsequence[$nextsequencekey];
}
}
return FALSE;
}

+ Here is the call graph for this function:

ilTestSequence::getOrderedSequence ( )

Definition at line 304 of file class.ilTestSequence.php.

{
return array_keys($this->questions);
}
ilTestSequence::getOrderedSequenceQuestions ( )

Definition at line 309 of file class.ilTestSequence.php.

References $questions.

{
}
ilTestSequence::getPass ( )

Definition at line 510 of file class.ilTestSequence.php.

References $pass.

{
return $this->pass;
}
ilTestSequence::getPositionOfSequence (   $sequence)

Definition at line 285 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
$correctedsequence = $this->getCorrectedSequence();
$sequencekey = array_search($sequence, $correctedsequence);
if ($sequencekey !== FALSE)
{
return $sequencekey + 1;
}
else
{
return "";
}
}

+ Here is the call graph for this function:

ilTestSequence::getPreviousSequence (   $sequence)

Definition at line 416 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
$correctedsequence = $this->getCorrectedSequence();
$sequencekey = array_search($sequence, $correctedsequence);
if ($sequencekey !== FALSE)
{
$prevsequencekey = $sequencekey - 1;
if (($prevsequencekey >= 0) && (array_key_exists($prevsequencekey, $correctedsequence)))
{
return $correctedsequence[$prevsequencekey];
}
}
return FALSE;
}

+ Here is the call graph for this function:

ilTestSequence::getQuestionForSequence (   $sequence)

Definition at line 451 of file class.ilTestSequence.php.

Referenced by getSequenceSummary(), and getUserSequenceQuestions().

{
if ($sequence < 1) return FALSE;
if (array_key_exists($sequence, $this->questions))
{
return $this->questions[$sequence];
}
else
{
return FALSE;
}
}

+ Here is the caller graph for this function:

ilTestSequence::getSequenceForQuestion (   $question_id)

Definition at line 370 of file class.ilTestSequence.php.

{
return array_search($question_id, $this->questions);
}
& ilTestSequence::getSequenceSummary (   $obligationsFilter = false)

Definition at line 464 of file class.ilTestSequence.php.

References $pass, $row, ilObjTest\_getSolvedQuestions(), ilObjTest\_instanciateQuestion(), getCorrectedSequence(), getQuestionForSequence(), isPostponedQuestion(), and ilObjTest\isQuestionObligatory().

{
$correctedsequence = $this->getCorrectedSequence();
$result_array = array();
include_once "./Modules/Test/classes/class.ilObjTest.php";
$solved_questions = ilObjTest::_getSolvedQuestions($this->active_id);
$key = 1;
foreach ($correctedsequence as $sequence)
{
if (is_object($question))
{
$worked_through = $question->_isWorkedThrough($this->active_id, $question->getId(), $this->pass);
$solved = 0;
if (array_key_exists($question->getId(), $solved_questions))
{
$solved = $solved_questions[$question->getId()]["solved"];
}
$is_postponed = $this->isPostponedQuestion($question->getId());
$row = array(
"nr" => "$key",
"title" => $question->getTitle(),
"qid" => $question->getId(),
"visited" => $worked_through,
"solved" => (($solved)?"1":"0"),
"description" => $question->getComment(),
"points" => $question->getMaximumPoints(),
"worked_through" => $worked_through,
"postponed" => $is_postponed,
"sequence" => $sequence,
"obligatory" => ilObjTest::isQuestionObligatory($question->getId()),
'isAnswered' => $question->isAnswered($this->active_id, $this->pass)
);
if( !$obligationsFilter || $row['obligatory'] )
{
array_push($result_array, $row);
}
$key++;
}
}
return $result_array;
}

+ Here is the call graph for this function:

ilTestSequence::getUserQuestionCount ( )

Definition at line 299 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
return count($this->getCorrectedSequence());
}

+ Here is the call graph for this function:

ilTestSequence::getUserSequence ( )

Definition at line 314 of file class.ilTestSequence.php.

References getCorrectedSequence().

{
return $this->getCorrectedSequence(TRUE);
}

+ Here is the call graph for this function:

ilTestSequence::getUserSequenceQuestions ( )

Definition at line 319 of file class.ilTestSequence.php.

References getCorrectedSequence(), and getQuestionForSequence().

{
$seq = $this->getCorrectedSequence(TRUE);
$found = array();
foreach ($seq as $sequence)
{
array_push($found, $this->getQuestionForSequence($sequence));
}
return $found;
}

+ Here is the call graph for this function:

ilTestSequence::hasHiddenQuestions ( )

Definition at line 532 of file class.ilTestSequence.php.

{
if ((is_array($this->sequencedata["hidden"])) && (count($this->sequencedata["hidden"]) > 0))
{
return TRUE;
}
else
{
return FALSE;
}
}
ilTestSequence::hasSequence ( )

Definition at line 520 of file class.ilTestSequence.php.

{
if ((is_array($this->sequencedata["sequence"])) && (count($this->sequencedata["sequence"]) > 0))
{
return TRUE;
}
else
{
return FALSE;
}
}
ilTestSequence::hasStarted ( ilTestSession  $testSession)

Definition at line 570 of file class.ilTestSequence.php.

References getFirstSequence(), and ilTestSession\getLastSequence().

{
if( $testSession->getLastSequence() < 1 )
{
return false;
}
// WTF ?? heard about tests with only one question !?
if( $testSession->getLastSequence() == $this->getFirstSequence() )
{
return false;
}
return true;
}

+ Here is the call graph for this function:

ilTestSequence::hideCorrectAnsweredQuestions ( ilObjTest  $testOBJ,
  $activeId,
  $pass 
)
private

Definition at line 549 of file class.ilTestSequence.php.

References $pass, $result, ilObjTest\getTestResult(), hideQuestion(), and saveToDb().

{
if( $activeId > 0 )
{
$result = $testOBJ->getTestResult($activeId, $pass, TRUE);
foreach( $result as $sequence => $question )
{
if( is_numeric($sequence) )
{
if( $question['reached'] == $question['max'] )
{
$this->hideQuestion($question['qid']);
}
}
}
$this->saveToDb();
}
}

+ Here is the call graph for this function:

ilTestSequence::hideQuestion (   $question_id)

Definition at line 199 of file class.ilTestSequence.php.

References isHiddenQuestion().

Referenced by hideCorrectAnsweredQuestions().

{
if (!$this->isHiddenQuestion($question_id))
{
array_push($this->sequencedata["hidden"], intval($question_id));
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSequence::hideSequence (   $sequence)

Definition at line 273 of file class.ilTestSequence.php.

References isHiddenSequence().

{
if (!$this->isHiddenSequence($sequence))
{
if (array_key_exists($sequence, $this->questions))
{
if (!is_array($this->sequencedata["hidden"])) $this->sequencedata["hidden"] = array();
array_push($this->sequencedata["hidden"], intval($this->questions[$sequence]));
}
}
}

+ Here is the call graph for this function:

ilTestSequence::ilTestSequence (   $active_id,
  $pass,
  $randomtest 
)

ilTestSequence constructor

The constructor takes possible arguments an creates an instance of the ilTestSequence object.

Parameters
object$a_objectA reference to the test container object public

Definition at line 59 of file class.ilTestSequence.php.

References $active_id, and $pass.

{
$this->active_id = $active_id;
$this->pass = $pass;
$this->isRandomTest = $randomtest;
$this->sequencedata = array(
"sequence" => array(),
"postponed" => array(),
"hidden" => array()
);
}
ilTestSequence::isHiddenQuestion (   $question_id)

Definition at line 220 of file class.ilTestSequence.php.

Referenced by hideQuestion().

{
if (!is_array($this->sequencedata["hidden"])) return FALSE;
if (!in_array($question_id, $this->sequencedata["hidden"]))
{
return FALSE;
}
else
{
return TRUE;
}
}

+ Here is the caller graph for this function:

ilTestSequence::isHiddenSequence (   $sequence)

Definition at line 247 of file class.ilTestSequence.php.

Referenced by hideSequence().

{
if (!array_key_exists($sequence, $this->questions)) return FALSE;
if (!is_array($this->sequencedata["hidden"])) return FALSE;
if (!in_array($this->questions[$sequence], $this->sequencedata["hidden"]))
{
return FALSE;
}
else
{
return TRUE;
}
}

+ Here is the caller graph for this function:

ilTestSequence::isPostponedQuestion (   $question_id)

Definition at line 207 of file class.ilTestSequence.php.

Referenced by getSequenceSummary(), and postponeQuestion().

{
if (!is_array($this->sequencedata["postponed"])) return FALSE;
if (!in_array($question_id, $this->sequencedata["postponed"]))
{
return FALSE;
}
else
{
return TRUE;
}
}

+ Here is the caller graph for this function:

ilTestSequence::isPostponedSequence (   $sequence)

Definition at line 233 of file class.ilTestSequence.php.

Referenced by postponeSequence().

{
if (!array_key_exists($sequence, $this->questions)) return FALSE;
if (!is_array($this->sequencedata["postponed"])) return FALSE;
if (!in_array($this->questions[$sequence], $this->sequencedata["postponed"]))
{
return FALSE;
}
else
{
return TRUE;
}
}

+ Here is the caller graph for this function:

ilTestSequence::loadFromDb ( )

Loads the sequence data for a given active id.

Returns
string The filesystem path of the certificate

Definition at line 135 of file class.ilTestSequence.php.

References $result, and $row.

{
global $ilDB;
$result = $ilDB->queryF("SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s",
array('integer','integer'),
array($this->active_id, $this->pass)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$this->sequencedata = array(
"sequence" => unserialize($row["sequence"]),
"postponed" => unserialize($row["postponed"]),
"hidden" => unserialize($row["hidden"])
);
if (!is_array($this->sequencedata["sequence"])) $this->sequencedata["sequence"] = array();
if (!is_array($this->sequencedata["postponed"])) $this->sequencedata["postponed"] = array();
if (!is_array($this->sequencedata["hidden"])) $this->sequencedata["hidden"] = array();
}
}
ilTestSequence::loadQuestions ( ilTestQuestionSetConfig  $testQuestionSetConfig = null,
  $taxonomyFilterSelection = array() 
)

Loads the question mapping.

Definition at line 93 of file class.ilTestSequence.php.

References $result.

{
global $ilDB;
$this->questions = array();
if ($this->isRandomTest)
{
$result = $ilDB->queryF("SELECT tst_test_rnd_qst.* FROM tst_test_rnd_qst, qpl_questions WHERE tst_test_rnd_qst.active_fi = %s AND qpl_questions.question_id = tst_test_rnd_qst.question_fi AND tst_test_rnd_qst.pass = %s ORDER BY sequence",
array('integer','integer'),
array($this->active_id, $this->pass)
);
// The following is a fix for random tests prior to ILIAS 3.8. If someone started a random test in ILIAS < 3.8, there
// is only one test pass (pass = 0) in tst_test_rnd_qst while with ILIAS 3.8 there are questions for every test pass.
// To prevent problems with tests started in an older version and continued in ILIAS 3.8, the first pass should be taken if
// no questions are present for a newer pass.
if ($result->numRows() == 0)
{
$result = $ilDB->queryF("SELECT tst_test_rnd_qst.* FROM tst_test_rnd_qst, qpl_questions WHERE tst_test_rnd_qst.active_fi = %s AND qpl_questions.question_id = tst_test_rnd_qst.question_fi AND tst_test_rnd_qst.pass = 0 ORDER BY sequence",
array('integer'),
array($this->active_id)
);
}
}
else
{
$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",
array('integer'),
array($this->active_id)
);
}
$index = 1;
while ($data = $ilDB->fetchAssoc($result))
{
$this->questions[$index++] = $data["question_fi"];
}
}
ilTestSequence::openQuestionExists ( )

Definition at line 586 of file class.ilTestSequence.php.

References getFirstSequence().

{
return $this->getFirstSequence() !== false;
}

+ Here is the call graph for this function:

ilTestSequence::pcArrayShuffle (   $array)

Shuffles the values of a given array.

Shuffles the values of a given array

Parameters
array$arrayAn array which should be shuffled public

Definition at line 439 of file class.ilTestSequence.php.

References $result.

Referenced by createNewSequence().

{
$keys = array_keys($array);
shuffle($keys);
$result = array();
foreach ($keys as $key)
{
$result[$key] = $array[$key];
}
return $result;
}

+ Here is the caller graph for this function:

ilTestSequence::postponeQuestion (   $question_id)

Definition at line 191 of file class.ilTestSequence.php.

References isPostponedQuestion().

{
if (!$this->isPostponedQuestion($question_id))
{
array_push($this->sequencedata["postponed"], intval($question_id));
}
}

+ Here is the call graph for this function:

ilTestSequence::postponeSequence (   $sequence)

Definition at line 261 of file class.ilTestSequence.php.

References isPostponedSequence().

{
if (!$this->isPostponedSequence($sequence))
{
if (array_key_exists($sequence, $this->questions))
{
if (!is_array($this->sequencedata["postponed"])) $this->sequencedata["postponed"] = array();
array_push($this->sequencedata["postponed"], intval($this->questions[$sequence]));
}
}
}

+ Here is the call graph for this function:

ilTestSequence::questionExists (   $questionId)

Definition at line 591 of file class.ilTestSequence.php.

{
return in_array($questionId, $this->questions);
}
ilTestSequence::saveToDb ( )

Saves the sequence data for a given pass to the database.

public

Definition at line 161 of file class.ilTestSequence.php.

Referenced by hideCorrectAnsweredQuestions().

{
global $ilDB;
$postponed = NULL;
if ((is_array($this->sequencedata["postponed"])) && (count($this->sequencedata["postponed"])))
{
$postponed = serialize($this->sequencedata["postponed"]);
}
$hidden = NULL;
if ((is_array($this->sequencedata["hidden"])) && (count($this->sequencedata["hidden"])))
{
$hidden = serialize($this->sequencedata["hidden"]);
}
$affectedRows = $ilDB->manipulateF("DELETE FROM tst_sequence WHERE active_fi = %s AND pass = %s",
array('integer','integer'),
array($this->active_id, $this->pass)
);
$affectedRows = $ilDB->insert("tst_sequence", array(
"active_fi" => array("integer", $this->active_id),
"pass" => array("integer", $this->pass),
"sequence" => array("clob", serialize($this->sequencedata["sequence"])),
"postponed" => array("text", $postponed),
"hidden" => array("text", $hidden),
"tstamp" => array("integer", time())
));
}

+ Here is the caller graph for this function:

ilTestSequence::setPass (   $pass)

Definition at line 515 of file class.ilTestSequence.php.

References $pass.

{
$this->pass = $pass;
}

Field Documentation

ilTestSequence::$active_id
ilTestSequence::$isRandomTest

Definition at line 48 of file class.ilTestSequence.php.

ilTestSequence::$questions

Definition at line 27 of file class.ilTestSequence.php.

Referenced by getOrderedSequenceQuestions().

ilTestSequence::$sequencedata

Definition at line 20 of file class.ilTestSequence.php.


The documentation for this class was generated from the following file: