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']; } }