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;
 }
Example #2
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;
 }
Example #3
0
 function copyGapCombination($orgID, $newID)
 {
     $assClozeGapCombinationObj = new assClozeGapCombination();
     $array = $assClozeGapCombinationObj->loadFromDb($orgID);
     $assClozeGapCombinationObj->importGapCombinationToDb($newID, $array);
 }