diff options
author | Anna Larch <anna@nextcloud.com> | 2021-09-27 14:58:16 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-10-14 08:22:24 +0200 |
commit | a58d1e6b06d553927ff6b80822074e640ee66a9c (patch) | |
tree | 27472486e3dd55dca6311e7c9ad131d050156b6d /lib/private/Calendar | |
parent | b7ee885f930c32ab5412208a0e6cc13650735663 (diff) | |
download | nextcloud-server-a58d1e6b06d553927ff6b80822074e640ee66a9c.tar.gz nextcloud-server-a58d1e6b06d553927ff6b80822074e640ee66a9c.zip |
Add Public Calendar Provider
Signed-off-by: Anna Larch <anna@nextcloud.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Calendar')
-rw-r--r-- | lib/private/Calendar/CalendarQuery.php | 124 | ||||
-rw-r--r-- | lib/private/Calendar/Manager.php | 50 |
2 files changed, 173 insertions, 1 deletions
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); + } } |