Skip to content

Commit b1c761d

Browse files
Merge pull request #28970 from nextcloud/enhancement/calendar-appointments
Add an API for calendar providers
2 parents f95a268 + a58d1e6 commit b1c761d

16 files changed

Lines changed: 476 additions & 21 deletions

File tree

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'OCA\\DAV\\CalDAV\\CalendarImpl' => $baseDir . '/../lib/CalDAV/CalendarImpl.php',
4444
'OCA\\DAV\\CalDAV\\CalendarManager' => $baseDir . '/../lib/CalDAV/CalendarManager.php',
4545
'OCA\\DAV\\CalDAV\\CalendarObject' => $baseDir . '/../lib/CalDAV/CalendarObject.php',
46+
'OCA\\DAV\\CalDAV\\CalendarProvider' => $baseDir . '/../lib/CalDAV/CalendarProvider.php',
4647
'OCA\\DAV\\CalDAV\\CalendarRoot' => $baseDir . '/../lib/CalDAV/CalendarRoot.php',
4748
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => $baseDir . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
4849
'OCA\\DAV\\CalDAV\\IRestorable' => $baseDir . '/../lib/CalDAV/IRestorable.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ComposerStaticInitDAV
5858
'OCA\\DAV\\CalDAV\\CalendarImpl' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarImpl.php',
5959
'OCA\\DAV\\CalDAV\\CalendarManager' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarManager.php',
6060
'OCA\\DAV\\CalDAV\\CalendarObject' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarObject.php',
61+
'OCA\\DAV\\CalDAV\\CalendarProvider' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarProvider.php',
6162
'OCA\\DAV\\CalDAV\\CalendarRoot' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarRoot.php',
6263
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
6364
'OCA\\DAV\\CalDAV\\IRestorable' => __DIR__ . '/..' . '/../lib/CalDAV/IRestorable.php',

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,17 +1845,19 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
18451845
$outerQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));
18461846

