aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Schemas/CourseEvent.php
blob: 470d86bbb0f9d6972852337d0600c9e3785672fd (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
<?php

namespace JsonApi\Schemas;

use Neomerx\JsonApi\Document\Link;

class CourseEvent extends SchemaProvider
{
    const TYPE = 'course-events';
    const REL_OWNER = 'owner';

    protected $resourceType = self::TYPE;

    public function getId($resource)
    {
        return $resource->id;
    }

    public function getAttributes($resource)
    {
        return [
            'title' => $resource->title,
            'description' => $resource->getDescription(),
            'start' => date('c', $resource->getStart()),
            'end' => date('c', $resource->getEnd()),
            'categories' => array_filter($resource->toStringCategories(true)),
            'location' => $resource->getLocation(),

            'mkdate' => date('c', $resource->mkdate),
            'chdate' => date('c', $resource->chdate),
            'recurrence' => $resource->getRecurrence(),
        ];
    }

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function getRelationships($resource, $isPrimary, array $includeList)
    {
        $relationships = [];

        if ($owner = $resource->course) {
            $link = $this->getSchemaContainer()->getSchema($owner)->getSelfSubLink($owner);
            $relationships = [
                self::REL_OWNER => [self::LINKS => [Link::RELATED => $link], self::DATA => $owner],
            ];
        }

        return $relationships;
    }
}