1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
13
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Values\BookmarkList as BookmarkListValue; |
15
|
|
|
|
16
|
|
|
class BookmarkList extends ValueObjectVisitor |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function visit(Visitor $visitor, Generator $generator, $data) |
22
|
|
|
{ |
23
|
|
|
$generator->startObjectElement('BookmarkList'); |
24
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType('BookmarkList')); |
25
|
|
|
|
26
|
|
|
$this->visitAttributes($visitor, $generator, $data); |
27
|
|
|
$generator->endObjectElement('BookmarkList'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function visitAttributes(Visitor $visitor, Generator $generator, BookmarkListValue $data): void |
31
|
|
|
{ |
32
|
|
|
$generator->startValueElement('count', $data->totalCount); |
33
|
|
|
$generator->endValueElement('count'); |
34
|
|
|
|
35
|
|
|
$generator->startList('items'); |
36
|
|
|
foreach ($data->items as $restLocation) { |
37
|
|
|
$generator->startObjectElement('Bookmark'); |
38
|
|
|
|
39
|
|
|
$generator->startAttribute('_href', $this->router->generate('ezpublish_rest_isBookmarked', [ |
40
|
|
|
'locationId' => $restLocation->location->id, |
41
|
|
|
])); |
42
|
|
|
$generator->endAttribute('_href'); |
43
|
|
|
|
44
|
|
|
$visitor->visitValueObject($restLocation); |
45
|
|
|
$generator->endObjectElement('Bookmark'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$generator->endList('items'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|