Skip to content
Open
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
43 changes: 32 additions & 11 deletions apps/dav/lib/Search/EventsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\Search;

use OCA\DAV\CalDAV\CalDavBackend;
Expand All @@ -28,7 +29,8 @@
*
* @package OCA\DAV\Search
*/
class EventsSearchProvider extends ACalendarSearchProvider implements IFilteringProvider {
class EventsSearchProvider extends ACalendarSearchProvider implements IFilteringProvider
{
/**
* @var string[]
*/
Expand Down Expand Up @@ -57,21 +59,24 @@ class EventsSearchProvider extends ACalendarSearchProvider implements IFiltering
/**
* @inheritDoc
*/
public function getId(): string {
public function getId(): string
{
return 'calendar';
}

/**
* @inheritDoc
*/
public function getName(): string {
public function getName(): string
{
return $this->l10n->t('Events');
}

/**
* @inheritDoc
*/
public function getOrder(string $route, array $routeParameters): ?int {
public function getOrder(string $route, array $routeParameters): ?int
{
if ($this->appManager->isEnabledForUser('calendar')) {
return $route === 'calendar.View.index' ? -1 : 30;
}
Expand Down Expand Up @@ -115,6 +120,7 @@ public function search(
]
);
}

/** @var IUser|null $person */
$person = $query->getFilter('person')?->get();
$personDisplayName = $person?->getDisplayName();
Expand Down Expand Up @@ -147,6 +153,16 @@ public function search(
$searchResults[] = $attendeeResult;
}
}

// Sorting the search results by event start date (DTSTART)
usort($searchResults, function ($a, $b) {
$componentA = $this->getPrimaryComponent($a['calendardata'], self::$componentType);
$componentB = $this->getPrimaryComponent($b['calendardata'], self::$componentType);
$dateA = $componentA->DTSTART->getDateTime();

Check notice

Code scanning / Psalm

PossiblyNullReference

Cannot call method getDateTime on possibly null value

Check notice

Code scanning / Psalm

UndefinedMethod

Method Sabre\VObject\Property::getDateTime does not exist
$dateB = $componentB->DTSTART->getDateTime();

Check notice

Code scanning / Psalm

PossiblyNullReference

Cannot call method getDateTime on possibly null value

Check notice

Code scanning / Psalm

UndefinedMethod

Method Sabre\VObject\Property::getDateTime does not exist
return $dateB <=> $dateA;
});

$formattedResults = \array_map(function (array $eventRow) use ($calendarsById, $subscriptionsById): SearchResultEntry {
$component = $this->getPrimaryComponent($eventRow['calendardata'], self::$componentType);
$title = (string)($component->SUMMARY ?? $this->l10n->t('Untitled event'));
Expand Down Expand Up @@ -186,8 +202,8 @@ protected function getDeepLinkToCalendarApp(
// This route will automatically figure out what recurrence-id to open
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute('calendar.view.index')
. 'edit/'
. base64_encode($davUrl)
. 'edit/'
. base64_encode($davUrl)
);
}

Expand All @@ -204,7 +220,8 @@ protected function getDavUrlForCalendarObject(
. $calendarObjectUri;
}

protected function generateSubline(Component $eventComponent): string {
protected function generateSubline(Component $eventComponent): string

Check notice

Code scanning / Psalm

InvalidReturnType

The declared return type 'string' for OCA\DAV\Search\EventsSearchProvider::generateSubline is incorrect, got 'false|int|string'
{
$dtStart = $eventComponent->DTSTART;
$dtEnd = $this->getDTEndForEvent($eventComponent);
$isAllDayEvent = $dtStart instanceof Property\ICalendar\Date;
Expand Down Expand Up @@ -234,7 +251,8 @@ protected function generateSubline(Component $eventComponent): string {
return "$formattedStartDate $formattedStartTime - $formattedEndDate $formattedEndTime";
}

protected function getDTEndForEvent(Component $eventComponent):Property {
protected function getDTEndForEvent(Component $eventComponent): Property
{
if (isset($eventComponent->DTEND)) {
$end = $eventComponent->DTEND;
} elseif (isset($eventComponent->DURATION)) {
Expand Down Expand Up @@ -263,7 +281,8 @@ protected function isDayEqual(
return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
}

public function getSupportedFilters(): array {
public function getSupportedFilters(): array
{
return [
'term',
'person',
Expand All @@ -272,11 +291,13 @@ public function getSupportedFilters(): array {
];
}

public function getAlternateIds(): array {
public function getAlternateIds(): array
{
return [];
}

public function getCustomFilters(): array {
public function getCustomFilters(): array
{
return [];
}
}