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
|
<?php
namespace JsonApi\Schemas;
use Neomerx\JsonApi\Document\Link;
class CalendarEvent extends SchemaProvider
{
const TYPE = 'calendar-events';
const REL_OWNER = 'owner';
protected $resourceType = self::TYPE;
public function getId($resource)
{
return $resource->id;
}
public function getAttributes($resource)
{
return [
'title' => $resource->title,
'description' => $resource->getDescription(),
'start' => date('c', $resource->getStart()),
'end' => date('c', $resource->getEnd()),
'categories' => $resource->toStringCategories(true),
'location' => $resource->getLocation(),
// TODO: 'is-canceled' => $singledate->isHoliday() ?: false,
'mkdate' => date('c', $resource->mkdate),
'chdate' => date('c', $resource->chdate),
'recurrence' => $resource->getRecurrence(),
];
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getRelationships($resource, $isPrimary, array $includeList)
{
$relationships = [];
if ($owner = $resource->getOwner()) {
$link = $this->getSchemaContainer()->getSchema($owner)->getSelfSubLink($owner);
$relationships = [
self::REL_OWNER => [self::LINKS => [Link::RELATED => $link], self::DATA => $owner],
];
}
return $relationships;
}
}
|