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\Persistence\Legacy\Bookmark; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\Bookmark\Bookmark; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct; |
13
|
|
|
use eZ\Publish\SPI\Persistence\Bookmark\Handler as HandlerInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Storage Engine handler for bookmarks. |
17
|
|
|
*/ |
18
|
|
|
class Handler implements HandlerInterface |
19
|
|
|
{ |
20
|
|
|
/** @var \eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway */ |
21
|
|
|
private $gateway; |
22
|
|
|
|
23
|
|
|
/** @var \eZ\Publish\Core\Persistence\Legacy\Bookmark\Mapper */ |
24
|
|
|
private $mapper; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Handler constructor. |
28
|
|
|
* |
29
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway $gateway |
30
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Bookmark\Mapper $mapper |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Gateway $gateway, Mapper $mapper) |
33
|
|
|
{ |
34
|
|
|
$this->gateway = $gateway; |
35
|
|
|
$this->mapper = $mapper; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function create(CreateStruct $createStruct): Bookmark |
42
|
|
|
{ |
43
|
|
|
$bookmark = $this->mapper->createBookmarkFromCreateStruct( |
44
|
|
|
$createStruct |
45
|
|
|
); |
46
|
|
|
$bookmark->id = $this->gateway->insertBookmark($bookmark); |
47
|
|
|
|
48
|
|
|
return $bookmark; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function delete(int $bookmarkId): void |
55
|
|
|
{ |
56
|
|
|
$this->gateway->deleteBookmark($bookmarkId); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function loadByUserIdAndLocationId(int $userId, array $locationIds): array |
63
|
|
|
{ |
64
|
|
|
$bookmarks = $this->mapper->extractBookmarksFromRows( |
65
|
|
|
$this->gateway->loadBookmarkDataByUserIdAndLocationId($userId, $locationIds) |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$list = []; |
69
|
|
|
foreach ($bookmarks as $bookmark) { |
70
|
|
|
$list[$bookmark->locationId] = $bookmark; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $list; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array |
80
|
|
|
{ |
81
|
|
|
return $this->mapper->extractBookmarksFromRows( |
82
|
|
|
$this->gateway->loadUserBookmarks($userId, $offset, $limit) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function countUserBookmarks(int $userId): int |
90
|
|
|
{ |
91
|
|
|
return $this->gateway->countUserBookmarks($userId); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function locationSwapped(int $location1Id, int $location2Id): void |
98
|
|
|
{ |
99
|
|
|
$this->gateway->locationSwapped($location1Id, $location2Id); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|