Exemple #1
0
 /**
  * Calculates the question results from a previously saved question solution
  *
  * @final
  * @global ilDB $ilDB
  * @global ilObjUser $ilUser
  * @param integer $active_id Active id of the user
  * @param integer $pass Test pass
  */
 public final function calculateResultsFromSolution($active_id, $pass = NULL, $obligationsEnabled = false)
 {
     global $ilDB, $ilUser;
     if (is_null($pass)) {
         include_once "./Modules/Test/classes/class.ilObjTest.php";
         $pass = ilObjTest::_getPass($active_id);
     }
     // determine reached points for submitted solution
     $reached_points = $this->calculateReachedPoints($active_id, $pass);
     // deduct points for requested hints from reached points
     require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
     $questionHintTracking = new ilAssQuestionHintTracking($this->getId(), $active_id, $pass);
     $requestsStatisticData = $questionHintTracking->getRequestStatisticDataByQuestionAndTestpass();
     $reached_points = $reached_points - $requestsStatisticData->getRequestsPoints();
     // adjust reached points regarding to tests scoring options
     $reached_points = $this->adjustReachedPointsByScoringOptions($reached_points, $active_id, $pass);
     if ($obligationsEnabled && ilObjTest::isQuestionObligatory($this->getId())) {
         $isAnswered = $this->isAnswered($active_id, $pass);
     } else {
         $isAnswered = true;
     }
     if (is_null($reached_points)) {
         $reached_points = 0;
     }
     $this->getProcessLocker()->requestUserQuestionResultUpdateLock();
     $query = "\n\t\t\tDELETE FROM\t\ttst_test_result\n\t\t\t\n\t\t\tWHERE\t\t\tactive_fi = %s\n\t\t\tAND\t\t\t\tquestion_fi = %s\n\t\t\tAND\t\t\t\tpass = %s\n\t\t";
     $types = array('integer', 'integer', 'integer');
     $values = array($active_id, $this->getId(), $pass);
     if ($this->getStep() !== NULL) {
         $query .= "\n\t\t\t\tAND\t\t\t\tstep = %s\n\t\t\t";
         $types[] = 'integer';
         $values[] = $this->getStep();
     }
     $affectedRows = $ilDB->manipulateF($query, $types, $values);
     $next_id = $ilDB->nextId("tst_test_result");
     $fieldData = array('test_result_id' => array('integer', $next_id), 'active_fi' => array('integer', $active_id), 'question_fi' => array('integer', $this->getId()), 'pass' => array('integer', $pass), 'points' => array('float', $reached_points), 'tstamp' => array('integer', time()), 'hint_count' => array('integer', $requestsStatisticData->getRequestsCount()), 'hint_points' => array('float', $requestsStatisticData->getRequestsPoints()), 'answered' => array('integer', $isAnswered));
     if ($this->getStep() !== NULL) {
         $fieldData['step'] = array('integer', $this->getStep());
     }
     $ilDB->insert('tst_test_result', $fieldData);
     $this->getProcessLocker()->releaseUserQuestionResultUpdateLock();
     include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
     if (ilObjAssessmentFolder::_enabledAssessmentLogging()) {
         $this->logAction(sprintf($this->lng->txtlng("assessment", "log_user_answered_question", ilObjAssessmentFolder::_getLogLanguage()), $reached_points), $active_id, $this->getId());
     }
     // update test pass results
     $this->_updateTestPassResults($active_id, $pass, $obligationsEnabled, $this->getProcessLocker());
     // Update objective status
     include_once 'Modules/Course/classes/class.ilCourseObjectiveResult.php';
     ilCourseObjectiveResult::_updateObjectiveResult($ilUser->getId(), $active_id, $this->getId());
 }