From 62816e38b1d5bbd1d0633dcc076eec9573a9cd1d Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Fri, 9 Aug 2024 12:55:12 +0200 Subject: [PATCH] don't grade empty responses, fixes #261 --- exercises/Exercise.php | 5 ++--- exercises/mco_exercise.php | 6 +++--- exercises/sc_exercise.php | 4 ++-- exercises/tb_exercise.php | 5 ++++- views/exercises/mco_exercise/correct.php | 6 +++--- views/exercises/mco_exercise/print.php | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/exercises/Exercise.php b/exercises/Exercise.php index 6d85b3e..ecfaf23 100644 --- a/exercises/Exercise.php +++ b/exercises/Exercise.php @@ -297,10 +297,10 @@ abstract class Exercise extends SimpleORMap foreach ($results as $item) { if ($item['points'] === 0) { ++$malus; + } else if ($item['points'] !== null) { + $points += $item['points']; } - $points += $item['points']; - if ($item['safe'] === null) { $safe = null; } else if ($safe !== null) { @@ -334,7 +334,6 @@ abstract class Exercise extends SimpleORMap * Return the response of the student from the request POST data. * * @param array $request array containing the postdata for the solution. - * @return array containing the solutions of the student. */ public function responseFromRequest($request) { diff --git a/exercises/mco_exercise.php b/exercises/mco_exercise.php index b39293d..0d15eac 100644 --- a/exercises/mco_exercise.php +++ b/exercises/mco_exercise.php @@ -126,10 +126,10 @@ class mco_exercise extends Exercise $response = $solution->response; foreach ($this->task['answers'] as $i => $answer) { - if ($response[$i] == '-1') { + if (!isset($response[$i]) || $response[$i] === '' || $response[$i] == -1) { $points = null; } else { - $points = $response[$i] == (string) $answer['choice'] ? 1 : 0; + $points = $response[$i] == $answer['choice'] ? 1 : 0; } $result[] = ['points' => $points, 'safe' => true]; @@ -248,6 +248,6 @@ class mco_exercise extends Exercise */ public function exportResponse($response) { - return array_map(function($a) { return $a == '-1' ? '' : $a; }, $response); + return array_map(function($a) { return $a == -1 ? '' : $a; }, $response); } } diff --git a/exercises/sc_exercise.php b/exercises/sc_exercise.php index b19a27d..4335df0 100644 --- a/exercises/sc_exercise.php +++ b/exercises/sc_exercise.php @@ -136,7 +136,7 @@ class sc_exercise extends Exercise $response = $solution->response; foreach ($this->task as $i => $task) { - if ($response[$i] == '-1') { + if (!isset($response[$i]) || $response[$i] === '' || $response[$i] == -1) { $points = null; } else { $points = $task['answers'][$response[$i]]['score']; @@ -258,6 +258,6 @@ class sc_exercise extends Exercise */ public function exportResponse($response) { - return array_map(function($a) { return $a == '-1' ? '' : $a; }, $response); + return array_map(function($a) { return $a == -1 ? '' : $a; }, $response); } } diff --git a/exercises/tb_exercise.php b/exercises/tb_exercise.php index 27d1678..de245ff 100644 --- a/exercises/tb_exercise.php +++ b/exercises/tb_exercise.php @@ -142,7 +142,10 @@ class tb_exercise extends Exercise public function responseFromRequest($request) { $result = parent::responseFromRequest($request); - $result = array_map('Studip\Markup::purifyHtml', $result); + + if ($this->getLayout() === 'markup') { + $result = array_map('Studip\Markup::purifyHtml', $result); + } return $result; } diff --git a/views/exercises/mco_exercise/correct.php b/views/exercises/mco_exercise/correct.php index 54d3e3b..a063927 100644 --- a/views/exercises/mco_exercise/correct.php +++ b/views/exercises/mco_exercise/correct.php @@ -6,10 +6,10 @@ </td> <td style="white-space: nowrap;"> - <? if ($solution->id): ?> - <? if ($response[$key] == (string) $entry['choice']): ?> + <? if (isset($response[$key]) && $response[$key] !== '' && $response[$key] != -1): ?> + <? if ($response[$key] == $entry['choice']): ?> <?= Icon::create('accept', 'status-green', ['class' => 'correction_marker', 'title' => _vips('richtig')]) ?> - <? elseif ($response[$key] != -1): ?> + <? else: ?> <?= Icon::create('decline', 'status-red', ['class' => 'correction_marker', 'title' => _vips('falsch')]) ?> <? endif ?> <? endif ?> diff --git a/views/exercises/mco_exercise/print.php b/views/exercises/mco_exercise/print.php index 67a0601..82dee70 100644 --- a/views/exercises/mco_exercise/print.php +++ b/views/exercises/mco_exercise/print.php @@ -6,10 +6,10 @@ </td> <td style="white-space: nowrap;"> - <? if ($solution->id && $print_correction): ?> + <? if (isset($response[$key]) && $response[$key] !== '' && $response[$key] != -1 && $print_correction): ?> <? if ($response[$key] == $entry['choice']): ?> <?= Icon::create('accept', 'status-green', ['class' => 'correction_marker', 'title' => _vips('richtig')]) ?> - <? elseif ($response[$key] != -1): ?> + <? else: ?> <?= Icon::create('decline', 'status-red', ['class' => 'correction_marker', 'title' => _vips('falsch')]) ?> <? endif ?> <? endif ?> -- GitLab