Skip to content
Snippets Groups Projects
Commit efda6293 authored by Ron Lucke's avatar Ron Lucke Committed by Elmar Ludwig
Browse files

fixes #306

parent 12bc4185
No related branches found
No related tags found
No related merge requests found
......@@ -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 [];
......
......@@ -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();
......
......@@ -12,7 +12,7 @@
"type": "string"
},
"grade": {
"type": "string"
"type": ["string", "boolean"]
},
"file_id": {
"type": "string"
......
......@@ -35,7 +35,7 @@ class Download extends BlockType
'title' => '',
'info' => '',
'success' => '',
'grade' => 'false',
'grade' => false,
'file_id' => '',
];
}
......
......@@ -13,7 +13,7 @@
}
},
"required": [
"type", "folder_id"
"folder_id"
],
"additionalProperties": false
}
......@@ -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
......
......@@ -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,
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment