diff --git a/controllers/api.php b/controllers/api.php index 5e7933283e59212f42e6d5b62b7be0fcc06dbef4..207dbb1ec11c7fb0e6255371dfebc89dd97e7b28 100644 --- a/controllers/api.php +++ b/controllers/api.php @@ -24,8 +24,7 @@ class ApiController extends StudipController foreach ($assignments as $assignment) { if ($assignment->type !== 'exam') { $data[] = [ - 'id' => $assignment->id, - 'link' => $this->url_for('api/assignment', $assignment->id), + 'id' => (int) $assignment->id, 'title' => $assignment->test->title, 'type' => $assignment->type, 'icon' => $assignment->getTypeIcon()->getShape(), @@ -63,7 +62,7 @@ class ApiController extends StudipController } $data = [ - 'id' => $assignment->id, + 'id' => (int) $assignment->id, 'title' => $assignment->test->title, 'type' => $assignment->type, 'icon' => $assignment->getTypeIcon()->getShape(), @@ -82,8 +81,7 @@ class ApiController extends StudipController $exercise = $exercise_ref->exercise; $data['exercises'][] = [ - 'id' => $exercise->id, - 'link' => $this->url_for('api/exercise', $assignment_id, $exercise->id), + 'id' => (int) $exercise->id, 'type' => $exercise->type, 'title' => $exercise->title, 'template' => $template->render(), @@ -122,7 +120,7 @@ class ApiController extends StudipController $exercise = $exercise_ref->exercise; $data = [ - 'id' => $exercise->id, + 'id' => (int) $exercise->id, 'type' => $exercise->type, 'title' => $exercise->title, 'template' => $template->render(), @@ -140,6 +138,7 @@ class ApiController extends StudipController $solution = $assignment->getSolution($user_id, $exercise->id); $max_tries = $assignment->getMaxTries(); $max_points = $exercise_ref->points; + $sample_solution = false; $show_solution = false; $tries_left = null; diff --git a/js/test-block.js b/js/test-block.js index 25efc11b24855d151ff6127e38a4dd450bb273a6..c03bdae2e4844019503441c526d03f3cc76dda0f 100644 --- a/js/test-block.js +++ b/js/test-block.js @@ -84,7 +84,9 @@ const CoursewareTestBlock = { </template> <template #selected-option="{title, icon, start, end}"> <studip-icon :shape="icon" role="info"/> - {{title}} ({{start}} - {{end}}) + <template v-if="title"> + {{title}} ({{start}} - {{end}}) + </template> </template> <template #option="{title, icon, start, end, block}"> <studip-icon :shape="icon" role="info"/> @@ -115,7 +117,7 @@ const CoursewareTestBlock = { data() { return { assignments: [], - assignment_id: '', + assignment_id: 0, assignment: null, errorMessage: null, exercises: [], @@ -163,7 +165,7 @@ const CoursewareTestBlock = { }); }, loadSelectedAssignment() { - if (this.assignment_id === '') { + if (!this.assignment_id) { this.errorMessage = this.$gettext('Es wurde noch kein Aufgabenblatt ausgewählt.'); return; } diff --git a/lib/TestBlock.php b/lib/TestBlock.php index 031f5f199a4bc74d7a668db918c4a2540288a216..290246a3f358cd987e07af3ed321ed429323118e 100644 --- a/lib/TestBlock.php +++ b/lib/TestBlock.php @@ -64,7 +64,7 @@ class TestBlock extends BlockType */ public function initialPayload(): array { - return ['assignment' => '']; + return ['assignment' => 0]; } /** @@ -76,7 +76,7 @@ class TestBlock extends BlockType 'type' => 'object', 'properties' => [ 'assignment' => [ - 'type' => 'string' + 'type' => 'integer' ] ] ]; @@ -108,6 +108,17 @@ class TestBlock extends BlockType return []; } + /** + * Returns the decoded payload of the block associated with this instance. + */ + public function getPayload() + { + $payload = parent::getPayload(); + $payload['assignment'] = (int) $payload['assignment']; + + return $payload; + } + /** * Copy the payload of this block into the given range id. */ diff --git a/views/exercises/courseware_block.php b/views/exercises/courseware_block.php index 8212b78b38f4fc607fdb8938f813b0780e94cd26..31534558cb4a88ddf82a46bd0630b647509cb513 100644 --- a/views/exercises/courseware_block.php +++ b/views/exercises/courseware_block.php @@ -56,7 +56,7 @@ <? else: ?> <?= $this->render_partial($exercise->getSolveTemplate($solution, $assignment, $user_id)) ?> - <? if ($exercise->options['comment']): ?> + <? if (!empty($exercise->options['comment'])): ?> <label> <?= _vips('Bemerkungen zur Lösung (optional)') ?> <textarea name="student_comment"><?= htmlReady($solution->student_comment) ?></textarea> diff --git a/views/sheets/show_exercise.php b/views/sheets/show_exercise.php index 3ee5fc97fdd5947a77e9ff5af55bf870b4ff66a9..8e7633a6826977cf8331c17c970145267c8d699c 100644 --- a/views/sheets/show_exercise.php +++ b/views/sheets/show_exercise.php @@ -96,7 +96,7 @@ <?= $this->render_partial($exercise->getSolveTemplate($solution, $assignment, $solver_id)) ?> - <? if (isset($exercise->options['comment']) && $exercise->options['comment']) : ?> + <? if (!empty($exercise->options['comment'])) : ?> <label> <?= _vips('Bemerkungen zur Lösung (optional)') ?> <textarea name="student_comment"><?= $solution ? htmlReady($solution->student_comment) : '' ?></textarea>