summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php22
-rw-r--r--lib/private/Calendar/CalendarQuery.php124
-rw-r--r--lib/private/Calendar/Manager.php50
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php9
-rw-r--r--lib/public/Calendar/ICalendar.php3
-rw-r--r--lib/public/Calendar/ICalendarProvider.php45
-rw-r--r--lib/public/Calendar/ICalendarQuery.php82
-rw-r--r--lib/public/Calendar/IManager.php29
10 files changed, 369 insertions, 1 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 823eef1fde3..353fc22d486 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -117,6 +117,8 @@ return array(
'OCP\\Broadcast\\Events\\IBroadcastEvent' => $baseDir . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
+ 'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',
+ 'OCP\\Calendar\\ICalendarQuery' => $baseDir . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\IManager' => $baseDir . '/lib/public/Calendar/IManager.php',
'OCP\\Calendar\\IMetadataProvider' => $baseDir . '/lib/public/Calendar/IMetadataProvider.php',
'OCP\\Calendar\\Resource\\IBackend' => $baseDir . '/lib/public/Calendar/Resource/IBackend.php',
@@ -759,6 +761,7 @@ return array(
'OC\\Broadcast\\Events\\BroadcastEvent' => $baseDir . '/lib/private/Broadcast/Events/BroadcastEvent.php',
'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php',
+ 'OC\\Calendar\\CalendarQuery' => $baseDir . '/lib/private/Calendar/CalendarQuery.php',
'OC\\Calendar\\Manager' => $baseDir . '/lib/private/Calendar/Manager.php',
'OC\\Calendar\\Resource\\Manager' => $baseDir . '/lib/private/Calendar/Resource/Manager.php',
'OC\\Calendar\\Room\\Manager' => $baseDir . '/lib/private/Calendar/Room/Manager.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 81cd22b0570..f7c541d8c31 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -146,6 +146,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Broadcast\\Events\\IBroadcastEvent' => __DIR__ . '/../../..' . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
+ 'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
+ 'OCP\\Calendar\\ICalendarQuery' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\IManager' => __DIR__ . '/../../..' . '/lib/public/Calendar/IManager.php',
'OCP\\Calendar\\IMetadataProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/IMetadataProvider.php',
'OCP\\Calendar\\Resource\\IBackend' => __DIR__ . '/../../..' . '/lib/public/Calendar/Resource/IBackend.php',
@@ -788,6 +790,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Broadcast\\Events\\BroadcastEvent' => __DIR__ . '/../../..' . '/lib/private/Broadcast/Events/BroadcastEvent.php',
'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php',
+ 'OC\\Calendar\\CalendarQuery' => __DIR__ . '/../../..' . '/lib/private/Calendar/CalendarQuery.php',
'OC\\Calendar\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Manager.php',
'OC\\Calendar\\Resource\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Resource/Manager.php',
'OC\\Calendar\\Room\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Room/Manager.php',
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 30ac63281d1..8eed6a5bde4 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -35,6 +35,7 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Services\InitialStateProvider;
use OCP\Authentication\IAlternativeLogin;
+use OCP\Calendar\ICalendarProvider;
use OCP\Capabilities\ICapability;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
@@ -95,6 +96,9 @@ class RegistrationContext {
/** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */
private $twoFactorProviders = [];
+ /** @var ServiceRegistration<ICalendarProvider>[] */
+ private $calendarProviders = [];
+
/** @var LoggerInterface */
private $logger;
@@ -225,6 +229,13 @@ class RegistrationContext {
$twoFactorProviderClass
);
}
+
+ public function registerCalendarProvider(string $class): void {
+ $this->context->registerCalendarProvider(
+ $this->appId,
+ $class
+ );
+ }
};
}
@@ -300,6 +311,10 @@ class RegistrationContext {
$this->twoFactorProviders[] = new ServiceRegistration($appId, $class);
}
+ public function registerCalendarProvider(string $appId, string $class): void {
+ $this->calendarProviders[] = new ServiceRegistration($appId, $class);
+ }
+
/**
* @param App[] $apps
*/
@@ -530,4 +545,11 @@ class RegistrationContext {
public function getTwoFactorProviders(): array {
return $this->twoFactorProviders;
}
+
+ /**
+ * @return ServiceRegistration<ICalendarProvider>[]
+ */
+ public function getCalendarProviders(): array {
+ return $this->calendarProviders;
+ }
}
diff --git a/lib/private/Calendar/CalendarQuery.php b/lib/private/Calendar/CalendarQuery.php
new file mode 100644
index 00000000000..6b4e2b3be16
--- /dev/null
+++ b/lib/private/Calendar/CalendarQuery.php
@@ -0,0 +1,124 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2021 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OC\Calendar;
+
+use OCP\Calendar\ICalendarQuery;
+
+class CalendarQuery implements ICalendarQuery {
+
+ /** @var string */
+ private $principalUri;
+
+ /** @var array */
+ public $searchProperties;
+
+ /** @var string|null */
+ private $searchPattern;
+
+ /** @var array */
+ private $options;
+
+ /** @var int|null */
+ private $offset;
+
+ /** @var int|null */
+ private $limit;
+
+ /** @var array */
+ private $calendarUris;
+
+ public function __construct(string $principalUri) {
+ $this->principalUri = $principalUri;
+ $this->searchProperties = [];
+ $this->options = [
+ 'types' => [],
+ ];
+ }
+
+ public function getPrincipalUri(): string {
+ return $this->principalUri;
+ }
+
+ public function setPrincipalUri(string $principalUri): void {
+ $this->principalUri = $principalUri;
+ }
+
+ public function setSearchPattern(string $pattern): void {
+ $this->searchPattern = $pattern;
+ }
+
+ public function getSearchPattern(): ?string {
+ return $this->searchPattern;
+ }
+
+ public function addSearchProperty(string $value): void {
+ $this->searchProperties[] = $value;
+ }
+
+ public function getSearchProperties(): array {
+ return $this->searchProperties;
+ }
+
+ public function addSearchCalendar(string $calendarUri): void {
+ $this->calendarUris[] = $calendarUri;
+ }
+
+ public function getCalendarUris(): array {
+ return $this->calendarUris;
+ }
+
+ public function getLimit(): ?int {
+ return $this->limit;
+ }
+
+ public function setLimit(int $limit): void {
+ $this->limit = $limit;
+ }
+
+ public function getOffset(): ?int {
+ return $this->offset;
+ }
+
+ public function setOffset(int $offset): void {
+ $this->offset = $offset;
+ }
+
+ public function addType(string $value): void {
+ $this->options['types'][] = $value;
+ }
+
+ public function setTimerangeStart(\DateTimeImmutable $startTime): void {
+ $this->options['timerange']['start'] = $startTime;
+ }
+
+ public function setTimerangeEnd(\DateTimeImmutable $endTime): void {
+ $this->options['timerange']['end'] = $endTime;
+ }
+
+ public function getOptions(): array {
+ return $this->options;
+ }
+}
diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php
index ab22c3ba7b8..30ee60e4943 100644
--- a/lib/private/Calendar/Manager.php
+++ b/lib/private/Calendar/Manager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,9 +26,13 @@
*/
namespace OC\Calendar;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Calendar\ICalendar;
+use OCP\Calendar\ICalendarProvider;
+use OCP\Calendar\ICalendarQuery;
+use OCP\Calendar\IManager;
-class Manager implements \OCP\Calendar\IManager {
+class Manager implements IManager {
/**
* @var ICalendar[] holds all registered calendars
@@ -37,6 +44,13 @@ class Manager implements \OCP\Calendar\IManager {
*/
private $calendarLoaders = [];
+ /** @var Coordinator */
+ private $coordinator;
+
+ public function __construct(Coordinator $coordinator) {
+ $this->coordinator = $coordinator;
+ }
+
/**
* This function is used to search and find objects within the user's calendars.
* In case $pattern is empty all events/journals/todos will be returned.
@@ -137,4 +151,38 @@ class Manager implements \OCP\Calendar\IManager {
}
$this->calendarLoaders = [];
}
+
+ public function searchForPrincipal(ICalendarQuery $query): array {
+ $context = $this->coordinator->getRegistrationContext();
+ if ($context === null) {
+ return [];
+ }
+
+ /** @var CalendarQuery $query */
+ $calendars = array_merge(...array_map(static function (ICalendarProvider $p) use ($query) {
+ return $p->getCalendars($query->getPrincipalUri(), $query->getCalendarUris());
+ }, $context->getCalendarProviders()));
+
+ $results = [];
+ /** @var ICalendar $calendar */
+ foreach ($calendars as $calendar) {
+ $r = $calendar->search(
+ $query->getSearchPattern() ?? '',
+ $query->getSearchProperties(),
+ $query->getOptions(),
+ $query->getLimit(),
+ $query->getOffset()
+ );
+
+ foreach ($r as $o) {
+ $o['calendar-key'] = $calendar->getKey();
+ $results[] = $o;
+ }
+ }
+ return $results;
+ }
+
+ public function newQuery(string $principalUri): ICalendarQuery {
+ return new CalendarQuery($principalUri);
+ }
}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 589140d3edd..d396c619923 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -228,4 +228,13 @@ interface IRegistrationContext {
* @since 22.0.0
*/
public function registerTwoFactorProvider(string $twoFactorProviderClass): void;
+
+ /**
+ * Register a calendar provider
+ *
+ * @param string $class
+ * @psalm-param class-string<IProvider> $class
+ * @since 23.0.0
+ */
+ public function registerCalendarProvider(string $class): void;
}
diff --git a/lib/public/Calendar/ICalendar.php b/lib/public/Calendar/ICalendar.php
index ebaa7c50f84..551870de20e 100644
--- a/lib/public/Calendar/ICalendar.php
+++ b/lib/public/Calendar/ICalendar.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
*
diff --git a/lib/public/Calendar/ICalendarProvider.php b/lib/public/Calendar/ICalendarProvider.php
new file mode 100644
index 00000000000..d135910b08c
--- /dev/null
+++ b/lib/public/Calendar/ICalendarProvider.php
@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2021 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Calendar;
+
+/**
+ * This interface defines a lazy loading mechanism for
+ * calendars for Public Consumption
+ *
+ * @since 23.0.0
+ */
+interface ICalendarProvider {
+
+ /**
+ * @param string $principalUri
+ * @param string[] $calendarUris
+ * @return ICalendar[]
+ * @since 23.0.0
+ */
+ public function getCalendars(string $principalUri, array $calendarUris = []): array;
+}
diff --git a/lib/public/Calendar/ICalendarQuery.php b/lib/public/Calendar/ICalendarQuery.php
new file mode 100644
index 00000000000..142810d3fb9
--- /dev/null
+++ b/lib/public/Calendar/ICalendarQuery.php
@@ -0,0 +1,82 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2021 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Calendar;
+
+use DateTimeImmutable;
+
+/**
+ * Build a flexible, extendable query to the CalDAV backend
+ *
+ * @since 23.0.0
+ */
+interface ICalendarQuery {
+
+ /**
+ * Limit the results to the calendar uri(s)
+ *
+ * @since 23.0.0
+ */
+ public function addSearchCalendar(string $calendarUri): void;
+
+ /**
+ * Search the property values
+ *
+ * @since 23.0.0
+ */
+ public function setSearchPattern(string $pattern): void;
+
+ /**
+ * Define the property name(s) to search for
+ *
+ * @since 23.0.0
+ */
+ public function addSearchProperty(string $value): void;
+
+ /**
+ * @since 23.0.0
+ */
+ public function addType(string $value): void;
+
+ /**
+ * @since 23.0.0
+ */
+ public function setTimerangeStart(DateTimeImmutable $startTime): void;
+
+ /**
+ * @since 23.0.0
+ */
+ public function setTimerangeEnd(DateTimeImmutable $endTime): void;
+
+ /**
+ * @since 23.0.0
+ */
+ public function setLimit(int $limit): void;
+
+ /**
+ * @since 23.0.0
+ */
+ public function setOffset(int $offset): void;
+}
diff --git a/lib/public/Calendar/IManager.php b/lib/public/Calendar/IManager.php
index df4c993b2b5..eb4113bba99 100644
--- a/lib/public/Calendar/IManager.php
+++ b/lib/public/Calendar/IManager.php
@@ -1,9 +1,13 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Georg Ehrke <oc.list@georgehrke.com>
+ * @author Anna Larch <anna.larch@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
@@ -67,6 +71,7 @@ interface IManager {
* @param integer|null $offset - offset for paging of search results
* @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs
* @since 13.0.0
+ * @deprecated 23.0.0 use \OCP\Calendar\IManager::searchForPrincipal
*/
public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null);
@@ -75,6 +80,7 @@ interface IManager {
*
* @return bool true if enabled, false if not
* @since 13.0.0
+ * @deprecated 23.0.0
*/
public function isEnabled();
@@ -84,6 +90,7 @@ interface IManager {
* @param ICalendar $calendar
* @return void
* @since 13.0.0
+ * @deprecated 23.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerCalendarProvider
*/
public function registerCalendar(ICalendar $calendar);
@@ -93,6 +100,7 @@ interface IManager {
* @param ICalendar $calendar
* @return void
* @since 13.0.0
+ * @deprecated 23.0.0
*/
public function unregisterCalendar(ICalendar $calendar);
@@ -103,19 +111,40 @@ interface IManager {
* @param \Closure $callable
* @return void
* @since 13.0.0
+ * @deprecated 23.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerCalendarProvider
*/
public function register(\Closure $callable);
/**
* @return ICalendar[]
* @since 13.0.0
+ * @deprecated 23.0.0
*/
public function getCalendars();
/**
* removes all registered calendar instances
+ *
* @return void
* @since 13.0.0
+ * @deprecated 23.0.0
*/
public function clear();
+
+ /**
+ * Query a principals calendar(s)
+ *
+ * @param ICalendarQuery $query
+ * @return array[]
+ * @since 23.0.0
+ */
+ public function searchForPrincipal(ICalendarQuery $query): array;
+
+ /**
+ * Build a new query for searchForPrincipal
+ *
+ * @return ICalendarQuery
+ * @since 23.0.0
+ */
+ public function newQuery(string $principalUri) : ICalendarQuery;
}