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
62
63
64
65
66
67
68
69
70
|
<?php
namespace JsonApi\Schemas;
use Neomerx\JsonApi\Document\Link;
class SemClass extends SchemaProvider
{
const REL_SEM_TYPES = 'sem-types';
const TYPE = 'sem-classes';
protected $resourceType = self::TYPE;
public function getId($resource)
{
return $resource['id'];
}
public function getAttributes($resource)
{
return [
'name' => (string) $resource['name'],
'only-inst-user' => (bool) $resource['only_inst_user'],
'default-read-level' => (int) $resource['default_read_level'],
'default-write-level' => (int) $resource['default_write_level'],
'bereiche' => (int) $resource['bereiche'],
'show-browse' => (bool) $resource['show_browse'],
'write-access-nobody' => (bool) $resource['write_access_nobody'],
'topic-create-autor' => (bool) $resource['topic_create_autor'],
'visible' => (bool) $resource['visible'],
'course-creation-forbidden' => (bool) $resource['course_creation_forbidden'],
];
}
public function getRelationships($resource, $isPrimary, array $includeList)
{
$relationships = [];
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
// SemTypes
$relationships = $this->addSemTypesRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_SEM_TYPES)
);
return $relationships;
}
private function addSemTypesRelationship(array $relationships, $resource, $includeData)
{
$relation = [
self::LINKS => [
Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_SEM_TYPES),
]
];
if ($includeData) {
$related = $resource->getSemTypes();
$relation[self::DATA] = $related;
}
$relationships[self::REL_SEM_TYPES] = $relation;
return $relationships;
}
}
|