Skip to content

Commit

Permalink
TA: 37918, numeric question
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and kergomard committed Dec 16, 2024
1 parent 2a1588a commit 8169778
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 117 deletions.
22 changes: 11 additions & 11 deletions Modules/TestQuestionPool/classes/class.assClozeTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public function renderSolutionOutput(
$gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", true, true, "Modules/TestQuestionPool");
$found = [];
foreach ($user_solutions as $solutionarray) {
if ($solutionarray["value1"] == $gap_index) {
if ($solutionarray['value1'] == $gap_index) {
$found = $solutionarray;
}
}
Expand Down Expand Up @@ -1083,12 +1083,12 @@ public function renderSolutionOutput(
case CLOZE_TEXT:
$solutiontext = "";
if (($active_id > 0) && (!$show_correct_solution)) {
if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0)) {
if ((count($found) == 0) || (strlen(trim($found['value2'])) == 0)) {
for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
$solutiontext .= "&nbsp;";
}
} else {
$solutiontext = ilLegacyFormElementsUtil::prepareFormOutput($found["value2"]);
$solutiontext = ilLegacyFormElementsUtil::prepareFormOutput($found['value2']);
}
} else {
$solutiontext = $this-> getBestSolutionText($gap, $gap_index, $check_for_gap_combinations);
Expand All @@ -1101,12 +1101,12 @@ public function renderSolutionOutput(
case CLOZE_SELECT:
$solutiontext = "";
if (($active_id > 0) && (!$show_correct_solution)) {
if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0)) {
if ((count($found) == 0) || (strlen(trim($found['value2'])) == 0)) {
for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++) {
$solutiontext .= "&nbsp;";
}
} else {
$item = $gap->getItem($found["value2"]);
$item = $gap->getItem($found['value2']);
if (is_object($item)) {
$solutiontext = ilLegacyFormElementsUtil::prepareFormOutput($item->getAnswertext());
} else {
Expand Down Expand Up @@ -1251,9 +1251,9 @@ public function getTestOutput(

$gaptemplate->setVariable("GAP_COUNTER", $gap_index);
foreach ($user_solution as $solution) {
if (strcmp($solution["value1"], $gap_index) == 0) {
if (strcmp($solution['value1'], $gap_index) == 0) {
$gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilLegacyFormElementsUtil::prepareFormOutput(
$solution["value2"]
$solution['value2']
) . "\"");
}
}
Expand All @@ -1271,8 +1271,8 @@ public function getTestOutput(
ilLegacyFormElementsUtil::prepareFormOutput($item->getAnswerText())
);
foreach ($user_solution as $solution) {
if (strcmp($solution["value1"], $gap_index) == 0) {
if (strcmp($solution["value2"], $item->getOrder()) == 0) {
if (strcmp($solution['value1'], $gap_index) == 0) {
if (strcmp($solution['value2'], $item->getOrder()) == 0) {
$gaptemplate->setVariable("SELECT_GAP_SELECTED", " selected=\"selected\"");
}
}
Expand All @@ -1295,9 +1295,9 @@ public function getTestOutput(

$gaptemplate->setVariable("GAP_COUNTER", $gap_index);
foreach ($user_solution as $solution) {
if (strcmp($solution["value1"], $gap_index) == 0) {
if (strcmp($solution['value1'], $gap_index) == 0) {
$gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilLegacyFormElementsUtil::prepareFormOutput(
$solution["value2"]
$solution['value2']
) . "\"");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/TestQuestionPool/classes/class.assErrorTextGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function analyze(): void
* current errorText question object.
* @param integer $active_id The active test id
* @param integer $pass The test pass counter
* @param boolean $graphical_output Show visual feedback for right/wrong answers
* @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
Expand Down
66 changes: 31 additions & 35 deletions Modules/TestQuestionPool/classes/class.assFormulaQuestionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ protected function writePostData(bool $always = false): int
$this->object->setQuestion($this->request->string('question'));

$this->object->parseQuestionText();
$found_vars = array();
$found_results = array();
$found_vars = [];
$found_results = [];

foreach ($this->request->getParsedBody() as $key => $value) {
if (preg_match("/^unit_(\\\$v\d+)$/", $key, $matches)) {
Expand Down Expand Up @@ -189,7 +189,7 @@ public function resetSavedPreviewSession(): void
$user_id = $ilUser->getId();
$question_id = $this->object->getId();
$ilAssQuestionPreviewSession = new ilAssQuestionPreviewSession($user_id, $question_id);
$ilAssQuestionPreviewSession->setParticipantsSolution(array());
$ilAssQuestionPreviewSession->setParticipantsSolution([]);
}

public function isSaveCommand(): bool
Expand Down Expand Up @@ -225,7 +225,7 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$categorized_units = $this->object->getUnitrepository()->getCategorizedUnits();
$result_units = $this->object->getAllResultUnits();

$unit_options = array();
$unit_options = [];
$category_name = '';
$new_category = false;
foreach ($categorized_units as $item) {
Expand Down Expand Up @@ -302,8 +302,8 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$form->addItem($intprecision);
}
}
$quest_vars = array();
$result_vars = array();
$quest_vars = [];
$result_vars = [];
$results = $this->object->getResults();
if (count($results)) {
uasort($results, function (assFormulaQuestionResult $r1, assFormulaQuestionResult $r2) {
Expand Down Expand Up @@ -352,7 +352,7 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$range_max->setRequired(true);
$range_max->setValue($result->getRangeMax());

$matches = array();
$matches = [];

$precision = new ilNumberInputGUI($this->lng->txt('precision'), 'precision_' . $result->getResult());
$precision->setRequired(true);
Expand Down Expand Up @@ -382,7 +382,7 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$mc_result_units = new ilMultiSelectInputGUI($this->lng->txt('result_units'), 'units_' . $result->getResult());
$mc_result_units->setOptions($unit_options);
$mc_result_units->setInfo($this->lng->txt('result_units_info'));
$selectedvalues = array();
$selectedvalues = [];
foreach ($unit_options as $unit_id => $txt) {
if ($this->hasResultUnit($result, $unit_id, $result_units)) {
$selectedvalues[] = $unit_id;
Expand Down Expand Up @@ -470,9 +470,9 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$form->addItem($rating_type);
}

$defined_result_vars = array();
$defined_result_vars = [];

$defined_result_res = array();
$defined_result_res = [];

foreach ($variables as $key => $object) {
$quest_vars[$key] = $key;
Expand Down Expand Up @@ -552,8 +552,8 @@ public function editQuestion($checkonly = false, string $suggest_range_for_resul
$errors = $checked;

if ($save) {
$found_vars = array();
$found_results = array();
$found_vars = [];
$found_results = [];
foreach ($this->request->getParsedBody() as $key => $value) {
if (preg_match("/^unit_(\\\$v\d+)$/", $key, $matches)) {
array_push($found_vars, $matches[1]);
Expand Down Expand Up @@ -882,7 +882,7 @@ public function renderSolutionOutput(

public function getPreview($show_question_only = false, $showInlineFeedback = false): string
{
$user_solution = array();
$user_solution = [];

if (is_object($this->getPreviewSession())) {
$solutions = (array) $this->getPreviewSession()->getParticipantsSolution();
Expand All @@ -892,12 +892,12 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
$user_solution[$matches[1]] = $val2;
} elseif (preg_match("/^(\\\$r\\d+)$/", $val1, $matches)) {
if (!array_key_exists($matches[1], $user_solution)) {
$user_solution[$matches[1]] = array();
$user_solution[$matches[1]] = [];
}
$user_solution[$matches[1]]["value"] = $val2;
} elseif (preg_match("/^(\\\$r\\d+)_unit$/", $val1, $matches)) {
if (!array_key_exists($matches[1], $user_solution)) {
$user_solution[$matches[1]] = array();
$user_solution[$matches[1]] = [];
}
$user_solution[$matches[1]]["unit"] = $val2;
}
Expand All @@ -920,7 +920,7 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
if (is_object($this->getPreviewSession())) {
$questiontext = $this->object->substituteVariables($user_solution);
} else {
$questiontext = $this->object->substituteVariables(array());
$questiontext = $this->object->substituteVariables([]);
}
$template->setVariable("QUESTIONTEXT", ilLegacyFormElementsUtil::prepareTextareaOutput($questiontext, true));
$questionoutput = $template->get();
Expand All @@ -937,41 +937,37 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $use_pos
{
$this->tpl->setOnScreenMessage('info', $this->lng->txt('enter_valid_values'));
// get the solution of the user for the active pass or from the last pass if allowed
$user_solution = array();
$user_solution = [];
if ($active_id) {


$actualPassIndex = null;
if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
$actualPassIndex = ilObjTest::_getPass($active_id);
}


$solutions = [];
foreach ($this->object->getTestOutputSolutions($active_id, $pass) as $val1 => $val2) {
$solutions[] = array('value1' => $val1, 'value2' => $val2);
$solutions[] = ['value1' => $val1, 'value2' => $val2];
}

foreach ($solutions as $idx => $solution_value) {
if (preg_match("/^(\\\$v\\d+)$/", $solution_value["value1"], $matches)) {
if (preg_match("/^(\\\$v\\d+)$/", $solution_value['value1'], $matches)) {
if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
$this->object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value["value2"], true);
$this->object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value['value2'], true);
}

$user_solution[$matches[1]] = $solution_value["value2"];
} elseif (preg_match("/^(\\\$r\\d+)$/", $solution_value["value1"], $matches)) {
$user_solution[$matches[1]] = $solution_value['value2'];
} elseif (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]] = [];
}
$user_solution[$matches[1]]["value"] = $solution_value["value2"];
} elseif (preg_match("/^(\\\$r\\d+)_unit$/", $solution_value["value1"], $matches)) {
$user_solution[$matches[1]]["value"] = $solution_value['value2'];
} elseif (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]] = [];
}
$user_solution[$matches[1]]["unit"] = $solution_value["value2"];
$user_solution[$matches[1]]["unit"] = $solution_value['value2'];
}
if (preg_match("/^(\\\$r\\d+)/", $solution_value["value1"], $matches) && !isset($user_solution[$matches[1]]["result_type"])) {
$user_solution[$matches[1]]["result_type"] = assFormulaQuestionResult::getResultTypeByQstId($this->object->getId(), $solution_value["value1"]);
if (preg_match("/^(\\\$r\\d+)/", $solution_value['value1'], $matches) && !isset($user_solution[$matches[1]]["result_type"])) {
$user_solution[$matches[1]]["result_type"] = assFormulaQuestionResult::getResultTypeByQstId($this->object->getId(), $solution_value['value1']);
}
}
}
Expand All @@ -982,8 +978,8 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $use_pos
$solutions[] = array('value1' => $val1, 'value2' => $val2);
}
foreach ($solutions as $idx => $solution_value) {
if (preg_match("/^(\\\$v\\d+)$/", $solution_value["value1"], $matches)) {
$user_solution[$matches[1]] = $solution_value["value2"];
if (preg_match("/^(\\\$v\\d+)$/", $solution_value['value1'], $matches)) {
$user_solution[$matches[1]] = $solution_value['value2'];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ protected function completeTestOutputFormAction($formAction, $active_id, $pass)
$info = $this->object->getTestOutputSolutions($active_id, $pass);

if (count($info)) {
if ($info[0]["value1"] !== "") {
$formAction .= "&selImage=" . $info[0]["value1"];
if ($info[0]['value1'] !== "") {
$formAction .= "&selImage=" . $info[0]['value1'];
}
}

Expand Down Expand Up @@ -496,7 +496,7 @@ public function renderSolutionOutput(
if (is_array($user_solutions)) {
$preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->getImageFilename());
foreach ($user_solutions as $idx => $solution_value) {
$value1 = $solution_value["value1"];
$value1 = $solution_value['value1'];
if (
$value1 === '' ||
!isset($this->object->answers[$value1])
Expand Down Expand Up @@ -667,9 +667,9 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $use_pos
$preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->getImageFilename());

foreach ($solutions as $idx => $solution_value) {
if ($solution_value["value1"] !== null) {
$preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
$userSelection[$selectionIndex] = $solution_value["value1"];
if ($solution_value['value1'] !== null) {
$preview->addArea($solution_value['value1'], $this->object->answers[$solution_value['value1']]->getArea(), $this->object->answers[$solution_value['value1']]->getCoords(), $this->object->answers[$solution_value['value1']]->getAnswertext(), "", "", true, $this->linecolor);
$userSelection[$selectionIndex] = $solution_value['value1'];

$selectionIndex = $this->object->getIsMultipleChoice() ? ++$selectionIndex : $selectionIndex;
}
Expand Down
2 changes: 0 additions & 2 deletions Modules/TestQuestionPool/classes/class.assKprimChoiceGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ public function getSolutionOutput(
if (($active_id > 0) && (!$show_correct_solution)) {
$solutions = $this->object->getSolutionValues($active_id, $pass);
foreach ($solutions as $idx => $solution_value) {
//$user_solution[$solution_value['value1']] = $solution_value['value2'];
$user_solution[] = [
'value1' => $solution_value['value1'],
'value2' => $solution_value['value2']
Expand All @@ -578,7 +577,6 @@ public function getSolutionOutput(
} else {
// take the correct solution instead of the user solution
foreach ($this->object->getAnswers() as $answer) {
//$user_solution[$answer->getPosition()] = $answer->getCorrectness();
$user_solution[] = [
'value1' => $answer->getPosition(),
'value2' => $answer->getCorrectness()
Expand Down
24 changes: 2 additions & 22 deletions Modules/TestQuestionPool/classes/class.assLongMenuGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ public function __construct($id = -1)

}

/**
* @param $active_id
* @param $pass
* @return array
*/
/*
protected function getUserSolution($active_id, $pass): array
{
$user_solution = array();
if ($active_id) {
$solutions = $this->object->getSolutionValues($active_id, $pass, true);
// hey.
foreach ($solutions as $idx => $solution_value) {
$user_solution[$solution_value["value1"]] = $solution_value["value2"];
}
return $user_solution;
}
return $user_solution;
}*/

public function getCommand($cmd)
{
return $cmd;
Expand Down Expand Up @@ -410,7 +390,7 @@ public function renderSolutionOutput(

$user_solution = [];
foreach ($user_solutions as $idx => $solution_value) {
$user_solution[$solution_value["value1"]] = $solution_value["value2"];
$user_solution[$solution_value['value1']] = $solution_value['value2'];
}


Expand Down Expand Up @@ -479,7 +459,7 @@ public function getTestOutput(
if ($active_id) {
$solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
foreach ($solutions as $idx => $solution_value) {
$user_solution[$solution_value["value1"]] = $solution_value["value2"];
$user_solution[$solution_value['value1']] = $solution_value['value2'];
}
}

Expand Down
Loading

0 comments on commit 8169778

Please sign in to comment.