|
13 | 13 | use eZ\Publish\API\Repository\Repository as RepositoryInterface;
|
14 | 14 | use eZ\Publish\API\Repository\Values\Bookmark\BookmarkList;
|
15 | 15 | use eZ\Publish\API\Repository\Values\Content\Location;
|
| 16 | +use eZ\Publish\API\Repository\Values\Content\Query; |
| 17 | +use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
| 18 | +use eZ\Publish\API\Repository\Values\Content\Query\SortClause; |
| 19 | +use eZ\Publish\API\Repository\Values\Filter\Filter; |
16 | 20 | use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
|
17 |
| -use eZ\Publish\SPI\Persistence\Bookmark\Bookmark; |
18 | 21 | use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct;
|
19 | 22 | use eZ\Publish\SPI\Persistence\Bookmark\Handler as BookmarkHandler;
|
20 | 23 |
|
@@ -97,16 +100,22 @@ public function loadBookmarks(int $offset = 0, int $limit = 25): BookmarkList
|
97 | 100 | {
|
98 | 101 | $currentUserId = $this->getCurrentUserId();
|
99 | 102 |
|
100 |
| - $list = new BookmarkList(); |
101 |
| - $list->totalCount = $this->bookmarkHandler->countUserBookmarks($currentUserId); |
102 |
| - if ($list->totalCount > 0) { |
103 |
| - $bookmarks = $this->bookmarkHandler->loadUserBookmarks($currentUserId, $offset, $limit); |
104 |
| - |
105 |
| - $list->items = array_map(function (Bookmark $bookmark) { |
106 |
| - return $this->repository->getLocationService()->loadLocation($bookmark->locationId); |
107 |
| - }, $bookmarks); |
| 103 | + $filter = new Filter(); |
| 104 | + try { |
| 105 | + $filter |
| 106 | + ->withCriterion(new Criterion\Bookmark($currentUserId)) |
| 107 | + ->withSortClause(new SortClause\DatePublished(Query::SORT_ASC)) |
| 108 | + ->sliceBy($limit, $offset); |
| 109 | + |
| 110 | + $result = $this->repository->getlocationService()->find($filter, []); |
| 111 | + } catch (\eZ\Publish\API\Repository\Exceptions\BadStateException $e) { |
| 112 | + return new BookmarkList(); |
108 | 113 | }
|
109 | 114 |
|
| 115 | + $list = new BookmarkList(); |
| 116 | + $list->totalCount = $result->totalCount; |
| 117 | + $list->items = $result->locations; |
| 118 | + |
110 | 119 | return $list;
|
111 | 120 | }
|
112 | 121 |
|
|
0 commit comments