public function getCleanCombinationArray($question_id)
 {
     $assClozeGapCombinationObj = new assClozeGapCombination();
     $combination_from_db = $assClozeGapCombinationObj->loadFromDb($question_id);
     $clean_array = array();
     foreach ($combination_from_db as $key => $value) {
         $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['answer'] = $value['answer'];
         $clean_array[$value['cid']][$value['row_id']]['points'] = $value['points'];
         $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['type'] = $value['type'];
     }
     return $clean_array;
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $packageIliasVersion = $item->getIliasSourceVersion('ILIAS_VERSION');
     $seperate_question_field = $item->getMetadataEntry("question");
     $questiontext = null;
     if (!$packageIliasVersion || version_compare($packageIliasVersion, '5.0.0', '<')) {
         $questiontext = '&nbsp';
     } elseif ($seperate_question_field) {
         $questiontext = $this->processNonAbstractedImageReferences($seperate_question_field, $item->getIliasSourceNic());
     }
     $clozetext = array();
     $shuffle = 0;
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $gaps = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "material":
                 $materialString = $this->object->QTIMaterialToString($presentation->material[$entry["index"]]);
                 if ($questiontext === null) {
                     $questiontext = $materialString;
                 } else {
                     array_push($clozetext, $materialString);
                 }
                 break;
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 array_push($clozetext, "<<" . $response->getIdent() . ">>");
                 switch (strtolower(get_class($response->getRenderType()))) {
                     case "ilqtirenderfib":
                         switch ($response->getRenderType()->getFibtype()) {
                             case FIBTYPE_DECIMAL:
                             case FIBTYPE_INTEGER:
                                 array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_NUMERIC, "answers" => array(), "minnumber" => $response->getRenderType()->getMinnumber(), "maxnumber" => $response->getRenderType()->getMaxnumber(), 'gap_size' => $response->getRenderType()->getColumns()));
                                 break;
                             default:
                             case FIBTYPE_STRING:
                                 array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_TEXT, "answers" => array(), 'gap_size' => $response->getRenderType()->getColumns()));
                                 break;
                         }
                         break;
                     case "ilqtirenderchoice":
                         $answers = array();
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             foreach ($response_label->material as $mat) {
                                 $answertext .= $this->object->QTIMaterialToString($mat);
                             }
                             $answers[$ident] = array("answertext" => $answertext, "points" => 0, "answerorder" => $answerorder++, "action" => "", "shuffle" => $rendertype->getShuffle());
                         }
                         array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_SELECT, "shuffle" => $rendertype->getShuffle(), "answers" => $answers));
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $ident = "";
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varequal":
                         $equals = $conditionvar->varequal[$order["index"]]->getContent();
                         $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 if (strcmp($gapident, "") != 0) {
                     foreach ($gaps as $gi => $g) {
                         if (strcmp($g["ident"], $gapident) == 0) {
                             if ($g["type"] == CLOZE_SELECT) {
                                 foreach ($gaps[$gi]["answers"] as $ai => $answer) {
                                     if (strcmp($answer["answertext"], $equals) == 0) {
                                         $gaps[$gi]["answers"][$ai]["action"] = $setvar->getAction();
                                         $gaps[$gi]["answers"][$ai]["points"] = $setvar->getContent();
                                     }
                                 }
                             } else {
                                 if ($g["type"] == CLOZE_TEXT) {
                                     array_push($gaps[$gi]["answers"], array("answertext" => $equals, "points" => $setvar->getContent(), "answerorder" => count($gaps[$gi]["answers"]), "action" => $setvar->getAction()));
                                 } else {
                                     if ($g["type"] == CLOZE_NUMERIC) {
                                         array_push($gaps[$gi]["answers"], array("answertext" => $equals, "points" => $setvar->getContent(), "answerorder" => count($gaps[$gi]["answers"]), "action" => $setvar->getAction()));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (count($respcondition->displayfeedback)) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacks[$ifb->getIdent()] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacks[$ifb->getIdent()] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $textgap_rating = $item->getMetadataEntry("textgaprating");
     $this->object->setFixedTextLength($item->getMetadataEntry("fixedTextLength"));
     $this->object->setIdenticalScoring($item->getMetadataEntry("identicalScoring"));
     $combination = json_decode(base64_decode($item->getMetadataEntry("combinations")));
     if (strlen($textgap_rating) == 0) {
         $textgap_rating = "ci";
     }
     $this->object->setTextgapRating($textgap_rating);
     $gaptext = array();
     foreach ($gaps as $gapidx => $gap) {
         $gapcontent = array();
         include_once "./Modules/TestQuestionPool/classes/class.assClozeGap.php";
         $clozegap = new assClozeGap($gap["type"]);
         foreach ($gap["answers"] as $index => $answer) {
             include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
             $gapanswer = new assAnswerCloze($answer["answertext"], $answer["points"], $answer["answerorder"]);
             $gapanswer->setGapSize($gap["gap_size"]);
             switch ($clozegap->getType()) {
                 case CLOZE_SELECT:
                     $clozegap->setShuffle($answer["shuffle"]);
                     break;
                 case CLOZE_NUMERIC:
                     $gapanswer->setLowerBound($gap["minnumber"]);
                     $gapanswer->setUpperBound($gap["maxnumber"]);
                     break;
             }
             $clozegap->setGapSize($gap["gap_size"]);
             $clozegap->addItem($gapanswer);
             array_push($gapcontent, $answer["answertext"]);
         }
         $this->object->addGapAtIndex($clozegap, $gapidx);
         $gaptext[$gap["ident"]] = "[gap]" . join(",", $gapcontent) . "[/gap]";
     }
     $this->object->setQuestion($questiontext);
     $clozetext = join("", $clozetext);
     foreach ($gaptext as $idx => $val) {
         $clozetext = str_replace("<<" . $idx . ">>", $val, $clozetext);
     }
     $this->object->setClozeTextValue($clozetext);
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     // handle the import of media objects in XHTML code
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     $clozetext = $this->object->getClozeText();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             $clozetext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $clozetext);
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     $this->object->setClozeTextValue(ilRTE::_replaceMediaObjectImageSrc($clozetext, 1));
     foreach ($feedbacks as $ident => $material) {
         $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
     $this->object->saveToDb();
     if (count($combination) > 0) {
         require_once './Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
         assClozeGapCombination::clearGapCombinationsFromDb($this->object->getId());
         assClozeGapCombination::importGapCombinationToDb($this->object->getId(), $combination);
     }
     $this->object->saveToDb();
 }
示例#3
0
 /**
  * Get the question solution output
  *
  * @param integer $active_id             The active user id
  * @param integer $pass                  The test pass
  * @param boolean $graphicalOutput       Show visual feedback for right/wrong answers
  * @param boolean $result_output         Show the reached points for parts of the question
  * @param boolean $show_question_only    Show the question without the ILIAS content around
  * @param boolean $show_feedback         Show the question feedback
  * @param boolean $show_correct_solution Show the correct solution instead of the user solution
  * @param boolean $show_manual_scoring   Show specific information for the manual scoring output
  * @param bool    $show_question_text
  *
  * @return string The solution output of the question as HTML code
  */
 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE, $show_manual_scoring = FALSE, $show_question_text = TRUE)
 {
     // get the solution of the user for the active pass or from the last pass if allowed
     $user_solution = array();
     if ($active_id > 0 && !$show_correct_solution) {
         // get the solutions of a user
         $user_solution =& $this->object->getSolutionValues($active_id, $pass);
         if (!is_array($user_solution)) {
             $user_solution = array();
         }
     }
     include_once "./Services/UICore/classes/class.ilTemplate.php";
     $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
     $output = $this->object->getClozeText();
     foreach ($this->object->getGaps() as $gap_index => $gap) {
         $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", TRUE, TRUE, "Modules/TestQuestionPool");
         $found = array();
         foreach ($user_solution as $solutionarray) {
             if ($solutionarray["value1"] == $gap_index) {
                 $found = $solutionarray;
             }
         }
         if ($active_id) {
             if ($graphicalOutput) {
                 // output of ok/not ok icons for user entered solutions
                 $details = $this->object->calculateReachedPoints($active_id, $pass, TRUE);
                 $check = $details[$gap_index];
                 $assClozeGapCombinationObject = new assClozeGapCombination();
                 $check_for_gap_combinations = $assClozeGapCombinationObject->loadFromDb($this->object->getId());
                 if (count($check_for_gap_combinations) != 0) {
                     $gaps_used_in_combination = $assClozeGapCombinationObject->getGapsWhichAreUsedInCombination($this->object->getId());
                     $custom_user_solution = array();
                     if (array_key_exists($gap_index, $gaps_used_in_combination)) {
                         $combination_id = $gaps_used_in_combination[$gap_index];
                         foreach ($gaps_used_in_combination as $key => $value) {
                             $a = 0;
                             if ($value == $combination_id) {
                                 foreach ($user_solution as $solution_key => $solution_value) {
                                     if ($solution_value['value1'] == $key) {
                                         $result_row = array();
                                         $result_row['gap_id'] = $solution_value['value1'];
                                         $result_row['value'] = $solution_value['value2'];
                                         array_push($custom_user_solution, $result_row);
                                     }
                                 }
                             }
                         }
                         $points_array = $this->object->calculateCombinationResult($custom_user_solution);
                         $max_combination_points = $assClozeGapCombinationObject->getMaxPointsForCombination($this->object->getId(), $combination_id);
                         if ($points_array[0] == $max_combination_points) {
                             $gaptemplate->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
                             $gaptemplate->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
                         } else {
                             if ($points_array[0] > 0) {
                                 $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
                                 $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
                             } else {
                                 $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
                                 $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
                             }
                         }
                     } else {
                         if ($check["best"]) {
                             $gaptemplate->setCurrentBlock("icon_ok");
                             $gaptemplate->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
                             $gaptemplate->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
                             $gaptemplate->parseCurrentBlock();
                         } else {
                             $gaptemplate->setCurrentBlock("icon_not_ok");
                             if ($check["positive"]) {
                                 $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
                                 $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
                             } else {
                                 $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
                                 $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
                             }
                             $gaptemplate->parseCurrentBlock();
                         }
                     }
                 } else {
                     if ($check["best"]) {
                         $gaptemplate->setCurrentBlock("icon_ok");
                         $gaptemplate->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
                         $gaptemplate->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
                         $gaptemplate->parseCurrentBlock();
                     } else {
                         $gaptemplate->setCurrentBlock("icon_not_ok");
                         if ($check["positive"]) {
                             $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
                             $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
                         } else {
                             $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
                             $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
                         }
                         $gaptemplate->parseCurrentBlock();
                     }
                 }
             }
         }
         if ($result_output) {
             $points = $this->object->getMaximumGapPoints($gap_index);
             $resulttext = $points == 1 ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
             $gaptemplate->setCurrentBlock("result_output");
             $gaptemplate->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
             $gaptemplate->parseCurrentBlock();
         }
         switch ($gap->getType()) {
             case CLOZE_TEXT:
                 $solutiontext = "";
                 if ($active_id > 0 && !$show_correct_solution) {
                     if (count($found) == 0 || strlen(trim($found["value2"])) == 0) {
                         for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
                             $solutiontext .= "&nbsp;";
                         }
                     } else {
                         $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
                     }
                 } else {
                     $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
                 }
                 $gaptemplate->setVariable("SOLUTION", $solutiontext);
                 $output = preg_replace("/\\[gap\\].*?\\[\\/gap\\]/", $gaptemplate->get(), $output, 1);
                 break;
             case CLOZE_SELECT:
                 $solutiontext = "";
                 if ($active_id > 0 && !$show_correct_solution) {
                     if (count($found) == 0 || strlen(trim($found["value2"])) == 0) {
                         for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
                             $solutiontext .= "&nbsp;";
                         }
                     } else {
                         $item = $gap->getItem($found["value2"]);
                         if (is_object($item)) {
                             $solutiontext = ilUtil::prepareFormOutput($item->getAnswertext());
                         } else {
                             for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
                                 $solutiontext .= "&nbsp;";
                             }
                         }
                     }
                 } else {
                     $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
                 }
                 $gaptemplate->setVariable("SOLUTION", $solutiontext);
                 $output = preg_replace("/\\[gap\\].*?\\[\\/gap\\]/", $gaptemplate->get(), $output, 1);
                 break;
             case CLOZE_NUMERIC:
                 $solutiontext = "";
                 if ($active_id > 0 && !$show_correct_solution) {
                     if (count($found) == 0 || strlen(trim($found["value2"])) == 0) {
                         for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
                             $solutiontext .= "&nbsp;";
                         }
                     } else {
                         $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
                     }
                 } else {
                     $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
                 }
                 $gaptemplate->setVariable("SOLUTION", $solutiontext);
                 $output = preg_replace("/\\[gap\\].*?\\[\\/gap\\]/", $gaptemplate->get(), $output, 1);
                 break;
         }
     }
     if ($show_question_text) {
         $template->setVariable("QUESTIONTEXT", $this->object->getQuestion());
     }
     $template->setVariable("CLOZETEXT", $this->object->prepareTextareaOutput($output, TRUE));
     // generate the question output
     $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
     $questionoutput = $template->get();
     $feedback = '';
     if ($show_feedback) {
         $fb = $this->getGenericFeedbackOutput($active_id, $pass);
         $feedback .= strlen($fb) ? $fb : '';
         $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
         $feedback .= strlen($fb) ? $fb : '';
     }
     if (strlen($feedback)) {
         $solutiontemplate->setVariable("FEEDBACK", $feedback);
     }
     $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
     $solutionoutput = $solutiontemplate->get();
     $assClozeGapCombinationObject = new assClozeGapCombination();
     $check_for_gap_combinations = $assClozeGapCombinationObject->loadFromDb($this->object->getId());
     if (count($check_for_gap_combinations) != 0) {
         $solutionoutput .= '<i>Best Combination is: ' . $assClozeGapCombinationObject->getBestSolutionCombination($this->object->getId()) . '</i>';
     }
     if (!$show_question_only) {
         // get page object output
         $solutionoutput = $this->getILIASPage($solutionoutput);
     }
     return $solutionoutput;
 }
示例#4
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;
 }