diff --git a/exercises/Exercise.php b/exercises/Exercise.php index 6d85b3ef06f8bac302edffd79f05f1800061e034..ecfaf23eefe0c59e76bda65cdee93111c2841fb0 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 b39293de4110d50c26b99d2b9827524b8364472f..0d15eac7c5013a175232f5ea743f3a4f021e7a3c 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 b19a27d95583ebd5d0b13177ee1665eb2a61040b..4335df0af000e8293b0caf72d72e15f120cc315b 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 27d16786e42e2749a78d146e8b8f15c2562e5a9d..de245ffc75a3362231fbf4c32d7f4e1ea590519b 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 54d3e3be489b2d3b022bed02ec6508216b6e5f22..a0639277305e56fa97a9703f6f8ded32bc32ffc0 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 67a0601879e3c3e503efc641773395f6c020de0a..82dee70e9fba750d7ec1ebe48109c900eedf5704 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 ?>