diff options
author | Anna <anna@nextcloud.com> | 2022-10-28 11:48:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 11:48:14 +0300 |
commit | 9d2741d34e914985a797c7747546a0dd95b407a6 (patch) | |
tree | a31efbe1551143125e4dd415833fe6db2814973a | |
parent | 10adcac6a8f453827824cbcd3a7440d4163d7195 (diff) | |
parent | a5448476a36b7fb53e3464f2bd3e8010a5f28a4f (diff) |
Merge pull request #4689 from nextcloud/fix/search-daterange-empty
Fix mobile widget showing past events and limiting results too much
-rw-r--r-- | lib/Dashboard/CalendarWidget.php | 12 | ||||
-rw-r--r-- | tests/php/unit/Dashbaord/CalendarWidgetTest.php | 2 |
2 files changed, 3 insertions, 11 deletions
diff --git a/lib/Dashboard/CalendarWidget.php b/lib/Dashboard/CalendarWidget.php index cebe2662..662cf24f 100644 --- a/lib/Dashboard/CalendarWidget.php +++ b/lib/Dashboard/CalendarWidget.php @@ -142,21 +142,13 @@ class CalendarWidget implements IAPIWidget, IButtonWidget, IIconWidget, IOptionW * @param string|null $since Use any PHP DateTime allowed values to get future dates * @param int $limit Max 14 items is the default */ - public function getItems(string $userId, ?string $since = null, int $limit = 14): array { + public function getItems(string $userId, ?string $since = null, int $limit = 7): array { $calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $userId); $count = count($calendars); if ($count === 0) { return []; } - $limitPerCalendar = (int)round(($limit / $count)) ?? 1; $dateTime = (new DateTimeImmutable())->setTimestamp($this->timeFactory->getTime()); - if ($since !== null) { - try { - $dateTime = new DateTimeImmutable($since); - } catch (\Exception $e) { - // silently drop the exception and proceed with "now" - } - } $inTwoWeeks = $dateTime->add(new DateInterval('P14D')); $options = [ 'timerange' => [ @@ -166,7 +158,7 @@ class CalendarWidget implements IAPIWidget, IButtonWidget, IIconWidget, IOptionW ]; $widgetItems = []; foreach ($calendars as $calendar) { - $searchResult = $calendar->search('', [], $options, $limitPerCalendar); + $searchResult = $calendar->search('', [], $options, $limit); foreach ($searchResult as $calendarEvent) { /** @var DateTimeImmutable $startDate */ $startDate = $calendarEvent['objects'][0]['DTSTART'][0]; diff --git a/tests/php/unit/Dashbaord/CalendarWidgetTest.php b/tests/php/unit/Dashbaord/CalendarWidgetTest.php index 58907b2c..81c608e4 100644 --- a/tests/php/unit/Dashbaord/CalendarWidgetTest.php +++ b/tests/php/unit/Dashbaord/CalendarWidgetTest.php @@ -137,7 +137,7 @@ class CalendarWidgetTest extends TestCase { 'end' => $twoWeeks, ] ]; - $limit = 14; + $limit = 7; $result = [ 'id' => '3599', 'uid' => '59d30b6c-5a31-4d28-b1d6-c8f928180e96', |