Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/Dashboard/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,23 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
foreach ($calendars as $calendar) {
$searchResult = $calendar->search('', [], $options, $limit);
foreach ($searchResult as $calendarEvent) {
/** @var DateTimeImmutable $startDate */
$startDate = $calendarEvent['objects'][0]['DTSTART'][0];
// Find first recurrence in the future
$recurrence = null;
foreach ($calendarEvent['objects'] as $object) {
/** @var DateTimeImmutable $startDate */
$startDate = $object['DTSTART'][0];
if ($startDate->getTimestamp() >= $dateTime->getTimestamp()) {
$recurrence = $object;
break;
}
}

if ($recurrence === null) {
continue;
}

$widget = new WidgetItem(
$calendarEvent['objects'][0]['SUMMARY'][0] ?? 'New Event',
$recurrence['SUMMARY'][0] ?? 'New Event',
$this->dateTimeFormatter->formatTimeSpan(DateTime::createFromImmutable($startDate)),
$this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('calendar.view.index', ['objectId' => $calendarEvent['uid']])),
$this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('calendar.view.getCalendarDotSvg', ['color' => $calendar->getDisplayColor() ?? '#0082c9'])), // default NC blue fallback
Expand All @@ -167,6 +180,11 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
$widgetItems[] = $widget;
}
}

usort($widgetItems, static function (WidgetItem $a, WidgetItem $b) {
return (int)$a->getSinceId() - (int)$b->getSinceId();
});

return $widgetItems;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Dashboard/CalendarWidgetV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public function getItemsV2(string $userId, ?string $since = null, int $limit = 7
$halfEmptyContentMessage = '';
if (!empty($widgetItems)) {
$startOfTomorrow = $this->timeFactory->getDateTime('tomorrow')->getTimestamp();
foreach ($widgetItems as $item) {
if ((int)$item->getSinceId() >= $startOfTomorrow) {
$halfEmptyContentMessage = $this->l10n->t('No more events today');
}
if ($widgetItems[0]->getSinceId() >= $startOfTomorrow) {
$halfEmptyContentMessage = $this->l10n->t('No more events today');
}
}

Expand Down