aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Schemas/SemType.php
blob: 46b2e3ca84a9efab562a71aa73ad38f641f61e8b (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
<?php

namespace JsonApi\Schemas;

use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
use Neomerx\JsonApi\Schema\Link;

class SemType extends SchemaProvider
{
    const REL_SEM_CLASS = 'sem-class';
    const TYPE = 'sem-types';



    public function getId($resource): ?string
    {
        return $resource['id'];
    }

    public function getAttributes($resource, ContextInterface $context): iterable
    {
        return [
            'name' => $resource['name'],
            'mkdate' => date('c', $resource['mkdate']),
            'chdate' => date('c', $resource['chdate']),
        ];
    }

    public function getRelationships($resource, ContextInterface $context): iterable
    {
        $relationships = [];

        // SemClass
        $related = $resource->getClass();
        $relationships[self::REL_SEM_CLASS] = [
            self::RELATIONSHIP_LINKS => [
                Link::RELATED => $this->createLinkToResource($related)
            ],
            self::RELATIONSHIP_DATA => $related,
        ];

        return $relationships;
    }
}