|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @copyright 2023 Ferdinand Thiessen <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @author Ferdinand Thiessen <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0-or-later |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\DAV\CalDAV\AppCalendar; |
|
27
|
|
|
|
|
28
|
|
|
use OCA\DAV\CalDAV\Integration\ExternalCalendar; |
|
29
|
|
|
use OCA\DAV\CalDAV\Integration\ICalendarProvider; |
|
30
|
|
|
use OCP\Calendar\IManager; |
|
31
|
|
|
use Psr\Log\LoggerInterface; |
|
32
|
|
|
|
|
33
|
|
|
/* Plugin for wrapping application generated calendars registered in nextcloud core (OCP\Calendar\ICalendarProvider) */ |
|
34
|
|
|
class AppCalendarPlugin implements ICalendarProvider { |
|
35
|
|
|
protected IManager $manager; |
|
36
|
|
|
protected LoggerInterface $logger; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct(IManager $manager, LoggerInterface $logger) { |
|
39
|
|
|
$this->manager = $manager; |
|
40
|
|
|
$this->logger = $logger; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getAppID(): string { |
|
44
|
|
|
return 'dav-wrapper'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function fetchAllForCalendarHome(string $principalUri): array { |
|
48
|
|
|
return array_map(function ($calendar) use (&$principalUri) { |
|
49
|
|
|
return new AppCalendar($this->getAppID(), $calendar, $principalUri); |
|
50
|
|
|
}, $this->getWrappedCalendars($principalUri)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool { |
|
54
|
|
|
return count($this->getWrappedCalendars($principalUri, [ $calendarUri ])) > 0; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalCalendar { |
|
58
|
|
|
$calendars = $this->getWrappedCalendars($principalUri, [ $calendarUri ]); |
|
59
|
|
|
if (count($calendars) > 0) { |
|
60
|
|
|
return new AppCalendar($this->getAppID(), $calendars[0], $principalUri); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function getWrappedCalendars(string $principalUri, array $calendarUris = []): array { |
|
67
|
|
|
return array_values( |
|
68
|
|
|
array_filter($this->manager->getCalendarsForPrincipal($principalUri, $calendarUris), function ($c) { |
|
69
|
|
|
// We must not provide a wrapper for DAV calendars |
|
70
|
|
|
return ! ($c instanceof \OCA\DAV\CalDAV\CalendarImpl); |
|
71
|
|
|
}) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|