aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/Filesystem/CustomFile.php
diff options
context:
space:
mode:
authortgloeggl <tgloeggl@uos.de>2022-01-13 14:38:39 +0100
committertgloeggl <tgloeggl@uos.de>2022-07-28 13:59:21 +0200
commitda3db0c846bd2c3498a487727ddb11b37324824f (patch)
tree4b0b13adb6a1f55716372b75887e139d7f94df85 /lib/models/Courseware/Filesystem/CustomFile.php
parent7d087fcdf3218f8101e592b78f948479b3d02fe2 (diff)
working on creating plugin-api for im- and exportticket-334
fix bug fix passing of custom file to block fix custom-file creation on client side working on crud custom file api for courseware blocks create correct link for custom file add read part of CRUD add delete part of CRUD change behaviour of add a new file, contents are passed via separate route update custom-file content add route to patch metadata of custom-file changes to export for reference fix jsonapi for custom-files export custom-files correctly import custom files remove custom files from file-refs revert changes to block remove obsolte use statement in Block revert changes to BlockType and Download-Block remove obsolete implements from DownloadBlock add doku, fix exporting of blocks without custom-files remove debugging messages and now obsolete code cleaning up rework custom file check fix error and remove call to mime-type for custom files rename interface methods do not assign variables in function calls
Diffstat (limited to 'lib/models/Courseware/Filesystem/CustomFile.php')
-rw-r--r--lib/models/Courseware/Filesystem/CustomFile.php123
1 files changed, 123 insertions, 0 deletions
diff --git a/lib/models/Courseware/Filesystem/CustomFile.php b/lib/models/Courseware/Filesystem/CustomFile.php
new file mode 100644
index 0000000..7a6d4b8
--- /dev/null
+++ b/lib/models/Courseware/Filesystem/CustomFile.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Courseware\Filesystem;
+
+/**
+ * This class represents the metdata for a custom file in a courseware block
+ */
+class CustomFile
+{
+ /**
+ * The payload for this custom file, containt id, block_id and arbitrary attributes
+ * @var [type]
+ */
+ protected
+ $payload;
+
+ /**
+ * create a new custom file object, containing a self assigned id (make it unique!),
+ * the blocks id this custom file is referenced to and some attributes of
+ * your choice
+ *
+ * @param string $id an unique id for this custom file
+ * @param int $block_id the id of the related block
+ * @param array $attributes [description]
+ */
+ public function __construct($id = null, $block_id, $attributes = [])
+ {
+ $this->payload = [
+ 'id' => $id,
+ 'block_id' => $block_id,
+ 'attributes' => $attributes
+ ];
+ }
+
+ /**
+ * returns the payload: [
+ * 'id' => ...,
+ * 'block_id' => ...,
+ * 'attributes' => [ ... ]
+ * ]
+ *
+ * @return array the payload
+ */
+ public function getPayload()
+ {
+ return $this->payload;
+ }
+
+ /**
+ * get id for this custom file
+ *
+ * @return string custom file id
+ */
+ public function getId()
+ {
+ return $this->payload['id'];
+ }
+
+ /**
+ * get id of related block
+ *
+ * @return int related block id
+ */
+ public function getBlockId()
+ {
+ return $this->payload['block_id'];
+ }
+
+ /**
+ * Overwrite the complete payload for this block. The payload MUST have the
+ * following structure: [
+ * 'id' => ...,
+ * 'block_id' => ...,
+ * 'attributes' => [ ... ]
+ * ]
+ *
+ * @param array $payload the payload of appropriate structure
+ */
+ public function setPayload($payload): void
+ {
+ if (!$payload['id']) {
+ throw new InvalidArgumentException();
+ }
+
+ if (!$payload['block_id']) {
+ throw new InvalidArgumentException();
+ }
+
+ $this->payload = $payload;
+ }
+
+ /**
+ * Set the unique id for this custom file
+ *
+ * @param string $id
+ */
+ public function setId($id): void
+ {
+ $this->payload['id'] = $id;
+ }
+
+ /**
+ * Set the id for the related block
+ *
+ * @param int $block_id
+ */
+ public function setBlockId($block_id): void
+ {
+ $this->payload['block_id'] = $block_id;
+ }
+
+ /**
+ * Get the download url for this custom file
+ *
+ * @return string the download url
+ */
+ public function getDownloadUrl() : string
+ {
+ return rtrim(\URLHelper::getUrl('jsonapi.php/v1'), '/')
+ . '/courseware-blocks/' . $this->payload['block_id']
+ . '/custom-files/'. $this->payload['id'];
+ }
+}