aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark/BookmarkFileService.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/bookmark/BookmarkFileService.php')
-rw-r--r--application/bookmark/BookmarkFileService.php32
1 files changed, 22 insertions, 10 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php
index 6666a251..8ea37427 100644
--- a/application/bookmark/BookmarkFileService.php
+++ b/application/bookmark/BookmarkFileService.php
@@ -55,8 +55,12 @@ class BookmarkFileService implements BookmarkServiceInterface
55 /** 55 /**
56 * @inheritDoc 56 * @inheritDoc
57 */ 57 */
58 public function __construct(ConfigManager $conf, History $history, Mutex $mutex, bool $isLoggedIn) 58 public function __construct(
59 { 59 ConfigManager $conf,
60 History $history,
61 Mutex $mutex,
62 bool $isLoggedIn
63 ) {
60 $this->conf = $conf; 64 $this->conf = $conf;
61 $this->history = $history; 65 $this->history = $history;
62 $this->mutex = $mutex; 66 $this->mutex = $mutex;
@@ -129,8 +133,9 @@ class BookmarkFileService implements BookmarkServiceInterface
129 string $visibility = null, 133 string $visibility = null,
130 bool $caseSensitive = false, 134 bool $caseSensitive = false,
131 bool $untaggedOnly = false, 135 bool $untaggedOnly = false,
132 bool $ignoreSticky = false 136 bool $ignoreSticky = false,
133 ) { 137 array $pagination = []
138 ): SearchResult {
134 if ($visibility === null) { 139 if ($visibility === null) {
135 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; 140 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
136 } 141 }
@@ -143,13 +148,20 @@ class BookmarkFileService implements BookmarkServiceInterface
143 $this->bookmarks->reorder('DESC', true); 148 $this->bookmarks->reorder('DESC', true);
144 } 149 }
145 150
146 return $this->bookmarkFilter->filter( 151 $bookmarks = $this->bookmarkFilter->filter(
147 BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, 152 BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
148 [$searchTags, $searchTerm], 153 [$searchTags, $searchTerm],
149 $caseSensitive, 154 $caseSensitive,
150 $visibility, 155 $visibility,
151 $untaggedOnly 156 $untaggedOnly
152 ); 157 );
158
159 return SearchResult::getSearchResult(
160 $bookmarks,
161 $pagination['offset'] ?? 0,
162 $pagination['limit'] ?? null,
163 $pagination['allowOutOfBounds'] ?? false
164 );
153 } 165 }
154 166
155 /** 167 /**
@@ -282,7 +294,7 @@ class BookmarkFileService implements BookmarkServiceInterface
282 */ 294 */
283 public function count(string $visibility = null): int 295 public function count(string $visibility = null): int
284 { 296 {
285 return count($this->search([], $visibility)); 297 return $this->search([], $visibility)->getResultCount();
286 } 298 }
287 299
288 /** 300 /**
@@ -305,10 +317,10 @@ class BookmarkFileService implements BookmarkServiceInterface
305 */ 317 */
306 public function bookmarksCountPerTag(array $filteringTags = [], string $visibility = null): array 318 public function bookmarksCountPerTag(array $filteringTags = [], string $visibility = null): array
307 { 319 {
308 $bookmarks = $this->search(['searchtags' => $filteringTags], $visibility); 320 $searchResult = $this->search(['searchtags' => $filteringTags], $visibility);
309 $tags = []; 321 $tags = [];
310 $caseMapping = []; 322 $caseMapping = [];
311 foreach ($bookmarks as $bookmark) { 323 foreach ($searchResult->getBookmarks() as $bookmark) {
312 foreach ($bookmark->getTags() as $tag) { 324 foreach ($bookmark->getTags() as $tag) {
313 if ( 325 if (
314 empty($tag) 326 empty($tag)
@@ -357,7 +369,7 @@ class BookmarkFileService implements BookmarkServiceInterface
357 $previous = null; 369 $previous = null;
358 $next = null; 370 $next = null;
359 371
360 foreach ($this->search([], null, false, false, true) as $bookmark) { 372 foreach ($this->search([], null, false, false, true)->getBookmarks() as $bookmark) {
361 if ($to < $bookmark->getCreated()) { 373 if ($to < $bookmark->getCreated()) {
362 $next = $bookmark->getCreated(); 374 $next = $bookmark->getCreated();
363 } elseif ($from < $bookmark->getCreated() && $to > $bookmark->getCreated()) { 375 } elseif ($from < $bookmark->getCreated() && $to > $bookmark->getCreated()) {
@@ -378,7 +390,7 @@ class BookmarkFileService implements BookmarkServiceInterface
378 */ 390 */
379 public function getLatest(): ?Bookmark 391 public function getLatest(): ?Bookmark
380 { 392 {
381 foreach ($this->search([], null, false, false, true) as $bookmark) { 393 foreach ($this->search([], null, false, false, true)->getBookmarks() as $bookmark) {
382 return $bookmark; 394 return $bookmark;
383 } 395 }
384 396