/**
  * creates and returns an instance of a test sequence
  * that corresponds to the current test mode
  * 
  * @param integer $activeId
  * @return ilTestSession|ilTestSessionDynamicQuestionSet
  */
 public function getSession($activeId = null)
 {
     global $ilUser;
     if (self::$testSession === null) {
         switch ($this->testOBJ->getQuestionSetType()) {
             case ilObjTest::QUESTION_SET_TYPE_FIXED:
             case ilObjTest::QUESTION_SET_TYPE_RANDOM:
                 global $ilUser;
                 require_once 'Modules/Test/classes/class.ilTestSession.php';
                 self::$testSession = new ilTestSession();
                 break;
             case ilObjTest::QUESTION_SET_TYPE_DYNAMIC:
                 require_once 'Modules/Test/classes/class.ilTestSessionDynamicQuestionSet.php';
                 self::$testSession = new ilTestSessionDynamicQuestionSet();
                 break;
         }
         self::$testSession->setRefId($this->testOBJ->getRefId());
         self::$testSession->setTestId($this->testOBJ->getTestId());
         if ($activeId) {
             self::$testSession->loadFromDb($activeId);
         } else {
             self::$testSession->loadTestSession($this->testOBJ->getTestId(), $ilUser->getId(), $_SESSION["tst_access_code"][$this->testOBJ->getTestId()]);
         }
     }
     return self::$testSession;
 }
Exemplo n.º 2
0
 function createRandomSolutions($number)
 {
     global $ilDB;
     // 1. get a user
     $query = "SELECT usr_id FROM usr_data";
     $result = $ilDB->query($query);
     while ($data = $ilDB->fetchAssoc($result)) {
         $activequery = sprintf("SELECT user_fi FROM tst_active WHERE test_fi = %s AND user_fi = %s", $ilDB->quote($this->getTestId()), $ilDB->quote($data['usr_id']));
         $activeresult = $ilDB->query($activequery);
         if ($activeresult->numRows() == 0) {
             $user_id = $data['usr_id'];
             if ($user_id != 13) {
                 include_once "./Modules/Test/classes/class.ilTestSession.php";
                 $testSession = FALSE;
                 $testSession = new ilTestSession();
                 $testSession->setRefId($this->getRefId());
                 $testSession->setTestId($this->getTestId());
                 $testSession->setUserId($user_id);
                 $testSession->saveToDb();
                 $passes = $this->getNrOfTries() ? $this->getNrOfTries() : 10;
                 $nr_of_passes = rand(1, $passes);
                 $active_id = $testSession->getActiveId();
                 for ($pass = 0; $pass < $nr_of_passes; $pass++) {
                     include_once "./Modules/Test/classes/class.ilTestSequence.php";
                     $testSequence = new ilTestSequence($active_id, $pass, $this->isRandomTest());
                     if (!$testSequence->hasSequence()) {
                         $testSequence->createNewSequence($this->getQuestionCount(), $shuffle);
                         $testSequence->saveToDb();
                     }
                     for ($seq = 1; $seq <= count($this->questions); $seq++) {
                         $question_id = $testSequence->getQuestionForSequence($seq);
                         $objQuestion = ilObjTest::_instanciateQuestion($question_id);
                         $objQuestion->createRandomSolution($testSession->getActiveId(), $pass);
                     }
                     if ($pass < $nr_of_passes - 1) {
                         $testSession->increasePass();
                         $testSession->setLastSequence(0);
                         $testSession->saveToDb();
                     } else {
                         $testSession->setSubmitted(1);
                         $testSession->setSubmittedTimestamp(date('Y-m-d H:i:s'));
                         $testSession->saveToDb();
                     }
                 }
                 $number--;
                 if ($number == 0) {
                     return;
                 }
             }
         }
     }
 }