Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions components/ILIAS/TestQuestionPool/classes/class.assNumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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);
}
);

Expand Down