18471847
// only return public items for shared calendars for now
1848-
if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
1848+
if (isset($calendarInfo['{http://owncloud.org/ns}owner-principal']) === false || $calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
18491849
$innerQuery->andWhere($innerQuery->expr()->eq('c.classification',
18501850
$outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
18511851
}
18521852

1853-
$or = $innerQuery->expr()->orX();
1854-
foreach ($searchProperties as $searchProperty) {
1855-
$or->add($innerQuery->expr()->eq('op.name',
1856-
$outerQuery->createNamedParameter($searchProperty)));
1853+
if (!empty($searchProperties)) {
1854+
$or = $innerQuery->expr()->orX();
1855+
foreach ($searchProperties as $searchProperty) {
1856+
$or->add($innerQuery->expr()->eq('op.name',
1857+
$outerQuery->createNamedParameter($searchProperty)));
1858+
}
1859+
$innerQuery->andWhere($or);
18571860
}
1858-
$innerQuery->andWhere($or);
18591861

18601862
if ($pattern !== '') {
18611863
$innerQuery->andWhere($innerQuery->expr()->iLike('op.value',
@@ -1878,7 +1880,7 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
18781880
}
18791881
}
18801882

1881-
if (isset($options['types'])) {
1883+
if (!empty($options['types'])) {
18821884
$or = $outerQuery->expr()->orX();
18831885
foreach ($options['types'] as $type) {
18841886
$or->add($outerQuery->expr()->eq('componenttype',
@@ -1887,8 +1889,7 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
18871889
$outerQuery->andWhere($or);
18881890
}
18891891

1890-
$outerQuery->andWhere($outerQuery->expr()->in('c.id',
1891-
$outerQuery->createFunction($innerQuery->getSQL())));
1892+
$outerQuery->andWhere($outerQuery->expr()->in('c.id', $outerQuery->createFunction($innerQuery->getSQL())));
18921893

18931894
if ($offset) {
18941895
$outerQuery->setFirstResult($offset);

apps/dav/lib/CalDAV/CalendarImpl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
47
*
@@ -51,7 +54,7 @@ public function __construct(Calendar $calendar, array $calendarInfo,
5154
$this->calendarInfo = $calendarInfo;
5255
$this->backend = $backend;
5356
}
54-
57+
5558
/**
5659
* @return string defining the technical unique key
5760
* @since 13.0.0
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
7+
*
8+
* @author Anna Larch <anna.larch@gmx.net>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\DAV\CalDAV;
27+
28+
use OCP\Calendar\ICalendarProvider;
29+
use OCP\IConfig;
30+
use OCP\IL10N;
31+
32+
class CalendarProvider implements ICalendarProvider {
33+
34+
/** @var CalDavBackend */
35+
private $calDavBackend;
36+
37+
/** @var IL10N */
38+
private $l10n;
39+
40+
/** @var IConfig */
41+
private $config;
42+
43+
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config) {
44+
$this->calDavBackend = $calDavBackend;
45+
$this->l10n = $l10n;
46+
$this->config = $config;
47+
}
48+
49+
public function getCalendars(string $principalUri, array $calendarUris = []): array {
50+
$calendarInfos = [];
51+
if (empty($calendarUris)) {
52+
$calendarInfos[] = $this->calDavBackend->getCalendarsForUser($principalUri);
53+
} else {
54+
foreach ($calendarUris as $calendarUri) {
55+
$calendarInfos[] = $this->calDavBackend->getCalendarByUri($principalUri, $calendarUri);
56+
}
57+
}
58+
59+
$calendarInfos = array_filter($calendarInfos);
60+
61+
$iCalendars = [];
62+
foreach ($calendarInfos as $calendarInfo) {
63+
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config);
64+
$iCalendars[] = new CalendarImpl(
65+
$calendar,
66+
$calendarInfo,
67+
$this->calDavBackend,
68+
);
69+
}
70+
return $iCalendars;
71+
}
72+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
'OCP\\Broadcast\\Events\\IBroadcastEvent' => $baseDir . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
118118
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
119119
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
120+
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',
121+
'OCP\\Calendar\\ICalendarQuery' => $baseDir . '/lib/public/Calendar/ICalendarQuery.php',
120122
'OCP\\Calendar\\IManager' => $baseDir . '/lib/public/Calendar/IManager.php',
121123
'OCP\\Calendar\\IMetadataProvider' => $baseDir . '/lib/public/Calendar/IMetadataProvider.php',
122124
'OCP\\Calendar\\Resource\\IBackend' => $baseDir . '/lib/public/Calendar/Resource/IBackend.php',
@@ -759,6 +761,7 @@
759761
'OC\\Broadcast\\Events\\BroadcastEvent' => $baseDir . '/lib/private/Broadcast/Events/BroadcastEvent.php',
760762
'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php',
761763
'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php',
764+
'OC\\Calendar\\CalendarQuery' => $baseDir . '/lib/private/Calendar/CalendarQuery.php',
762765
'OC\\Calendar\\Manager' => $baseDir . '/lib/private/Calendar/Manager.php',
763766
'OC\\Calendar\\Resource\\Manager' => $baseDir . '/lib/private/Calendar/Resource/Manager.php',
764767
'OC\\Calendar\\Room\\Manager' => $baseDir . '/lib/private/Calendar/Room/Manager.php',

lib/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
146146
'OCP\\Broadcast\\Events\\IBroadcastEvent' => __DIR__ . '/../../..' . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
147147
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
148148
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
149+
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
150+
'OCP\\Calendar\\ICalendarQuery' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarQuery.php',
149151
'OCP\\Calendar\\IManager' => __DIR__ . '/../../..' . '/lib/public/Calendar/IManager.php',
150152
'OCP\\Calendar\\IMetadataProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/IMetadataProvider.php',
151153
'OCP\\Calendar\\Resource\\IBackend' => __DIR__ . '/../../..' . '/lib/public/Calendar/Resource/IBackend.php',
@@ -788,6 +790,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
788790
'OC\\Broadcast\\Events\\BroadcastEvent' => __DIR__ . '/../../..' . '/lib/private/Broadcast/Events/BroadcastEvent.php',
789791
'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php',
790792
'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php',
793+
'OC\\Calendar\\CalendarQuery' => __DIR__ . '/../../..' . '/lib/private/Calendar/CalendarQuery.php',
791794
'OC\\Calendar\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Manager.php',
792795
'OC\\Calendar\\Resource\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Resource/Manager.php',
793796
'OC\\Calendar\\Room\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Room/Manager.php',

lib/private/AppFramework/Bootstrap/RegistrationContext.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCP\AppFramework\Middleware;
3636
use OCP\AppFramework\Services\InitialStateProvider;
3737
use OCP\Authentication\IAlternativeLogin;
38+
use OCP\Calendar\ICalendarProvider;
3839
use OCP\Capabilities\ICapability;
3940
use OCP\Dashboard\IManager;
4041
use OCP\Dashboard\IWidget;
@@ -95,6 +96,9 @@ class RegistrationContext {
9596
/** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */
9697
private $twoFactorProviders = [];
9798

99+
/** @var ServiceRegistration<ICalendarProvider>[] */
100+
private $calendarProviders = [];
101+
98102
/** @var LoggerInterface */
99103
private $logger;
100104

@@ -225,6 +229,13 @@ public function registerTwoFactorProvider(string $twoFactorProviderClass): void
225229
$twoFactorProviderClass
226230
);
227231
}
232+
233+
public function registerCalendarProvider(string $class): void {
234+
$this->context->registerCalendarProvider(
235+
$this->appId,
236+
$class
237+
);
238+
}
228239
};
229240
}
230241

@@ -300,6 +311,10 @@ public function registerTwoFactorProvider(string $appId, string $class): void {
300311
$this->twoFactorProviders[] = new ServiceRegistration($appId, $class);
301312
}
302313

314+
public function registerCalendarProvider(string $appId, string $class): void {
315+
$this->calendarProviders[] = new ServiceRegistration($appId, $class);
316+
}
317+
303318
/**
304319
* @param App[] $apps
305320
*/
@@ -530,4 +545,11 @@ public function getNotifierServices(): array {
530545
public function getTwoFactorProviders(): array {
531546
return $this->twoFactorProviders;
532547
}
548+
549+
/**
550+
* @return ServiceRegistration<ICalendarProvider>[]
551+
*/
552+
public function getCalendarProviders(): array {
553+
return $this->calendarProviders;
554+
}
533555
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
7+
*
8+
* @author Anna Larch <anna.larch@gmx.net>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OC\Calendar;
27+
28+
use OCP\Calendar\ICalendarQuery;
29+
30+
class CalendarQuery implements ICalendarQuery {
31+
32+
/** @var string */
33+
private $principalUri;
34+
35+
/** @var array */
36+
public $searchProperties;
37+
38+
/** @var string|null */
39+
private $searchPattern;
40+
41+
/** @var array */
42+
private $options;
43+
44+
/** @var int|null */
45+
private $offset;
46+
47+
/** @var int|null */
48+
private $limit;
49+
50+
/** @var array */
51+
private $calendarUris;
52+
53+
public function __construct(string $principalUri) {
54+
$this->principalUri = $principalUri;
55+
$this->searchProperties = [];
56+
$this->options = [
57+
'types' => [],
58+
];
59+
}
60+
61+
public function getPrincipalUri(): string {
62+
return $this->principalUri;
63+
}
64+
65+
public function setPrincipalUri(string $principalUri): void {
66+
$this->principalUri = $principalUri;
67+
}
68+
69+
public function setSearchPattern(string $pattern): void {
70+
$this->searchPattern = $pattern;
71+
}
72+
73+
public function getSearchPattern(): ?string {
74+
return $this->searchPattern;
75+
}
76+
77+
public function addSearchProperty(string $value): void {
78+
$this->searchProperties[] = $value;
79+
}
80+
81+
public function getSearchProperties(): array {
82+
return $this->searchProperties;
83+
}
84+
85+
public function addSearchCalendar(string $calendarUri): void {
86+
$this->calendarUris[] = $calendarUri;
87+
}
88+
89+
public function getCalendarUris(): array {
90+
return $this->calendarUris;
91+
}
92+
93+
public function getLimit(): ?int {
94+
return $this->limit;
95+
}
96+
97+
public function setLimit(int $limit): void {
98+
$this->limit = $limit;
99+
}
100+
101+
public function getOffset(): ?int {
102+
return $this->offset;
103+
}
104+
105+
public function setOffset(int $offset): void {
106+
$this->offset = $offset;
107+
}
108+
109+
public function addType(string $value): void {
110+
$this->options['types'][] = $value;
111+
}
112+
113+
public function setTimerangeStart(\DateTimeImmutable $startTime): void {
114+
$this->options['timerange']['start'] = $startTime;
115+
}
116+
117+
public function setTimerangeEnd(\DateTimeImmutable $endTime): void {
118+
$this->options['timerange']['end'] = $endTime;
119+
}
120+
121+
public function getOptions(): array {
122+
return $this->options;
123+
}
124+
}

0 commit comments

Comments
 (0)