aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-27 19:59:28 +0100
committerGitHub <noreply@github.com>2020-10-27 19:59:28 +0100
commitb8e5a253ab5521ce2be6c0d3e04e0101527df3c1 (patch)
tree8e3eb3e10088dc4f52e58f2c8cf80f68fc26dbf9 /application/bookmark
parent977db7eabc30cd9d84f22330a114cb9d904cb514 (diff)
parent54afb1d6f65f727b20b66582bb63a42c421eea4d (diff)
downloadShaarli-b8e5a253ab5521ce2be6c0d3e04e0101527df3c1.tar.gz
Shaarli-b8e5a253ab5521ce2be6c0d3e04e0101527df3c1.tar.zst
Shaarli-b8e5a253ab5521ce2be6c0d3e04e0101527df3c1.zip
Merge pull request #1595 from ArthurHoaro/feature/daily-period
Diffstat (limited to 'application/bookmark')
-rw-r--r--application/bookmark/BookmarkFileService.php38
-rw-r--r--application/bookmark/BookmarkServiceInterface.php27
2 files changed, 44 insertions, 21 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php
index 14b3d620..0df2f47f 100644
--- a/application/bookmark/BookmarkFileService.php
+++ b/application/bookmark/BookmarkFileService.php
@@ -343,26 +343,42 @@ class BookmarkFileService implements BookmarkServiceInterface
343 /** 343 /**
344 * @inheritDoc 344 * @inheritDoc
345 */ 345 */
346 public function days(): array 346 public function findByDate(
347 { 347 \DateTimeInterface $from,
348 $bookmarkDays = []; 348 \DateTimeInterface $to,
349 foreach ($this->search() as $bookmark) { 349 ?\DateTimeInterface &$previous,
350 $bookmarkDays[$bookmark->getCreated()->format('Ymd')] = 0; 350 ?\DateTimeInterface &$next
351 ): array {
352 $out = [];
353 $previous = null;
354 $next = null;
355
356 foreach ($this->search([], null, false, false, true) as $bookmark) {
357 if ($to < $bookmark->getCreated()) {
358 $next = $bookmark->getCreated();
359 } else if ($from < $bookmark->getCreated() && $to > $bookmark->getCreated()) {
360 $out[] = $bookmark;
361 } else {
362 if ($previous !== null) {
363 break;
364 }
365 $previous = $bookmark->getCreated();
366 }
351 } 367 }
352 $bookmarkDays = array_keys($bookmarkDays);
353 sort($bookmarkDays);
354 368
355 return array_map('strval', $bookmarkDays); 369 return $out;
356 } 370 }
357 371
358 /** 372 /**
359 * @inheritDoc 373 * @inheritDoc
360 */ 374 */
361 public function filterDay(string $request) 375 public function getLatest(): ?Bookmark
362 { 376 {
363 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; 377 foreach ($this->search([], null, false, false, true) as $bookmark) {
378 return $bookmark;
379 }
364 380
365 return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility); 381 return null;
366 } 382 }
367 383
368 /** 384 /**
diff --git a/application/bookmark/BookmarkServiceInterface.php b/application/bookmark/BookmarkServiceInterface.php
index 9fa61533..08cdbb4e 100644
--- a/application/bookmark/BookmarkServiceInterface.php
+++ b/application/bookmark/BookmarkServiceInterface.php
@@ -156,22 +156,29 @@ interface BookmarkServiceInterface
156 public function bookmarksCountPerTag(array $filteringTags = [], ?string $visibility = null): array; 156 public function bookmarksCountPerTag(array $filteringTags = [], ?string $visibility = null): array;
157 157
158 /** 158 /**
159 * Returns the list of days containing articles (oldest first) 159 * Return a list of bookmark matching provided period of time.
160 * It also update directly previous and next date outside of given period found in the datastore.
160 * 161 *
161 * @return array containing days (in format YYYYMMDD). 162 * @param \DateTimeInterface $from Starting date.
163 * @param \DateTimeInterface $to Ending date.
164 * @param \DateTimeInterface|null $previous (by reference) updated with first created date found before $from.
165 * @param \DateTimeInterface|null $next (by reference) updated with first created date found after $to.
166 *
167 * @return array List of bookmarks matching provided period of time.
162 */ 168 */
163 public function days(): array; 169 public function findByDate(
170 \DateTimeInterface $from,
171 \DateTimeInterface $to,
172 ?\DateTimeInterface &$previous,
173 ?\DateTimeInterface &$next
174 ): array;
164 175
165 /** 176 /**
166 * Returns the list of articles for a given day. 177 * Returns the latest bookmark by creation date.
167 *
168 * @param string $request day to filter. Format: YYYYMMDD.
169 * 178 *
170 * @return Bookmark[] list of shaare found. 179 * @return Bookmark|null Found Bookmark or null if the datastore is empty.
171 *
172 * @throws BookmarkNotFoundException
173 */ 180 */
174 public function filterDay(string $request); 181 public function getLatest(): ?Bookmark;
175 182
176 /** 183 /**
177 * Creates the default database after a fresh install. 184 * Creates the default database after a fresh install.