aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-09-26 11:07:49 +0200
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-11-10 09:21:16 +0100
commit3545a1c613b8310fd5956517c91bac48e73fbd20 (patch)
tree6d19e37896d17185ee4b4340f1aad5807a40ca8b /apps/dav/lib/CalDAV
parenta75a93af8e140809abe50429601cb3d07f35245c (diff)
downloadnextcloud-server-3545a1c613b8310fd5956517c91bac48e73fbd20.tar.gz
nextcloud-server-3545a1c613b8310fd5956517c91bac48e73fbd20.zip
feat(caldav): Allow advanced search for events/tasks
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php73
1 files changed, 40 insertions, 33 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 249dbca9f71..5a55a9bbbef 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -208,36 +208,22 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*/
protected array $userDisplayNames;
- private IDBConnection $db;
private Backend $calendarSharingBackend;
- private Principal $principalBackend;
- private IUserManager $userManager;
- private ISecureRandom $random;
- private LoggerInterface $logger;
- private IEventDispatcher $dispatcher;
- private IConfig $config;
- private bool $legacyEndpoint;
private string $dbObjectPropertiesTable = 'calendarobjects_props';
private array $cachedObjects = [];
- public function __construct(IDBConnection $db,
- Principal $principalBackend,
- IUserManager $userManager,
- IGroupManager $groupManager,
- ISecureRandom $random,
- LoggerInterface $logger,
- IEventDispatcher $dispatcher,
- IConfig $config,
- bool $legacyEndpoint = false) {
- $this->db = $db;
- $this->principalBackend = $principalBackend;
- $this->userManager = $userManager;
+ public function __construct(
+ private IDBConnection $db,
+ private Principal $principalBackend,
+ private IUserManager $userManager,
+ IGroupManager $groupManager,
+ private ISecureRandom $random,
+ private LoggerInterface $logger,
+ private IEventDispatcher $dispatcher,
+ private IConfig $config,
+ private bool $legacyEndpoint = false,
+ ) {
$this->calendarSharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'calendar');
- $this->random = $random;
- $this->logger = $logger;
- $this->dispatcher = $dispatcher;
- $this->config = $config;
- $this->legacyEndpoint = $legacyEndpoint;
}
/**
@@ -1855,8 +1841,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*
* @return array
*/
- public function search(array $calendarInfo, $pattern, array $searchProperties,
- array $options, $limit, $offset) {
+ public function search(
+ array $calendarInfo,
+ $pattern,
+ array $searchProperties,
+ array $options,
+ $limit,
+ $offset
+ ) {
$outerQuery = $this->db->getQueryBuilder();
$innerQuery = $this->db->getQueryBuilder();
@@ -2074,11 +2066,12 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @return array
*/
public function searchPrincipalUri(string $principalUri,
- string $pattern,
- array $componentTypes,
- array $searchProperties,
- array $searchParameters,
- array $options = []): array {
+ string $pattern,
+ array $componentTypes,
+ array $searchProperties,
+ array $searchParameters,
+ array $options = []
+ ): array {
return $this->atomic(function () use ($principalUri, $pattern, $componentTypes, $searchProperties, $searchParameters, $options) {
$escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
@@ -2160,6 +2153,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
if (isset($options['offset'])) {
$calendarObjectIdQuery->setFirstResult($options['offset']);
}
+ if (isset($options['timerange'])) {
+ if (isset($options['timerange']['start']) && $options['timerange']['start'] instanceof DateTimeInterface) {
+ $calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->gt(
+ 'lastoccurence',
+ $calendarObjectIdQuery->createNamedParameter($options['timerange']['start']->getTimeStamp()),
+ ));
+ }
+ if (isset($options['timerange']['end']) && $options['timerange']['end'] instanceof DateTimeInterface) {
+ $calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->lt(
+ 'firstoccurence',
+ $calendarObjectIdQuery->createNamedParameter($options['timerange']['end']->getTimeStamp()),
+ ));
+ }
+ }
$result = $calendarObjectIdQuery->executeQuery();
$matches = [];
@@ -3187,7 +3194,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$maxId = (int) $result->fetchOne();
$result->closeCursor();
if (!$maxId || $maxId < $keep) {
- return 0;
+ return 0;
}
$query = $this->db->getQueryBuilder();