/**
  * Returns the points, a learner has reached answering the question
  * The points are calculated from the given answers.
  * 
  * @param integer $user_id The database ID of the learner
  * @param integer $test_id The database Id of the test containing the question
  * @access public
  */
 function calculateReachedPoints($active_id, $pass = NULL, $returndetails = false)
 {
     if (is_null($pass)) {
         $pass = $this->getSolutionMaxPass($active_id);
     }
     $solutions =& $this->getSolutionValues($active_id, $pass);
     $user_solution = array();
     foreach ($solutions as $idx => $solution_value) {
         if (preg_match("/^(\\\$v\\d+)\$/", $solution_value["value1"], $matches)) {
             $user_solution[$matches[1]] = $solution_value["value2"];
             $varObj = $this->getVariable($solution_value["value1"]);
             $varObj->setValue($solution_value["value2"]);
         } else {
             if (preg_match("/^(\\\$r\\d+)\$/", $solution_value["value1"], $matches)) {
                 if (!array_key_exists($matches[1], $user_solution)) {
                     $user_solution[$matches[1]] = array();
                 }
                 $user_solution[$matches[1]]["value"] = $solution_value["value2"];
             } else {
                 if (preg_match("/^(\\\$r\\d+)_unit\$/", $solution_value["value1"], $matches)) {
                     if (!array_key_exists($matches[1], $user_solution)) {
                         $user_solution[$matches[1]] = array();
                     }
                     $user_solution[$matches[1]]["unit"] = $solution_value["value2"];
                 }
             }
         }
     }
     $points = 0;
     foreach ($this->getResults() as $result) {
         $points += $result->getReachedPoints($this->getVariables(), $this->getResults(), $user_solution[$result->getResult()]["value"], $user_solution[$result->getResult()]["unit"], $this->unitrepository->getUnits());
     }
     return $points;
 }
Exemplo n.º 2
0
 public function calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
 {
     $user_solution = $previewSession->getParticipantsSolution();
     $points = 0;
     foreach ($this->getResults() as $result) {
         $points += $result->getReachedPoints($this->getVariables(), $this->getResults(), $user_solution[$result->getResult()], $user_solution[$result->getResult() . '_unit'], $this->unitrepository->getUnits());
     }
     return $points;
 }