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
|
<?php
namespace JsonApi\Schemas;
use Neomerx\JsonApi\Schema\Link;
use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
class ScheduleEntry extends SchemaProvider
{
const TYPE = 'schedule-entries';
const REL_OWNER = 'owner';
public function getId($entry): ?string
{
return $entry->id;
}
public function getAttributes($entry, ContextInterface $context): iterable
{
return [
'title' => $entry->label,
'description' => mb_strlen(trim($entry->content)) ? $entry->content : null,
'start' => $this->formatTime($entry->start_time),
'end' => $this->formatTime($entry->end_time),
'weekday' => (int) $entry->dow,
'color' => '',
];
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getRelationships($entry, ContextInterface $context): iterable
{
$link = $this->createLinkToResource($entry->user);
$relationships = [
self::REL_OWNER => [
self::RELATIONSHIP_LINKS => [
Link::RELATED => $link,
],
self::RELATIONSHIP_DATA => $entry->user,
],
];
return $relationships;
}
private function formatTime($time)
{
return sprintf('%02d:%02d', (int) ($time / 100), (int) ($time % 100));
}
}
|