mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Add Public Calendar Provider
Signed-off-by: Anna Larch <anna@nextcloud.com> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
b7ee885f93
commit
a58d1e6b06
16 changed files with 476 additions and 21 deletions
|
|
@ -43,6 +43,7 @@ return array(
|
|||
'OCA\\DAV\\CalDAV\\CalendarImpl' => $baseDir . '/../lib/CalDAV/CalendarImpl.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarManager' => $baseDir . '/../lib/CalDAV/CalendarManager.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarObject' => $baseDir . '/../lib/CalDAV/CalendarObject.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarProvider' => $baseDir . '/../lib/CalDAV/CalendarProvider.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarRoot' => $baseDir . '/../lib/CalDAV/CalendarRoot.php',
|
||||
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => $baseDir . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
|
||||
'OCA\\DAV\\CalDAV\\IRestorable' => $baseDir . '/../lib/CalDAV/IRestorable.php',
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class ComposerStaticInitDAV
|
|||
'OCA\\DAV\\CalDAV\\CalendarImpl' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarImpl.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarManager' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarManager.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarObject' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarObject.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarProvider' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarProvider.php',
|
||||
'OCA\\DAV\\CalDAV\\CalendarRoot' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarRoot.php',
|
||||
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
|
||||
'OCA\\DAV\\CalDAV\\IRestorable' => __DIR__ . '/..' . '/../lib/CalDAV/IRestorable.php',
|
||||
|
|
|
|||
|
|
@ -1845,17 +1845,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$outerQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));
|
||||
|
||||
// only return public items for shared calendars for now
|
||||
if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
|
||||
if (isset($calendarInfo['{http://owncloud.org/ns}owner-principal']) === false || $calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
|
||||
$innerQuery->andWhere($innerQuery->expr()->eq('c.classification',
|
||||
$outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
|
||||
}
|
||||
|
||||
$or = $innerQuery->expr()->orX();
|
||||
foreach ($searchProperties as $searchProperty) {
|
||||
$or->add($innerQuery->expr()->eq('op.name',
|
||||
$outerQuery->createNamedParameter($searchProperty)));
|
||||
if (!empty($searchProperties)) {
|
||||
$or = $innerQuery->expr()->orX();
|
||||
foreach ($searchProperties as $searchProperty) {
|
||||
$or->add($innerQuery->expr()->eq('op.name',
|
||||
$outerQuery->createNamedParameter($searchProperty)));
|
||||
}
|
||||
$innerQuery->andWhere($or);
|
||||
}
|
||||
$innerQuery->andWhere($or);
|
||||
|
||||
if ($pattern !== '') {
|
||||
$innerQuery->andWhere($innerQuery->expr()->iLike('op.value',
|
||||
|
|
@ -1878,7 +1880,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($options['types'])) {
|
||||
if (!empty($options['types'])) {
|
||||
$or = $outerQuery->expr()->orX();
|
||||
foreach ($options['types'] as $type) {
|
||||
$or->add($outerQuery->expr()->eq('componenttype',
|
||||
|
|
@ -1887,8 +1889,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$outerQuery->andWhere($or);
|
||||
}
|
||||
|
||||
$outerQuery->andWhere($outerQuery->expr()->in('c.id',
|
||||
$outerQuery->createFunction($innerQuery->getSQL())));
|
||||
$outerQuery->andWhere($outerQuery->expr()->in('c.id', $outerQuery->createFunction($innerQuery->getSQL())));
|
||||
|
||||
if ($offset) {
|
||||
$outerQuery->setFirstResult($offset);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
|
|
@ -51,7 +54,7 @@ class CalendarImpl implements ICalendar {
|
|||
$this->calendarInfo = $calendarInfo;
|
||||
$this->backend = $backend;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string defining the technical unique key
|
||||
* @since 13.0.0
|
||||
|
|
|
|||
72
apps/dav/lib/CalDAV/CalendarProvider.php
Normal file
72
apps/dav/lib/CalDAV/CalendarProvider.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?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 OCA\DAV\CalDAV;
|
||||
|
||||
use OCP\Calendar\ICalendarProvider;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
|
||||
class CalendarProvider implements ICalendarProvider {
|
||||
|
||||
/** @var CalDavBackend */
|
||||
private $calDavBackend;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config) {
|
||||
$this->calDavBackend = $calDavBackend;
|
||||
$this->l10n = $l10n;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getCalendars(string $principalUri, array $calendarUris = []): array {
|
||||
$calendarInfos = [];
|
||||
if (empty($calendarUris)) {
|
||||
$calendarInfos[] = $this->calDavBackend->getCalendarsForUser($principalUri);
|
||||
} else {
|
||||
foreach ($calendarUris as $calendarUri) {
|
||||
$calendarInfos[] = $this->calDavBackend->getCalendarByUri($principalUri, $calendarUri);
|
||||
}
|
||||
}
|
||||
|
||||
$calendarInfos = array_filter($calendarInfos);
|
||||
|
||||
$iCalendars = [];
|
||||
foreach ($calendarInfos as $calendarInfo) {
|
||||
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config);
|
||||
$iCalendars[] = new CalendarImpl(
|
||||
$calendar,
|
||||
$calendarInfo,
|
||||
$this->calDavBackend,
|
||||
);
|
||||
}
|
||||
return $iCalendars;
|
||||
}
|
||||
}
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
124
lib/private/Calendar/CalendarQuery.php
Normal file
124
lib/private/Calendar/CalendarQuery.php
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
|
|
|
|||
45
lib/public/Calendar/ICalendarProvider.php
Normal file
45
lib/public/Calendar/ICalendarProvider.php
Normal file
|
|
@ -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;
|
||||
}
|
||||
82
lib/public/Calendar/ICalendarQuery.php
Normal file
82
lib/public/Calendar/ICalendarQuery.php
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,26 +23,35 @@
|
|||
|
||||
namespace Test\Calendar;
|
||||
|
||||
use OC\AppFramework\Bootstrap\Coordinator;
|
||||
use OC\Calendar\Manager;
|
||||
use OCP\Calendar\ICalendar;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ManagerTest extends TestCase {
|
||||
|
||||
/** @var Coordinator|MockObject */
|
||||
private $coordinator;
|
||||
|
||||
/** @var Manager */
|
||||
private $manager;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->manager = new Manager();
|
||||
$this->coordinator = $this->createMock(Coordinator::class);
|
||||
|
||||
$this->manager = new Manager(
|
||||
$this->coordinator
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider searchProvider
|
||||
*/
|
||||
public function testSearch($search1, $search2, $expected) {
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar1 */
|
||||
/** @var ICalendar | MockObject $calendar1 */
|
||||
$calendar1 = $this->createMock(ICalendar::class);
|
||||
$calendar1->method('getKey')->willReturn('simple:1');
|
||||
$calendar1->expects($this->once())
|
||||
|
|
@ -50,7 +59,7 @@ class ManagerTest extends TestCase {
|
|||
->with('', [], [], null, null)
|
||||
->willReturn($search1);
|
||||
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar2 */
|
||||
/** @var ICalendar | MockObject $calendar2 */
|
||||
$calendar2 = $this->createMock(ICalendar::class);
|
||||
$calendar2->method('getKey')->willReturn('simple:2');
|
||||
$calendar2->expects($this->once())
|
||||
|
|
@ -69,7 +78,7 @@ class ManagerTest extends TestCase {
|
|||
* @dataProvider searchProvider
|
||||
*/
|
||||
public function testSearchOptions($search1, $search2, $expected) {
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar1 */
|
||||
/** @var ICalendar | MockObject $calendar1 */
|
||||
$calendar1 = $this->createMock(ICalendar::class);
|
||||
$calendar1->method('getKey')->willReturn('simple:1');
|
||||
$calendar1->expects($this->once())
|
||||
|
|
@ -78,7 +87,7 @@ class ManagerTest extends TestCase {
|
|||
['timerange' => ['start' => null, 'end' => null]], 5, 20)
|
||||
->willReturn($search1);
|
||||
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar2 */
|
||||
/** @var ICalendar | MockObject $calendar2 */
|
||||
$calendar2 = $this->createMock(ICalendar::class);
|
||||
$calendar2->method('getKey')->willReturn('simple:2');
|
||||
$calendar2->expects($this->once())
|
||||
|
|
@ -150,11 +159,11 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testRegisterUnregister() {
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar1 */
|
||||
/** @var ICalendar | MockObject $calendar1 */
|
||||
$calendar1 = $this->createMock(ICalendar::class);
|
||||
$calendar1->method('getKey')->willReturn('key1');
|
||||
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar2 */
|
||||
/** @var ICalendar | MockObject $calendar2 */
|
||||
$calendar2 = $this->createMock(ICalendar::class);
|
||||
$calendar2->method('getKey')->willReturn('key2');
|
||||
|
||||
|
|
@ -174,11 +183,11 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testGetCalendars() {
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar1 */
|
||||
/** @var ICalendar | MockObject $calendar1 */
|
||||
$calendar1 = $this->createMock(ICalendar::class);
|
||||
$calendar1->method('getKey')->willReturn('key1');
|
||||
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar2 */
|
||||
/** @var ICalendar | MockObject $calendar2 */
|
||||
$calendar2 = $this->createMock(ICalendar::class);
|
||||
$calendar2->method('getKey')->willReturn('key2');
|
||||
|
||||
|
|
@ -203,7 +212,7 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testIfEnabledIfSo() {
|
||||
/** @var ICalendar | \PHPUnit\Framework\MockObject\MockObject $calendar */
|
||||
/** @var ICalendar | MockObject $calendar */
|
||||
$calendar = $this->createMock(ICalendar::class);
|
||||
$this->manager->registerCalendar($calendar);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue