Skip to content
Snippets Groups Projects
Commit 3a9b4941 authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

don't grade empty responses, fixes #261

parent 2028806a
No related branches found
No related tags found
No related merge requests found
...@@ -297,9 +297,9 @@ abstract class Exercise extends SimpleORMap ...@@ -297,9 +297,9 @@ abstract class Exercise extends SimpleORMap
foreach ($results as $item) { foreach ($results as $item) {
if ($item['points'] === 0) { if ($item['points'] === 0) {
++$malus; ++$malus;
} } else if ($item['points'] !== null) {
$points += $item['points']; $points += $item['points'];
}
if ($item['safe'] === null) { if ($item['safe'] === null) {
$safe = null; $safe = null;
...@@ -334,7 +334,6 @@ abstract class Exercise extends SimpleORMap ...@@ -334,7 +334,6 @@ abstract class Exercise extends SimpleORMap
* Return the response of the student from the request POST data. * Return the response of the student from the request POST data.
* *
* @param array $request array containing the postdata for the solution. * @param array $request array containing the postdata for the solution.
* @return array containing the solutions of the student.
*/ */
public function responseFromRequest($request) public function responseFromRequest($request)
{ {
......
...@@ -126,10 +126,10 @@ class mco_exercise extends Exercise ...@@ -126,10 +126,10 @@ class mco_exercise extends Exercise
$response = $solution->response; $response = $solution->response;
foreach ($this->task['answers'] as $i => $answer) { foreach ($this->task['answers'] as $i => $answer) {
if ($response[$i] == '-1') { if (!isset($response[$i]) || $response[$i] === '' || $response[$i] == -1) {
$points = null; $points = null;
} else { } else {
$points = $response[$i] == (string) $answer['choice'] ? 1 : 0; $points = $response[$i] == $answer['choice'] ? 1 : 0;
} }
$result[] = ['points' => $points, 'safe' => true]; $result[] = ['points' => $points, 'safe' => true];
...@@ -248,6 +248,6 @@ class mco_exercise extends Exercise ...@@ -248,6 +248,6 @@ class mco_exercise extends Exercise
*/ */
public function exportResponse($response) public function exportResponse($response)
{ {
return array_map(function($a) { return $a == '-1' ? '' : $a; }, $response); return array_map(function($a) { return $a == -1 ? '' : $a; }, $response);
} }
} }
...@@ -136,7 +136,7 @@ class sc_exercise extends Exercise ...@@ -136,7 +136,7 @@ class sc_exercise extends Exercise
$response = $solution->response; $response = $solution->response;
foreach ($this->task as $i => $task) { foreach ($this->task as $i => $task) {
if ($response[$i] == '-1') { if (!isset($response[$i]) || $response[$i] === '' || $response[$i] == -1) {
$points = null; $points = null;
} else { } else {
$points = $task['answers'][$response[$i]]['score']; $points = $task['answers'][$response[$i]]['score'];
...@@ -258,6 +258,6 @@ class sc_exercise extends Exercise ...@@ -258,6 +258,6 @@ class sc_exercise extends Exercise
*/ */
public function exportResponse($response) public function exportResponse($response)
{ {
return array_map(function($a) { return $a == '-1' ? '' : $a; }, $response); return array_map(function($a) { return $a == -1 ? '' : $a; }, $response);
} }
} }
...@@ -142,7 +142,10 @@ class tb_exercise extends Exercise ...@@ -142,7 +142,10 @@ class tb_exercise extends Exercise
public function responseFromRequest($request) public function responseFromRequest($request)
{ {
$result = parent::responseFromRequest($request); $result = parent::responseFromRequest($request);
if ($this->getLayout() === 'markup') {
$result = array_map('Studip\Markup::purifyHtml', $result); $result = array_map('Studip\Markup::purifyHtml', $result);
}
return $result; return $result;
} }
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
</td> </td>
<td style="white-space: nowrap;"> <td style="white-space: nowrap;">
<? if ($solution->id): ?> <? if (isset($response[$key]) && $response[$key] !== '' && $response[$key] != -1): ?>
<? if ($response[$key] == (string) $entry['choice']): ?> <? if ($response[$key] == $entry['choice']): ?>
<?= Icon::create('accept', 'status-green', ['class' => 'correction_marker', 'title' => _vips('richtig')]) ?> <?= 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')]) ?> <?= Icon::create('decline', 'status-red', ['class' => 'correction_marker', 'title' => _vips('falsch')]) ?>
<? endif ?> <? endif ?>
<? endif ?> <? endif ?>
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
</td> </td>
<td style="white-space: nowrap;"> <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']): ?> <? if ($response[$key] == $entry['choice']): ?>
<?= Icon::create('accept', 'status-green', ['class' => 'correction_marker', 'title' => _vips('richtig')]) ?> <?= 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')]) ?> <?= Icon::create('decline', 'status-red', ['class' => 'correction_marker', 'title' => _vips('falsch')]) ?>
<? endif ?> <? endif ?>
<? endif ?> <? endif ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment