From 0061c6be014723dc0e3d8df7056d905e19273790 Mon Sep 17 00:00:00 2001 From: Ron Lucke <lucke@elan-ev.de> Date: Mon, 4 Oct 2021 17:01:06 +0000 Subject: [PATCH] fixes #253 --- .../Courseware/StructuralElementsUpdate.php | 3 ++ lib/models/Courseware/StructuralElement.php | 28 +++++++++++++++++++ .../courseware/CoursewareToolsContents.vue | 18 ++++++------ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/classes/JsonApi/Routes/Courseware/StructuralElementsUpdate.php b/lib/classes/JsonApi/Routes/Courseware/StructuralElementsUpdate.php index 480087df11f..78855bde26e 100755 --- a/lib/classes/JsonApi/Routes/Courseware/StructuralElementsUpdate.php +++ b/lib/classes/JsonApi/Routes/Courseware/StructuralElementsUpdate.php @@ -119,6 +119,9 @@ class StructuralElementsUpdate extends JsonApiController } } + $resource->release_date = $json['data']['attributes']['release-date']; + $resource->withdraw_date = $json['data']['attributes']['withdraw-date']; + // update parent if (self::arrayHas($json, 'data.relationships.parent')) { $parent = $this->getParentFromJson($json); diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php index a2698e14c08..0637bd7e8a1 100755 --- a/lib/models/Courseware/StructuralElement.php +++ b/lib/models/Courseware/StructuralElement.php @@ -238,6 +238,10 @@ class StructuralElement extends \SimpleORMap return true; } + if (!$this->releasedForReaders($this)) { + return false; + } + if (!count($this->read_approval)) { return $this->canReadSequential($user); } @@ -282,6 +286,30 @@ class StructuralElement extends \SimpleORMap return $this->previousProgressAchieved($user); } + /** + * @return bool true if the user may read this instance in time interval + * + * @SuppressWarnings(PHPMD.Superglobals) + */ + private function releasedForReaders(StructuralElement $element): bool + { + $released = false; + if (!$element->release_date || $element->release_date <= time()) { + $released = true; + } + + if ($element->withdraw_date && $element->withdraw_date <= time()) { + $released = false; + } + + $parent_released = true; + if (!$element->isRootNode()) { + $parent_released = $this->releasedForReaders($element->parent); + } + + return $released && $parent_released; + } + /** * @param mixed $user the user to validate * diff --git a/resources/vue/components/courseware/CoursewareToolsContents.vue b/resources/vue/components/courseware/CoursewareToolsContents.vue index 071903e4a44..c75c13c59ca 100755 --- a/resources/vue/components/courseware/CoursewareToolsContents.vue +++ b/resources/vue/components/courseware/CoursewareToolsContents.vue @@ -50,14 +50,16 @@ export default { for (var i = 0; i < data.length; i++) { if (data[i].relationships.parent.data?.id == parentId) { let new_childs = this.loadChildren(data[i].id, data, depth + 1); - children.push({ - name: data[i].attributes.title, - position: data[i].attributes.position, - element_id: data[i].id, - children: new_childs, - depth: depth, - current: this.currentElementId === data[i].id - }); + if (data[i].attributes['can-read']) { + children.push({ + name: data[i].attributes.title, + position: data[i].attributes.position, + element_id: data[i].id, + children: new_childs, + depth: depth, + current: this.currentElementId === data[i].id + }); + } } } -- GitLab