diff --git a/components/ILIAS/TestQuestionPool/classes/class.assNumeric.php b/components/ILIAS/TestQuestionPool/classes/class.assNumeric.php index b51987a8ffef..e4c2112db134 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assNumeric.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assNumeric.php @@ -199,8 +199,8 @@ public function contains($value): bool public function validateSolutionSubmit(): bool { - if ($this->getSolutionSubmit() === null) { - $this->tpl->setOnScreenMessage('failure', $this->lng->txt("err_no_numeric_value"), true); + if ($this->getRawSolutionSubmit() !== '' && $this->getSolutionSubmit() === null) { + $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_no_numeric_value'), true); return false; } @@ -209,7 +209,13 @@ public function validateSolutionSubmit(): bool protected function getSolutionSubmit(): ?float { - return $this->questionpool_request->float('numeric_result') ?? null; + $numeric_result = $this->getRawSolutionSubmit(); + return is_numeric($numeric_result) ? (float) $numeric_result : null; + } + + private function getRawSolutionSubmit(): string + { + return $this->questionpool_request->string('numeric_result'); } public function isValidSolutionSubmit($numeric_solution): bool @@ -228,33 +234,27 @@ public function saveWorkingData( ?int $pass = null, bool $authorized = true ): bool { - if (is_null($pass)) { - $pass = ilObjTest::_getPass($active_id); - } + $pass ??= ilObjTest::_getPass($active_id); $answer = $this->getSolutionSubmit(); $this->getProcessLocker()->executeUserSolutionUpdateLockOperation( - function () use ($answer, $active_id, $pass, $authorized) { + function () use ($answer, $active_id, $pass, $authorized): void { $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized); $update = -1; if ($this->db->numRows($result) !== 0) { - $row = $this->db->fetchAssoc($result); - $update = $row['solution_id']; + $update = $this->db->fetchAssoc($result)['solution_id']; } - if ($update !== -1 - && $answer === '') { - $this->removeSolutionRecordById($update); - return; - } - if ($update !== -1) { - $this->updateCurrentSolution($update, $answer, null, $authorized); + if ($update === -1) { + if ($answer !== null) { + $this->saveCurrentSolution($active_id, $pass, $answer, null, $authorized); + } return; } - if ($answer !== '') { - $this->saveCurrentSolution($active_id, $pass, $answer, null, $authorized); - } + $answer === null + ? $this->removeSolutionRecordById($update) + : $this->updateCurrentSolution($update, $answer, null, $authorized); } );