Skip to content
Snippets Groups Projects
Commit e53a71e5 authored by Viktoria Wiebe's avatar Viktoria Wiebe
Browse files

fix error when saving solution and remove unnecessary function

parent cc244f80
No related branches found
No related tags found
No related merge requests found
...@@ -102,7 +102,7 @@ class ls_exercise extends Exercise ...@@ -102,7 +102,7 @@ class ls_exercise extends Exercise
foreach ($request['answer'] as $group => $answers) { foreach ($request['answer'] as $group => $answers) {
foreach ($answers as $i => $answer) { foreach ($answers as $i => $answer) {
$result[$group][$i] = (int) trim($answer['score']); $result[$group][$i] = (int) trim($answer);
} }
} }
...@@ -123,29 +123,6 @@ class ls_exercise extends Exercise ...@@ -123,29 +123,6 @@ class ls_exercise extends Exercise
return $count; return $count;
} }
/**
* Shuffle the answer alternatives.
*
* @param $user_id is used for initialising the randomizer.
*/
function shuffleAnswers($user_id)
{
srand(crc32($this->id . ':' . $user_id));
for ($block = 0; $block < count($this->task); $block++) {
$random_order = range(0, count($this->task[$block]['answers']) - 1);
shuffle($random_order);
$answer_temp = [];
foreach ($random_order as $index) {
$answer_temp[$index] = $this->task[$block]['answers'][$index];
}
$this->task[$block]['answers'] = $answer_temp;
}
srand();
}
/** /**
* Returns true if this exercise type is considered as multiple choice. * Returns true if this exercise type is considered as multiple choice.
* In this case, the evaluation mode set on the assignment is applied. * In this case, the evaluation mode set on the assignment is applied.
...@@ -168,7 +145,7 @@ class ls_exercise extends Exercise ...@@ -168,7 +145,7 @@ class ls_exercise extends Exercise
foreach ($response as $group => $answers) { foreach ($response as $group => $answers) {
foreach ($answers as $i => $answer) { foreach ($answers as $i => $answer) {
$result[] = ['points' => $answer, 'safe' => true]; $result[] = ['points' => $this->task['scalepoints'][$answer], 'safe' => true];
} }
} }
...@@ -212,7 +189,7 @@ class ls_exercise extends Exercise ...@@ -212,7 +189,7 @@ class ls_exercise extends Exercise
foreach ($this->task['group'] as $i => $task) { foreach ($this->task['group'] as $i => $task) {
foreach ($task['answers'] as $j => $answer) { foreach ($task['answers'] as $j => $answer) {
$category = $answer['category']; $category = $answer['category'];
$result[$category] += $response[$i][$j]; $result[$category] += $this->task['scalepoints'][$response[$i][$j]];
} }
} }
return $result; return $result;
...@@ -318,8 +295,7 @@ class ls_exercise extends Exercise ...@@ -318,8 +295,7 @@ class ls_exercise extends Exercise
function getEditTemplate($assignment) function getEditTemplate($assignment)
{ {
if (!$this->task) { if (!$this->task) {
// TODO do I need this twice? In init and here? Maybe remove in init? $this->task['scale'] = 5;
$this->task['scale'] = 4;
$this->task['labels'] = ['0' => '']; $this->task['labels'] = ['0' => ''];
$this->task['scalepoints'] = array_fill(0, 4, 1); $this->task['scalepoints'] = array_fill(0, 4, 1);
$this->task['group'][0]['answers'] = array_fill(0, 5, ['text' => '', 'score' => 2, 'category' => 1]); $this->task['group'][0]['answers'] = array_fill(0, 5, ['text' => '', 'score' => 2, 'category' => 1]);
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
<td><?= htmlReady($entry['text']) ?></td> <td><?= htmlReady($entry['text']) ?></td>
<? for ($i = 0; $i < $exercise->task['scale']; $i++): ?> <? for ($i = 0; $i < $exercise->task['scale']; $i++): ?>
<td style="text-align: center;"> <td style="text-align: center;">
<input type="radio" name="answer[<?= $group ?>][<?= $key ?>]" value="<?= htmlReady($exercise->task['scalepoints'][$i]) ?>" <input type="radio" name="answer[<?= $group ?>][<?= $key ?>]" value="<?= $i ?>"
<? if($response[$group][$key] == $i): ?>checked<? endif ?>> <? if($response[$group][$key] === $i): ?>checked<? endif ?>>
</td> </td>
<? endfor ?> <? endfor ?>
</tr> </tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment