Skip to content

Commit

Permalink
0026494: Bug in gap questions with mixed string and numeric text fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbecker-databay committed Nov 23, 2020
1 parent c43cab4 commit b0159e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Modules/Test/classes/class.ilTestOutputGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public function saveQuestionSolution($authorized = true, $force = false)
}
}

if ($this->saveResult == false) {
if ($this->saveResult == false || (!$questionOBJ->validateSolutionSubmit() && $questionOBJ->savePartial()) ) {
$this->ctrl->setParameter($this, "save_error", "1");
$_SESSION["previouspost"] = $_POST;
}
Expand Down
38 changes: 35 additions & 3 deletions Modules/TestQuestionPool/classes/class.assClozeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ protected function isValidNumericSubmitValue($submittedValue)

public function validateSolutionSubmit()
{
foreach ($this->getSolutionSubmit() as $gapIndex => $value) {
foreach ($this->getSolutionSubmitValidation() as $gapIndex => $value) {
$gap = $this->getGap($gapIndex);

if ($gap->getType() != CLOZE_NUMERIC) {
Expand All @@ -1284,7 +1284,9 @@ public function fetchSolutionSubmit($submit)
$gap = $this->getGap($matches[1]);
if (is_object($gap)) {
if (!(($gap->getType() == CLOZE_SELECT) && ($value == -1))) {
if ($gap->getType() == CLOZE_NUMERIC) {
if ($gap->getType() == CLOZE_NUMERIC && !is_numeric(str_replace(",", ".", $value))) {
$value = null;
} else if ($gap->getType() == CLOZE_NUMERIC) {
$value = str_replace(",", ".", $value);
}
$solutionSubmit[trim($matches[1])] = $value;
Expand All @@ -1296,7 +1298,32 @@ public function fetchSolutionSubmit($submit)

return $solutionSubmit;
}


public function getSolutionSubmitValidation()
{
$submit = $_POST;
$solutionSubmit = array();

foreach ($submit as $key => $value) {
if (preg_match("/^gap_(\d+)/", $key, $matches)) {
$value = ilUtil::stripSlashes($value, false);
if (strlen($value)) {
$gap = $this->getGap($matches[1]);
if (is_object($gap)) {
if (!(($gap->getType() == CLOZE_SELECT) && ($value == -1))) {
if ($gap->getType() == CLOZE_NUMERIC) {
$value = str_replace(",", ".", $value);
}
$solutionSubmit[trim($matches[1])] = $value;
}
}
}
}
}

return $solutionSubmit;
}

public function getSolutionSubmit()
{
return $this->fetchSolutionSubmit($_POST);
Expand Down Expand Up @@ -1951,4 +1978,9 @@ public function addAnswerOptionValue($qIndex, $answerOptionValue, $points)

$gap->addItem($item);
}

public function savePartial()
{
return true;
}
}
7 changes: 6 additions & 1 deletion Modules/TestQuestionPool/classes/class.assQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ final public function calculateResultsFromSolution($active_id, $pass = null, $ob
*/
final public function persistWorkingState($active_id, $pass = null, $obligationsEnabled = false, $authorized = true)
{
if (!$this->validateSolutionSubmit()) {
if (!$this->validateSolutionSubmit() && !$this->savePartial()) {
return false;
}

Expand Down Expand Up @@ -5479,4 +5479,9 @@ protected function buildTestPresentationConfig()
}
// hey.
// fau.

public function savePartial()
{
return false;
}
}

0 comments on commit b0159e8

Please sign in to comment.