aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Schemas/Courseware/CustomFile.php
blob: 21105bc6ae93de02c0e25456064eb5652f9105ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace JsonApi\Schemas\Courseware;

use JsonApi\Schemas\SchemaProvider;
use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
use Neomerx\JsonApi\Schema\Link;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;

class CustomFile extends SchemaProvider
{
    const TYPE = 'courseware-custom-file';
    //const REL_CUSTOM_FILE = 'courseware-custom-file';

    /**
     * {@inheritdoc}
     */
    public function getId($resource): ?string
    {
        return $resource->getPayload()['id'];
    }

    /**
     * {@inheritdoc}
     */
    public function getAttributes($resource, ContextInterface $context): iterable
    {
        return $resource->getPayload();
    }

    /**
     * {@inheritdoc}
     */
    public function getRelationships($resource, ContextInterface $context): iterable
    {

        return [];
    }

    public function getSelfLink($resource): LinkInterface
    {
        $link = new Link(true, '/courseware-blocks/' . $resource->getBlockId()
            .'/custom-files', false);
        return $link;
    }

    /**
     * @inheritdoc
     */
    public function hasResourceMeta($resource): bool
    {
        return true;
    }

    public function getResourceMeta($resource)
    {
        return [
            'download-url' => $resource->getDownloadUrl()
        ];
    }
}