Skip to content

Commit

Permalink
feat(caldav): Allow advanced search for events/tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Altahrim committed Sep 26, 2023
1 parent c78349b commit e11b170
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,12 @@ public function searchPrincipalUri(string $principalUri,
if (isset($options['offset'])) {
$calendarObjectIdQuery->setFirstResult($options['offset']);
}
if (isset($options['start']) && $options['start'] instanceof DateTimeInterface) {
$calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->lte('co.lastoccurence', $calendarObjectIdQuery->createNamedParameter($options['start']->getTimestamp())));
}
if (isset($options['end']) && $options['end'] instanceof DateTimeInterface) {
$calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->gte('co.firstoccurence', $calendarObjectIdQuery->createNamedParameter($options['end']->getTimestamp())));
}

$result = $calendarObjectIdQuery->executeQuery();
$matches = $result->fetchAll();
Expand Down Expand Up @@ -3172,7 +3178,7 @@ public function pruneOutdatedSyncTokens(int $keep = 10_000): int {
$maxId = (int) $result->fetchOne();
$result->closeCursor();
if (!$maxId || $maxId < $keep) {
return 0;
return 0;
}

$query = $this->db->getQueryBuilder();
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Search/EventsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @package OCA\DAV\Search
*/
class EventsSearchProvider extends ACalendarSearchProvider {

/**
* @var string[]
*/
Expand Down Expand Up @@ -107,13 +106,15 @@ public function search(IUser $user,

$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getTerm(),
$query->getFilter('term', ''),
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
'start' => $query->getFilter('start', null),
'end' => $query->getFilter('end', null),
]
);
$formattedResults = \array_map(function (array $eventRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Search/TasksSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
* @package OCA\DAV\Search
*/
class TasksSearchProvider extends ACalendarSearchProvider {

/**
* @var string[]
*/
Expand Down Expand Up @@ -100,13 +99,15 @@ public function search(IUser $user,

$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getTerm(),
$query->getFilter('term', ''),
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
'start' => $query->getFilter('start'),
'end' => $query->getFilter('end'),
]
);
$formattedResults = \array_map(function (array $taskRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
Expand Down

0 comments on commit e11b170

Please sign in to comment.