Example #1
0
 public function populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
 {
     if (self::OLD_CLOZE_TEST_UI) {
         for ($gapCounter = 0; $gapCounter < $this->object->getGapCount(); $gapCounter++) {
             $this->populateGapFormPart($form, $gapCounter);
         }
         return $form;
     } else {
         require_once 'Modules/TestQuestionPool/classes/Form/class.ilClozeGapInputBuilderGUI.php';
         $json = $this->populateJSON();
         $assClozeGapCombinationObject = new assClozeGapCombination();
         $combination_exists = $assClozeGapCombinationObject->combinationExistsForQid($this->object->id);
         if ($combination_exists) {
             $combinations = $assClozeGapCombinationObject->loadFromDb($this->object->id);
         }
         $new_builder = new ilClozeGapInputBuilderGUI();
         $header = new ilFormSectionHeaderGUI();
         $form->addItem($header);
         $new_builder->setValueByArray($json);
         $new_builder->setValueCombinationFromDb($combinations);
         $form->addItem($new_builder);
         return $form;
     }
 }
Example #2
0
 /**
  * @param $user_result
  * @param $detailed
  * @return array
  */
 protected function calculateReachedPointsForSolution($user_result, &$detailed = null)
 {
     if ($detailed === null) {
         $detailed = array();
     }
     $assClozeGapCombinationObj = new assClozeGapCombination();
     $combinations[1] = array();
     if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) {
         $combinations = $this->calculateCombinationResult($user_result);
         $points = $combinations[0];
     }
     $counter = 0;
     $solution_values_text = array();
     // for identical scoring checks
     $solution_values_select = array();
     // for identical scoring checks
     $solution_values_numeric = array();
     // for identical scoring checks
     foreach ($user_result as $gap_id => $value) {
         if (is_string($value)) {
             $value = array("value" => $value);
         }
         if (array_key_exists($gap_id, $this->gaps) && !array_key_exists($gap_id, $combinations[1])) {
             switch ($this->gaps[$gap_id]->getType()) {
                 case CLOZE_TEXT:
                     $gappoints = 0;
                     for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
                         $answer = $this->gaps[$gap_id]->getItem($order);
                         $gotpoints = $this->getTextgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints());
                         if ($gotpoints > $gappoints) {
                             $gappoints = $gotpoints;
                         }
                     }
                     if (!$this->getIdenticalScoring()) {
                         // check if the same solution text was already entered
                         if (in_array($value["value"], $solution_values_text) && $gappoints > 0) {
                             $gappoints = 0;
                         }
                     }
                     $points += $gappoints;
                     $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE);
                     array_push($solution_values_text, $value["value"]);
                     break;
                 case CLOZE_NUMERIC:
                     $gappoints = 0;
                     for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
                         $answer = $this->gaps[$gap_id]->getItem($order);
                         $gotpoints = $this->getNumericgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
                         if ($gotpoints > $gappoints) {
                             $gappoints = $gotpoints;
                         }
                     }
                     if (!$this->getIdenticalScoring()) {
                         // check if the same solution value was already entered
                         include_once "./Services/Math/classes/class.EvalMath.php";
                         $eval = new EvalMath();
                         $eval->suppress_errors = TRUE;
                         $found_value = FALSE;
                         foreach ($solution_values_numeric as $solval) {
                             if ($eval->e($solval) == $eval->e($value["value"])) {
                                 $found_value = TRUE;
                             }
                         }
                         if ($found_value && $gappoints > 0) {
                             $gappoints = 0;
                         }
                     }
                     $points += $gappoints;
                     $detailed[$gap_id] = array("points" => $gappoints, "best" => $this->getMaximumGapPoints($gap_id) == $gappoints ? TRUE : FALSE, "positive" => $gappoints > 0 ? TRUE : FALSE);
                     array_push($solution_values_numeric, $value["value"]);
                     break;
                 case CLOZE_SELECT:
                     if ($value["value"] >= 0) {
                         for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
                             $answer = $this->gaps[$gap_id]->getItem($order);
                             if ($value["value"] == $answer->getOrder()) {
                                 $answerpoints = $answer->getPoints();
                                 if (!$this->getIdenticalScoring()) {
                                     // check if the same solution value was already entered
                                     if (in_array($answer->getAnswertext(), $solution_values_select) && $answerpoints > 0) {
                                         $answerpoints = 0;
                                     }
                                 }
                                 $points += $answerpoints;
                                 $detailed[$gap_id] = array("points" => $answerpoints, "best" => $this->getMaximumGapPoints($gap_id) == $answerpoints ? TRUE : FALSE, "positive" => $answerpoints > 0 ? TRUE : FALSE);
                                 array_push($solution_values_select, $answer->getAnswertext());
                             }
                         }
                     }
                     break;
             }
         }
     }
     return $points;
 }