diff --git a/lib/models/Courseware/BlockTypes/BlockType.php b/lib/models/Courseware/BlockTypes/BlockType.php index a25672dd3157ed81e29f45dccebb078ebee7219a..aa2c478815c19240470f2be55071e65138be3e4b 100755 --- a/lib/models/Courseware/BlockTypes/BlockType.php +++ b/lib/models/Courseware/BlockTypes/BlockType.php @@ -283,10 +283,9 @@ abstract class BlockType protected function getFileById(string $fileId) { $file_ref = \FileRef::find($fileId); - $file = $file_ref->getFileType(); $user = \User::findCurrent(); - if ($file_ref && $file->isDownloadable($user->id)) { + if ($file_ref && $file_ref->getFileType()->isDownloadable($user->id)) { return $file_ref->toArray(); } else { return []; diff --git a/lib/models/Courseware/BlockTypes/DialogCards.php b/lib/models/Courseware/BlockTypes/DialogCards.php index 023a41693c1c5bba83dc2fb0d831cce77b81dd9e..7d3c8ba0735de742361adf32932ed2648166b824 100755 --- a/lib/models/Courseware/BlockTypes/DialogCards.php +++ b/lib/models/Courseware/BlockTypes/DialogCards.php @@ -56,6 +56,28 @@ class DialogCards extends BlockType return $payload; } + /** + * get all files related to this block. + * + * @return \FileRef[] list of file references related to this block + */ + public function getFiles(): array + { + $payload = $this->getPayload(); + $files = []; + + foreach ($payload['cards'] as &$card) { + if ($card['front_file_id'] && $fileRef = \FileRef::find($card['front_file_id'])) { + $files[] = $fileRef; + } + if ($card['back_file_id'] && $fileRef = \FileRef::find($card['back_file_id'])) { + $files[] = $fileRef; + } + } + + return $files; + } + public function copyPayload(string $rangeId = ''): array { $payload = $this->getPayload(); diff --git a/lib/models/Courseware/BlockTypes/Download.json b/lib/models/Courseware/BlockTypes/Download.json index b919e1393ad183b196d9640ced708834e7ff45d9..bcc5f1dd67d1803465e3739da8c389eb6eb6db2d 100755 --- a/lib/models/Courseware/BlockTypes/Download.json +++ b/lib/models/Courseware/BlockTypes/Download.json @@ -12,7 +12,7 @@ "type": "string" }, "grade": { - "type": "string" + "type": ["string", "boolean"] }, "file_id": { "type": "string" diff --git a/lib/models/Courseware/BlockTypes/Download.php b/lib/models/Courseware/BlockTypes/Download.php index 2e60bf4c1f416ca8e2ce3b4b4ac93229e1e3c237..6656d9f0bc8c7ffbd81faa9df837e1c1180ab5dd 100755 --- a/lib/models/Courseware/BlockTypes/Download.php +++ b/lib/models/Courseware/BlockTypes/Download.php @@ -35,7 +35,7 @@ class Download extends BlockType 'title' => '', 'info' => '', 'success' => '', - 'grade' => 'false', + 'grade' => false, 'file_id' => '', ]; } diff --git a/lib/models/Courseware/BlockTypes/Folder.json b/lib/models/Courseware/BlockTypes/Folder.json index a3320493f3159a022d5db06adcb62a2d7636bcc5..24d57920a42072fdc8ca1e5e73faa2f085f8ddaf 100755 --- a/lib/models/Courseware/BlockTypes/Folder.json +++ b/lib/models/Courseware/BlockTypes/Folder.json @@ -13,7 +13,7 @@ } }, "required": [ - "type", "folder_id" + "folder_id" ], "additionalProperties": false } diff --git a/lib/models/Courseware/BlockTypes/Headline.php b/lib/models/Courseware/BlockTypes/Headline.php index addde05a11fe9c61addbafe6161eab1c046f7b98..855e2a94a54fe6ddb84e1cdb522bdcee822b4a96 100755 --- a/lib/models/Courseware/BlockTypes/Headline.php +++ b/lib/models/Courseware/BlockTypes/Headline.php @@ -53,17 +53,21 @@ class Headline extends BlockType return Schema::fromJsonString(file_get_contents($schemaFile)); } - public function getPayload() + /** + * get all files related to this block. + * + * @return \FileRef[] list of file references related to this block + */ + public function getFiles(): array { - $payload = $this->decodePayloadString($this->block['payload']); + $payload = $this->getPayload(); + $files = []; - if ('' != $payload['background_image_id']) { - $payload['background_image'] = $this->getFileById($payload['background_image_id']); - } else { - $payload['background_image'] = []; + if ($payload['background_image_id'] && $fileRef = \FileRef::find($payload['background_image_id'])) { + $files[] = $fileRef; } - return $payload; + return $files; } public function copyPayload(string $rangeId = ''): array diff --git a/resources/vue/components/courseware/CoursewareHeadlineBlock.vue b/resources/vue/components/courseware/CoursewareHeadlineBlock.vue index 8f1483502708f2220db4e68a85a8121acd2bd6a6..349ac9545c262ff6147f5ba5e9dd906d9ed1431e 100755 --- a/resources/vue/components/courseware/CoursewareHeadlineBlock.vue +++ b/resources/vue/components/courseware/CoursewareHeadlineBlock.vue @@ -169,7 +169,7 @@ <script> import CoursewareDefaultBlock from './CoursewareDefaultBlock.vue'; import CoursewareFileChooser from './CoursewareFileChooser.vue'; -import { mapActions } from 'vuex'; +import { mapGetters, mapActions } from 'vuex'; import contentIcons from './content-icons.js'; export default { @@ -196,9 +196,15 @@ export default { currentBackgroundType: '', currentBackgroundImageId: '', currentBackgroundImage: {}, + currentBackgroundURL: '', }; }, computed: { + ...mapGetters({ + fileRefById: 'file-refs/byId', + urlHelper: 'urlHelper', + relatedTermOfUse: 'terms-of-use/related', + }), title() { return this.block?.attributes?.payload?.title; }, @@ -292,16 +298,14 @@ export default { } return style; - }, - currentBackgroundURL() { - return this.currentBackgroundImage.download_url; - }, + } }, mounted() { this.initCurrentData(); }, methods: { ...mapActions({ + loadFileRef: 'file-refs/loadById', updateBlock: 'updateBlockInContainer', }), initCurrentData() { @@ -315,13 +319,31 @@ export default { this.currentIconColor = this.iconColor; this.currentBackgroundType = this.backgroundType; this.currentBackgroundImageId = this.backgroundImageId; - if (typeof this.backgroundImage === 'object' && !Array.isArray(this.backgroundImage)) { - this.currentBackgroundImage = this.backgroundImage; + if (this.currentBackgroundImageId !== '') { + this.loadFile(); + } + }, + async loadFile() { + const id = this.currentBackgroundImageId; + const options = { include: 'terms-of-use' }; + await this.loadFileRef({ id: id, options }); + const fileRef = this.fileRefById({ id: id }); + if (fileRef && this.relatedTermOfUse({parent: fileRef, relationship: 'terms-of-use'}).attributes['download-condition'] === 0) { + this.updateCurrentBackgroundImage({ + id: fileRef.id, + name: fileRef.attributes.name, + download_url: this.urlHelper.getURL( + 'sendfile.php', + { type: 0, file_id: fileRef.id, file_name: fileRef.attributes.name }, + true + ), + }); } }, updateCurrentBackgroundImage(file) { this.currentBackgroundImage = file; this.currentBackgroundImageId = file.id; + this.currentBackgroundURL = file.download_url; }, closeEdit() { this.initCurrentData(); @@ -333,12 +355,19 @@ export default { attributes.payload.subtitle = this.currentSubtitle; attributes.payload.style = this.currentStyle; attributes.payload.height = this.currentHeight; - attributes.payload.background_color = this.currentBackgroundColor; attributes.payload.text_color = this.currentTextColor; attributes.payload.icon = this.currentIcon; attributes.payload.icon_color = this.currentIconColor; - attributes.payload.background_image_id = this.currentBackgroundImageId; attributes.payload.background_type = this.currentBackgroundType; + attributes.payload.background_color = ''; + attributes.payload.background_image_id = ''; + + if (this.currentBackgroundType === 'color') { + attributes.payload.background_color = this.currentBackgroundColor; + } + if (this.currentBackgroundType === 'image') { + attributes.payload.background_image_id = this.currentBackgroundImageId; + } this.updateBlock({ attributes: attributes, diff --git a/resources/vue/mixins/courseware/export.js b/resources/vue/mixins/courseware/export.js index 65e8ece5b3d829c44a3f176172210df59eb3ccf4..410a366c00d3917a13ae5c5c324587d2274349ff 100755 --- a/resources/vue/mixins/courseware/export.js +++ b/resources/vue/mixins/courseware/export.js @@ -266,22 +266,41 @@ export default { async exportFileRefs(block_id) { // load file-ref data - let refs = await this.loadFileRefs(block_id); + let refs = [] + try { + refs = await this.loadFileRefs(block_id); + } catch(e) { + //TODO: Companion explains error + } // add infos to exportFiles JSON for (let ref_id in refs) { - let fileref = {}; + let fileref = {}; let folderId = refs[ref_id].relationships.parent.data.id; - await this.loadFolder(folderId); - let folder = this.folderById({id: folderId}); - + let folder = null; fileref.attributes = refs[ref_id].attributes; fileref.related_block_id = block_id; fileref.id = refs[ref_id].id; - fileref.folder = { - id: folder.id, - name: folder.attributes.name, - type: folder.attributes['folder-type'] + + try { + await this.loadFolder(folderId); + folder = this.folderById({id: folderId}); + } catch(e) { + //TODO: Companion explains error + } + + if (folder) { + fileref.folder = { + id: folder.id, + name: folder.attributes.name, + type: folder.attributes['folder-type'] + } + } else { + fileref.folder = { + id: folderId, + name: 'Unknown', + type: 'StandardFolder' + } } this.exportFiles.json.push(fileref);