Public Member Functions | Data Fields | Protected Member Functions | Private Member Functions

ilTestSequence Class Reference
[Modules/Test]

Test sequence handler. More...

Public Member Functions

 ilTestSequence ($active_id, $pass, $randomtest)
 ilTestSequence constructor
 getActiveId ()
 createNewSequence ($max, $shuffle)
 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 ()
 getUserSequence ()
 getSequenceForQuestion ($question_id)
 getFirstSequence ()
 getLastSequence ()
 getNextSequence ($sequence)
 getPreviousSequence ($sequence)
 pcArrayShuffle ($array)
 Shuffles the values of a given array.
 getQuestionForSequence ($sequence)
getSequenceSummary ()
 getPass ()
 setPass ($pass)
 hasSequence ()
 hasHiddenQuestions ()
 clearHiddenQuestions ()

Data Fields

 $sequencedata
 $questions
 $active_id
 $pass
 $isRandomTest

Protected Member Functions

 getCorrectedSequence ($with_hidden_questions=FALSE)

Private Member Functions

 loadQuestions ()
 Loads the question mapping.
 loadFromDb ()
 Loads the sequence data for a given active id.

Detailed Description

Test sequence handler.

This class manages the sequence settings for a given user

Author:
Helmut Schottmüller <helmut.schottmueller@mac.com>
Version:
Id:
class.ilTestSequence.php 15137 2007-10-30 11:52:06Z hschottm

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


Member Function Documentation

ilTestSequence::clearHiddenQuestions (  ) 

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

        {
                $this->sequencedata["hidden"] = array();
        }

ilTestSequence::createNewSequence ( max,
shuffle 
)

Definition at line 108 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 103 of file class.ilTestSequence.php.

        {
                return $this->active_id;
        }

