diff options
Diffstat (limited to 'application/bookmark')
-rw-r--r-- | application/bookmark/BookmarkArray.php | 9 | ||||
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 13 | ||||
-rw-r--r-- | application/bookmark/BookmarkServiceInterface.php | 9 |
3 files changed, 24 insertions, 7 deletions
diff --git a/application/bookmark/BookmarkArray.php b/application/bookmark/BookmarkArray.php index d87d43b4..3bd5eb20 100644 --- a/application/bookmark/BookmarkArray.php +++ b/application/bookmark/BookmarkArray.php | |||
@@ -234,16 +234,17 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess | |||
234 | * | 234 | * |
235 | * Also update the urls and ids mapping arrays. | 235 | * Also update the urls and ids mapping arrays. |
236 | * | 236 | * |
237 | * @param string $order ASC|DESC | 237 | * @param string $order ASC|DESC |
238 | * @param bool $ignoreSticky If set to true, sticky bookmarks won't be first | ||
238 | */ | 239 | */ |
239 | public function reorder($order = 'DESC') | 240 | public function reorder(string $order = 'DESC', bool $ignoreSticky = false): void |
240 | { | 241 | { |
241 | $order = $order === 'ASC' ? -1 : 1; | 242 | $order = $order === 'ASC' ? -1 : 1; |
242 | // Reorder array by dates. | 243 | // Reorder array by dates. |
243 | usort($this->bookmarks, function ($a, $b) use ($order) { | 244 | usort($this->bookmarks, function ($a, $b) use ($order, $ignoreSticky) { |
244 | /** @var $a Bookmark */ | 245 | /** @var $a Bookmark */ |
245 | /** @var $b Bookmark */ | 246 | /** @var $b Bookmark */ |
246 | if ($a->isSticky() !== $b->isSticky()) { | 247 | if (false === $ignoreSticky && $a->isSticky() !== $b->isSticky()) { |
247 | return $a->isSticky() ? -1 : 1; | 248 | return $a->isSticky() ? -1 : 1; |
248 | } | 249 | } |
249 | return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order; | 250 | return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order; |
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index b3a90ed4..e3a61146 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -114,8 +114,13 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
114 | /** | 114 | /** |
115 | * @inheritDoc | 115 | * @inheritDoc |
116 | */ | 116 | */ |
117 | public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false) | 117 | public function search( |
118 | { | 118 | $request = [], |
119 | $visibility = null, | ||
120 | $caseSensitive = false, | ||
121 | $untaggedOnly = false, | ||
122 | bool $ignoreSticky = false | ||
123 | ) { | ||
119 | if ($visibility === null) { | 124 | if ($visibility === null) { |
120 | $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; | 125 | $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; |
121 | } | 126 | } |
@@ -124,6 +129,10 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
124 | $searchtags = isset($request['searchtags']) ? $request['searchtags'] : ''; | 129 | $searchtags = isset($request['searchtags']) ? $request['searchtags'] : ''; |
125 | $searchterm = isset($request['searchterm']) ? $request['searchterm'] : ''; | 130 | $searchterm = isset($request['searchterm']) ? $request['searchterm'] : ''; |
126 | 131 | ||
132 | if ($ignoreSticky) { | ||
133 | $this->bookmarks->reorder('DESC', true); | ||
134 | } | ||
135 | |||
127 | return $this->bookmarkFilter->filter( | 136 | return $this->bookmarkFilter->filter( |
128 | BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, | 137 | BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, |
129 | [$searchtags, $searchterm], | 138 | [$searchtags, $searchterm], |
diff --git a/application/bookmark/BookmarkServiceInterface.php b/application/bookmark/BookmarkServiceInterface.php index ce8bd912..b9b483eb 100644 --- a/application/bookmark/BookmarkServiceInterface.php +++ b/application/bookmark/BookmarkServiceInterface.php | |||
@@ -49,10 +49,17 @@ interface BookmarkServiceInterface | |||
49 | * @param string $visibility | 49 | * @param string $visibility |
50 | * @param bool $caseSensitive | 50 | * @param bool $caseSensitive |
51 | * @param bool $untaggedOnly | 51 | * @param bool $untaggedOnly |
52 | * @param bool $ignoreSticky | ||
52 | * | 53 | * |
53 | * @return Bookmark[] | 54 | * @return Bookmark[] |
54 | */ | 55 | */ |
55 | public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false); | 56 | public function search( |
57 | $request = [], | ||
58 | $visibility = null, | ||
59 | $caseSensitive = false, | ||
60 | $untaggedOnly = false, | ||
61 | bool $ignoreSticky = false | ||
62 | ); | ||
56 | 63 | ||
57 | /** | 64 | /** |
58 | * Get a single bookmark by its ID. | 65 | * Get a single bookmark by its ID. |