aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware
diff options
context:
space:
mode:
authorRon Lucke <lucke@elan-ev.de>2021-10-14 12:48:54 +0000
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2021-10-14 12:48:54 +0000
commitefda629364fe8963ffd4488a97e3144449d1310a (patch)
treee9ceebd9e0cfa207c6f89718945316cb3b47965b /lib/models/Courseware
parent12bc41854992c5c8ec815022ca44493b494a2382 (diff)
fixes #306
Diffstat (limited to 'lib/models/Courseware')
-rwxr-xr-xlib/models/Courseware/BlockTypes/BlockType.php3
-rwxr-xr-xlib/models/Courseware/BlockTypes/DialogCards.php22
-rwxr-xr-xlib/models/Courseware/BlockTypes/Download.json2
-rwxr-xr-xlib/models/Courseware/BlockTypes/Download.php2
-rwxr-xr-xlib/models/Courseware/BlockTypes/Folder.json2
-rwxr-xr-xlib/models/Courseware/BlockTypes/Headline.php18
6 files changed, 37 insertions, 12 deletions
diff --git a/lib/models/Courseware/BlockTypes/BlockType.php b/lib/models/Courseware/BlockTypes/BlockType.php
index a25672d..aa2c478 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 023a416..7d3c8ba 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 b919e13..bcc5f1d 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 2e60bf4..6656d9f 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 a332049..24d5792 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 addde05..855e2a9 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