diff --git a/exercises/cloze_exercise.php b/exercises/cloze_exercise.php index 7ba11cafcaa68ee5fb15c346238ca28898a24d42..3c6c9f3382c7a0a12e1dcc85e001d3df7c30b324 100644 --- a/exercises/cloze_exercise.php +++ b/exercises/cloze_exercise.php @@ -194,7 +194,7 @@ class cloze_exercise extends Exercise { $template = parent::getViewTemplate($view, $solution, $assignment, $user_id); - if ($solution) { + if ($solution && $solution->id) { $template->results = $this->evaluateItems($solution); } diff --git a/exercises/lt_exercise.php b/exercises/lt_exercise.php index 10646123685ecfdec14ea1358d2f9a6d9cb5ee8f..746f2724518d23cff12f1777996a9320f2f40e8d 100644 --- a/exercises/lt_exercise.php +++ b/exercises/lt_exercise.php @@ -235,7 +235,7 @@ class lt_exercise extends Exercise { $template = parent::getViewTemplate($view, $solution, $assignment, $user_id); - if ($solution) { + if ($solution && $solution->id) { $template->results = $this->evaluateItems($solution); } diff --git a/exercises/me_exercise.php b/exercises/me_exercise.php index 29c8c6ed0e5db06a49a332f2a434f77e89c9de8c..9aa2c70617e4007847bb9ffd5dfff0426ac96c35 100644 --- a/exercises/me_exercise.php +++ b/exercises/me_exercise.php @@ -195,7 +195,7 @@ class me_exercise extends Exercise { $template = parent::getViewTemplate($view, $solution, $assignment, $user_id); - if ($solution) { + if ($solution && $solution->id) { $template->results = $this->evaluateItems($solution); } diff --git a/exercises/seq_exercise.php b/exercises/seq_exercise.php index 2373dc03cc6fc6d12024ee0d999a8136e2087551..c4c478f353c0b28157d50b65a20c2b21e0c5eea0 100644 --- a/exercises/seq_exercise.php +++ b/exercises/seq_exercise.php @@ -193,7 +193,7 @@ class seq_exercise extends Exercise { $template = parent::getViewTemplate($view, $solution, $assignment, $user_id); - if ($solution) { + if ($solution && $solution->id) { $template->results = $this->evaluateItems($solution); } diff --git a/exercises/tb_exercise.php b/exercises/tb_exercise.php index 950c21de51f4b5a7cdaa675639ec76fe484dd7e2..67a22c89487761b8cae94f2e44f6846d0491134c 100644 --- a/exercises/tb_exercise.php +++ b/exercises/tb_exercise.php @@ -79,6 +79,14 @@ class tb_exercise extends Exercise } } + /** + * Return the layout of this task (text, markup, code or none). + */ + public function getLayout() + { + return isset($this->task['layout']) ? $this->task['layout'] : 'text'; + } + /** * Evaluates a student's solution for the individual items in this * exercise. Returns an array of ('points' => float, 'safe' => boolean). diff --git a/lib/DummyExercise.php b/lib/DummyExercise.php index 8868f8af2d93761cb44a543c787ab8790da937ad..b0e9f9c4c83cc5c7d3739ab8ffb50b1e29b8393c 100644 --- a/lib/DummyExercise.php +++ b/lib/DummyExercise.php @@ -42,7 +42,10 @@ class DummyExercise extends Exercise */ public function getEditTemplate($assignment) { - return $GLOBALS['template_factory']->open('shared/string'); + $template = $GLOBALS['template_factory']->open('shared/string'); + $template->content = ''; + + return $template; } /** @@ -50,6 +53,9 @@ class DummyExercise extends Exercise */ public function getViewTemplate($view, $solution, $assignment, $user_id) { - return $GLOBALS['template_factory']->open('shared/string'); + $template = $GLOBALS['template_factory']->open('shared/string'); + $template->content = ''; + + return $template; } } diff --git a/views/exercises/cloze_exercise/edit.php b/views/exercises/cloze_exercise/edit.php index 485cf97b72d5bc551628cc112c1e7ffe393bc902..000302a003d03ae35338b7d587de2f4bb8ecce2a 100644 --- a/views/exercises/cloze_exercise/edit.php +++ b/views/exercises/cloze_exercise/edit.php @@ -42,24 +42,20 @@ <label> <?= _vips('Art des Textvergleichs') ?> - <? if ($exercise->task['compare']): ?> - <? $checked[$exercise->task['compare']] = 'selected' ?> - <? endif ?> - <select name="compare" onchange="$(this).parent().next('label').toggle($(this).val() === 'numeric')"> <option value=""> <?= _vips('Groß-/Kleinschreibung unterscheiden') ?> </option> - <option value="ignorecase" <?= $checked['ignorecase'] ?>> + <option value="ignorecase" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'ignorecase' ? 'selected' : '' ?>> <?= _vips('Groß-/Kleinschreibung ignorieren') ?> </option> - <option value="numeric" <?= $checked['numeric'] ?>> + <option value="numeric" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'numeric' ? 'selected' : '' ?>> <?= _vips('Numerischer Wertevergleich (ggf. mit Einheit)') ?> </option> </select> </label> - <label style="<?= $checked['numeric'] ? '' : 'display: none;' ?>"> + <label style="<?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'numeric' ? '' : 'display: none;' ?>"> <?= _vips('Erlaubte relative Abweichung vom korrekten Wert') ?> <br> <input type="text" class="size-s" style="display: inline; text-align: right;" diff --git a/views/exercises/lt_exercise/edit.php b/views/exercises/lt_exercise/edit.php index f6beb31b8110c5efe06036d3409b0031c0ffb9ab..10deffa94308d9c00740a1940ad9c291927b46d5 100644 --- a/views/exercises/lt_exercise/edit.php +++ b/views/exercises/lt_exercise/edit.php @@ -70,27 +70,23 @@ <label> <?= _vips('Art des Textvergleichs') ?> - <? if ($exercise->task['compare']): ?> - <? $checked[$exercise->task['compare']] = 'selected' ?> - <? endif ?> - <select name="compare" onchange="$(this).parent().next('label').toggle($(this).val() === 'numeric')"> <option value=""> <?= _vips('Groß-/Kleinschreibung ignorieren') ?> </option> - <option value="levenshtein" <?= $checked['levenshtein'] ?>> + <option value="levenshtein" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'levenshtein' ? 'selected' : '' ?>> <?= _vips('Textähnlichkeit (Levenshtein-Distanz)') ?> </option> - <option value="soundex" <?= $checked['soundex'] ?>> + <option value="soundex" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'soundex' ? 'selected' : '' ?>> <?= _vips('Ähnlichkeit der Aussprache (Soundex)') ?> </option> - <option value="numeric" <?= $checked['numeric'] ?>> + <option value="numeric" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'numeric' ? 'selected' : '' ?>> <?= _vips('Numerischer Wertevergleich (ggf. mit Einheit)') ?> </option> </select> </label> -<label style="<?= $checked['numeric'] ? '' : 'display: none;' ?>"> +<label style="<?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'numeric' ? '' : 'display: none;' ?>"> <?= _vips('Erlaubte relative Abweichung vom korrekten Wert') ?> <br> <input type="text" class="size-s" style="display: inline; text-align: right;" diff --git a/views/exercises/seq_exercise/edit.php b/views/exercises/seq_exercise/edit.php index 08d27cb0d5868d3d0b4966c781bc7666982ff91c..9f08d7f1ecedee2ad694cd068b117c145824b412 100644 --- a/views/exercises/seq_exercise/edit.php +++ b/views/exercises/seq_exercise/edit.php @@ -35,18 +35,14 @@ <label> <?= _vips('Verfahren zur Punktevergabe') ?> - <? if ($exercise->task['compare']): ?> - <? $checked[$exercise->task['compare']] = 'selected' ?> - <? endif ?> - <select name="compare"> <option value=""> <?= _vips('Punkte nur bei vollständig korrekter Lösung') ?> </option> - <option value="position" <?= $checked['position'] ?>> + <option value="position" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'position' ? 'selected' : '' ?>> <?= _vips('Punkte für Antworten an den korrekten Positionen') ?> </option> - <option value="sequence" <?= $checked['sequence'] ?>> + <option value="sequence" <?= isset($exercise->task['compare']) && $exercise->task['compare'] === 'sequence' ? 'selected' : '' ?>> <?= _vips('Punkte für Paare von Antworten in korrekter Reihenfolge') ?> </option> </select> diff --git a/views/exercises/tb_exercise/edit.php b/views/exercises/tb_exercise/edit.php index c2ab8cb4e4495e9cc7e0272b4392a6470643177f..1071dcb9efa81e8e33b5983a620f7fe235879f3b 100644 --- a/views/exercises/tb_exercise/edit.php +++ b/views/exercises/tb_exercise/edit.php @@ -5,22 +5,22 @@ <option value=""> <?= _vips('Texteingabe - einfacher Text ohne Formatierungen') ?> </option> - <option value="markup" <? if ($exercise->task['layout'] === 'markup'): ?>selected<? endif ?>> + <option value="markup" <? if ($exercise->getLayout() === 'markup'): ?>selected<? endif ?>> <?= _vips('Texteingabe - Textformatierungen bei Eingabe der Lösung anbieten') ?> </option> - <option value="code" <? if ($exercise->task['layout'] === 'code'): ?>selected<? endif ?>> + <option value="code" <? if ($exercise->getLayout() === 'code'): ?>selected<? endif ?>> <?= _vips('Texteingabe - Programmcode (nichtproportionale Schriftart)') ?> </option> - <option value="none" <? if ($exercise->task['layout'] === 'none'): ?>selected<? endif ?>> + <option value="none" <? if ($exercise->getLayout() === 'none'): ?>selected<? endif ?>> <?= _vips('keine Texteingabe - nur Hochladen von Dateien erlauben') ?> </option> </select> </label> -<label class="none-hidden" style="<?= $exercise->task['layout'] === 'none' ? 'display: none;' : '' ?>"> +<label class="none-hidden" style="<?= $exercise->getLayout() === 'none' ? 'display: none;' : '' ?>"> <?= _vips('Vorgegebener Text im Antwortfeld') ?> <?= $this->render_partial('exercises/flexible_textarea', - ['name' => 'answer_default', 'value' => $exercise->task['template'], 'monospace' => $exercise->task['layout'] === 'code', 'wysiwyg' => $exercise->task['layout'] === 'markup']) ?> + ['name' => 'answer_default', 'value' => $exercise->task['template'], 'monospace' => $exercise->getLayout() === 'code', 'wysiwyg' => $exercise->getLayout() === 'markup']) ?> </label> <label> @@ -28,7 +28,7 @@ <textarea class="character_input size-l wysiwyg" name="answer_0" rows="<?= vips_textarea_size($exercise->task['answers'][0]['text']) ?>"><?= wysiwygReady($exercise->task['answers'][0]['text']) ?></textarea> </label> -<div class="none-hidden" style="<?= $exercise->task['layout'] === 'none' ? 'display: none;' : '' ?>"> +<div class="none-hidden" style="<?= $exercise->getLayout() === 'none' ? 'display: none;' : '' ?>"> <label> <?= _vips('Zeichenwähler') ?> diff --git a/views/exercises/tb_exercise/print.php b/views/exercises/tb_exercise/print.php index cf828523f4ee04dbdc61832e06ccdaf62f32e990..391c411a7cfcd312a62e7b49e4a825318fbf30f8 100644 --- a/views/exercises/tb_exercise/print.php +++ b/views/exercises/tb_exercise/print.php @@ -1,4 +1,4 @@ -<? if ($exercise->task['layout'] !== 'none'): ?> +<? if ($exercise->getLayout() !== 'none'): ?> <? if ($print_correction && $solution->commented_solution != '') : ?> <div class="label-text"> <?= _vips('Kommentierte Lösung:') ?> @@ -11,9 +11,9 @@ </div> <div class="vips_output"> - <? if ($exercise->task['layout'] === 'markup'): ?> + <? if ($exercise->getLayout() === 'markup'): ?> <?= formatReady($response[0]) ?> - <? elseif ($exercise->task['layout'] === 'code'): ?> + <? elseif ($exercise->getLayout() === 'code'): ?> <pre><?= htmlReady($response[0]) ?></pre> <? else: ?> <?= htmlReady($response[0], true, true) ?> @@ -25,9 +25,9 @@ </div> <? else : ?> <div class="vips_output" style="min-height: 30em;"> - <? if ($exercise->task['layout'] === 'markup'): ?> + <? if ($exercise->getLayout() === 'markup'): ?> <?= formatReady($exercise->task['template']) ?> - <? elseif ($exercise->task['layout'] === 'code'): ?> + <? elseif ($exercise->getLayout() === 'code'): ?> <pre><?= htmlReady($exercise->task['template']) ?></pre> <? else: ?> <?= htmlReady($exercise->task['template'], true, true) ?> diff --git a/views/sheets/print_assignment.php b/views/sheets/print_assignment.php index 684230f73e95df8f511a205f4f2317b8f27305e9..4fa307a79b1b6a2703eb5767cc57ea453df62aa7 100644 --- a/views/sheets/print_assignment.php +++ b/views/sheets/print_assignment.php @@ -50,6 +50,11 @@ <? $solution = $assignment->getSolution($user_id, $exercise->id); ?> <? endif ?> + <? if (!$solution): ?> + <? $solution = new VipsSolution(); ?> + <? $solution->assignment = $assignment; ?> + <? endif ?> + <?= $this->render_partial('exercises/print_exercise', [ 'exercise' => $exercise, 'exercise_position' => $i + 1,