From 880e367bea888fce8768ee3c3a2b316dfbcadc55 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Thu, 22 Aug 2024 00:19:34 +0200
Subject: [PATCH] cast assignment_id in payload to string, fixes #265

---
 controllers/api.php                  | 7 +++----
 views/exercises/courseware_block.php | 2 +-
 views/sheets/show_exercise.php       | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/controllers/api.php b/controllers/api.php
index 5e79332..776f1b9 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'     => (string) $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'             => (string) $assignment->id,
             'title'          => $assignment->test->title,
             'type'           => $assignment->type,
             'icon'           => $assignment->getTypeIcon()->getShape(),
@@ -83,7 +82,6 @@ class ApiController extends StudipController
 
             $data['exercises'][] = [
                 'id'            => $exercise->id,
-                'link'          => $this->url_for('api/exercise', $assignment_id, $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/views/exercises/courseware_block.php b/views/exercises/courseware_block.php
index 8212b78..3153455 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 3ee5fc9..8e7633a 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>
-- 
GitLab