ilTestSequence::getCorrectedSequence ( with_hidden_questions = FALSE  )  [protected]

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

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

        {
                $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 397 of file class.ilTestSequence.php.

References getCorrectedSequence().

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

Here is the call graph for this function:

ilTestSequence::getLastSequence (  ) 

Definition at line 410 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 423 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 342 of file class.ilTestSequence.php.

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

ilTestSequence::getPass (  ) 

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

        {
                return $this->pass;
        }

ilTestSequence::getPositionOfSequence ( sequence  ) 

Definition at line 323 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 438 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 482 of file class.ilTestSequence.php.

Referenced by getSequenceSummary().

        {
                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 392 of file class.ilTestSequence.php.

        {
                return array_search($question_id, $this->questions);
        }

& ilTestSequence::getSequenceSummary (  ) 

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

References ilObjTest::_getSolvedQuestions(), ilObjTest::_instanciateQuestion(), getCorrectedSequence(), getQuestionForSequence(), and isPostponedQuestion().

        {
                $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)
                {
                        $question =& ilObjTest::_instanciateQuestion($this->getQuestionForSequence($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
                                );
                                array_push($result_array, $row);
                                $key++;
                        }
                }
                return $result_array;
        }

Here is the call graph for this function:

ilTestSequence::getUserQuestionCount (  ) 

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

References getCorrectedSequence().

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

Here is the call graph for this function:

ilTestSequence::getUserSequence (  ) 

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

References getCorrectedSequence().

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

Here is the call graph for this function:

ilTestSequence::hasHiddenQuestions (  ) 

Definition at line 556 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 544 of file class.ilTestSequence.php.

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

ilTestSequence::hideQuestion ( question_id  ) 

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

References isHiddenQuestion().

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

Here is the call graph for this function:

ilTestSequence::hideSequence ( sequence  ) 

Definition at line 311 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_object A reference to the test container object public

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

References $active_id, $pass, loadFromDb(), and loadQuestions().

        {
                $this->active_id = $active_id;
                $this->pass = $pass;
                $this->isRandomTest = $randomtest;
                $this->sequencedata = array(
                                "sequence" => array(),
                                "postponed" => array(),
                                "hidden" => array()
                        );
                $this->loadFromDb();
                $this->loadQuestions();
        }

Here is the call graph for this function:

ilTestSequence::isHiddenQuestion ( question_id  ) 

Definition at line 258 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 285 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 245 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 271 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 (  )  [private]

Loads the sequence data for a given active id.

Returns the filesystem path of the certificate

Returns:
string The filesystem path of the certificate private

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

Referenced by ilTestSequence().

        {
                global $ilDB;
                $query = sprintf("SELECT * FROM tst_sequence WHERE active_fi = %s AND pass = %s", 
                        $ilDB->quote($this->active_id . ""),
                        $ilDB->quote($this->pass . "")
                );
                $result = $ilDB->query($query);
                if ($result->numRows())
                {
                        $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
                        $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();
                }
        }

Here is the caller graph for this function:

ilTestSequence::loadQuestions (  )  [private]

Loads the question mapping.

Loads the question mapping

private

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

References $data.

Referenced by ilTestSequence().

        {
                global $ilDB;

                $this->questions = array();
                if ($this->isRandomTest)
                {
                        $query = sprintf("SELECT tst_test_random_question.* FROM tst_test_random_question, qpl_questions WHERE tst_test_random_question.active_fi = %s AND qpl_questions.question_id = tst_test_random_question.question_fi AND tst_test_random_question.pass = %s ORDER BY sequence",
                                $ilDB->quote($this->active_id . ""),
                                $ilDB->quote($this->pass . "")
                        );
                        $result = $ilDB->query($query);
                        // 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_random_question 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)
                        {
                                $query = sprintf("SELECT tst_test_random_question.* FROM tst_test_random_question, qpl_questions WHERE tst_test_random_question.active_fi = %s AND qpl_questions.question_id = tst_test_random_question.question_fi AND tst_test_random_question.pass = 0 ORDER BY sequence",
                                        $ilDB->quote($this->active_id . "")
                                );
                                $result = $ilDB->query($query);
                        }
                }
                else
                {
                        $query = sprintf("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",
                                $ilDB->quote($this->active_id . "")
                        );
                        $result = $ilDB->query($query);
                }
                $index = 1;
                while ($data = $result->fetchRow(DB_FETCHMODE_ASSOC))
                {
                        $this->questions[$index++] = $data["question_fi"];
                }
        }

Here is the caller graph for this function:

ilTestSequence::pcArrayShuffle ( array  ) 

Shuffles the values of a given array.

Shuffles the values of a given array

Parameters:
array $array An array which should be shuffled public

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

Referenced by createNewSequence().

        {
                mt_srand((double)microtime()*1000000);
                $i = count($array);
                if ($i > 0)
                {
                        while(--$i)
                        {
                                $j = mt_rand(0, $i);
                                if ($i != $j)
                                {
                                        // swap elements
                                        $tmp = $array[$j];
                                        $array[$j] = $array[$i];
                                        $array[$i] = $tmp;
                                }
                        }
                }
                return $array;
        }

Here is the caller graph for this function:

ilTestSequence::postponeQuestion ( question_id  ) 

Definition at line 229 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 299 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::saveToDb (  ) 

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

Saves the sequence data for a given pass to the database

public

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

        {
                global $ilDB;
                
                $postponed = "NULL";
                if ((is_array($this->sequencedata["postponed"])) && (count($this->sequencedata["postponed"])))
                {
                        $postponed = $ilDB->quote(serialize($this->sequencedata["postponed"]));
                }
                $hidden = "NULL";
                if ((is_array($this->sequencedata["hidden"])) && (count($this->sequencedata["hidden"])))
                {
                        $hidden = $ilDB->quote(serialize($this->sequencedata["hidden"]));
                }
                
                $query = sprintf("REPLACE INTO tst_sequence (active_fi, pass, sequence, postponed, hidden) VALUES (%s, %s, %s, %s, %s)",
                        $ilDB->quote($this->active_id . ""),
                        $ilDB->quote($this->pass . ""),
                        $ilDB->quote(serialize($this->sequencedata["sequence"])),
                        $postponed,
                        $hidden
                );
                $result = $ilDB->query($query);
        }

ilTestSequence::setPass ( pass  ) 

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

References $pass.

        {
                $this->pass = $pass;
        }


Field Documentation

ilTestSequence::$active_id

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

Referenced by ilTestSequence().

ilTestSequence::$isRandomTest

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

ilTestSequence::$pass

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

Referenced by ilTestSequence(), and setPass().

ilTestSequence::$questions

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

ilTestSequence::$sequencedata

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


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