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

namespace JsonApi\Schemas;

use Neomerx\JsonApi\Contracts\Schema\ContextInterface;

class ConfigValue extends SchemaProvider
{
    const TYPE = 'config-values';

    public function getId($resource): ?string
    {
        return join('_', [$resource['range_id'], $resource['field']]);
    }

    public function getAttributes($resource, ContextInterface $context): iterable
    {
        $i18nAwareCast = function ($mixed) use ($resource) {
            return 'i18n' === $resource->entry['type'] ? (string) $mixed : $mixed;
        };

        return [
            'field' => $resource['field'],
            'value' => $i18nAwareCast($resource->getTypedValue()),
            'field-type' => $resource->entry['type'],
            'comment' => $resource['comment'],
            'default-value' => $i18nAwareCast($resource->getTypedDefaultValue()),
            'mkdate' => date('c', $resource['mkdate']),
            'chdate' => date('c', $resource['chdate']),
        ];
    }

    public function getRelationships($user, ContextInterface $context): iterable
    {
        return [];
    }
}