Example #1
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;
                 }
             }
         }
     }
 }
 /**
  * Returns the previous reached points in a given pass
  *
  * @param string $sid Session ID
  * @param long $active_id Active user ID
  * @param integer $question_id Question ID
  * @param integer $pass Test pass
  *
  * @return array Reached points of the previous questions in this pass
  */
 function getPreviousReachedPoints($sid, $active_id, $question_id, $pass)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!$this->isAllowedCall($sid, $active_id, false)) {
         return $this->__raiseError("The required user information is only available for active users.", "");
     }
     global $lng, $ilDB;
     $result = $ilDB->queryF("SELECT tst_tests.random_test FROM tst_active, tst_tests WHERE tst_active.active_id = %s AND tst_tests.test_id = tst_active.test_fi", array('integer'), array($active_id));
     if ($result->numRows() != 1) {
         return -1;
     }
     $row = $ilDB->fetchAssoc($result);
     $is_random = $row["random_test"];
     include_once "./Modules/Test/classes/class.ilTestSequence.php";
     $sequence = new ilTestSequence($active_id, $pass, $is_random);
     $result = $ilDB->queryF("SELECT question_fi, points FROM tst_test_result WHERE active_fi = %s AND pass = %s", array('integer', 'integer'), array($active_id, $pass));
     $reachedpoints = array();
     while ($row = $ilDB->fetchAssoc($result)) {
         $reachedpoints[$row["question_fi"]] = $row["points"];
     }
     $atposition = FALSE;
     $pointsforposition = array();
     foreach ($sequence->getUserSequence() as $seq) {
         if (!$atposition) {
             $qid = $sequence->getQuestionForSequence($seq);
             if ($qid == $question_id) {
                 $atposition = TRUE;
             } else {
                 array_push($pointsforposition, $reachedpoints[$qid]);
             }
         }
     }
     return $pointsforposition;
 }