aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi
diff options
context:
space:
mode:
Diffstat (limited to 'lib/classes/JsonApi')
-rw-r--r--lib/classes/JsonApi/Routes/Courseware/UserProgressesOfUnitsShow.php7
-rw-r--r--lib/classes/JsonApi/Schemas/Courseware/Unit.php4
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/classes/JsonApi/Routes/Courseware/UserProgressesOfUnitsShow.php b/lib/classes/JsonApi/Routes/Courseware/UserProgressesOfUnitsShow.php
index 7b900e7..26bd261 100644
--- a/lib/classes/JsonApi/Routes/Courseware/UserProgressesOfUnitsShow.php
+++ b/lib/classes/JsonApi/Routes/Courseware/UserProgressesOfUnitsShow.php
@@ -36,6 +36,11 @@ class UserProgressesOfUnitsShow extends NonJsonApiController
if (!$GLOBALS['perm']->have_studip_perm('autor', $root->range_id) || !$unit->canRead($user)) {
throw new AuthorizationFailedException();
}
+ $response = $response->withHeader('Content-Type', 'application/json');
+ if (!$root) {
+ $response->getBody()->write((string) json_encode([]));
+ return $response;
+ }
$instance = new Instance($root);
$isTeacher = $GLOBALS['perm']->have_studip_perm('tutor', $root->range_id);
@@ -46,9 +51,7 @@ class UserProgressesOfUnitsShow extends NonJsonApiController
$progresses = $this->prepareProgressData($elements, $progress);
- $response = $response->withHeader('Content-Type', 'application/json');
$response->getBody()->write((string) json_encode($progresses));
-
return $response;
}
diff --git a/lib/classes/JsonApi/Schemas/Courseware/Unit.php b/lib/classes/JsonApi/Schemas/Courseware/Unit.php
index a1c554e..7a0bf4e 100644
--- a/lib/classes/JsonApi/Schemas/Courseware/Unit.php
+++ b/lib/classes/JsonApi/Schemas/Courseware/Unit.php
@@ -53,7 +53,7 @@ class Unit extends SchemaProvider
]
: [self::RELATIONSHIP_DATA => null];
- $relationships[self::REL_STRUCTURAL_ELEMENT] = $resource['structural_element_id']
+ $relationships[self::REL_STRUCTURAL_ELEMENT] = $resource->structural_element
? [
self::RELATIONSHIP_LINKS => [
Link::RELATED => $this->createLinkToResource($resource->structural_element),
@@ -76,4 +76,4 @@ class Unit extends SchemaProvider
return $relationships;
}
-} \ No newline at end of file
+}