/** * 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 .= " "; } } 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 .= " "; } } else { $item = $gap->getItem($found["value2"]); if (is_object($item)) { $solutiontext = ilUtil::prepareFormOutput($item->getAnswertext()); } else { for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) { $solutiontext .= " "; } } } } 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 .= " "; } } 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; }
/** * Returns the maximum points, a learner can reach answering the question * * @access public * @see $points */ function getMaximumPoints() { $assClozeGapCombinationObj = new assClozeGapCombination(); $points = 0; $gaps_used_in_combination = array(); if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) { $points = $assClozeGapCombinationObj->getMaxPointsForCombination($this->getId()); $gaps_used_in_combination = $assClozeGapCombinationObj->getGapsWhichAreUsedInCombination($this->getId()); } foreach ($this->gaps as $gap_index => $gap) { if (!array_key_exists($gap_index, $gaps_used_in_combination)) { if ($gap->getType() == CLOZE_TEXT) { $gap_max_points = 0; foreach ($gap->getItems() as $item) { if ($item->getPoints() > $gap_max_points) { $gap_max_points = $item->getPoints(); } } $points += $gap_max_points; } else { if ($gap->getType() == CLOZE_SELECT) { $srpoints = 0; foreach ($gap->getItems() as $item) { if ($item->getPoints() > $srpoints) { $srpoints = $item->getPoints(); } } $points += $srpoints; } else { if ($gap->getType() == CLOZE_NUMERIC) { $numpoints = 0; foreach ($gap->getItems() as $item) { if ($item->getPoints() > $numpoints) { $numpoints = $item->getPoints(); } } $points += $numpoints; } } } } } return $points; }