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

namespace JsonApi\Schemas;

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

    protected $resourceType = self::TYPE;

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

    public function getAttributes($resource)
    {
        $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']),
        ];
    }
}