|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright 2024 Daniel Kesselberg <[email protected]> |
| 7 | + * |
| 8 | + * @author Daniel Kesselberg <[email protected]> |
| 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\ICalendar; |
| 29 | +use OCP\Constants; |
| 30 | + |
| 31 | +class CachedSubscriptionImpl implements ICalendar { |
| 32 | + private CalDavBackend $backend; |
| 33 | + private CachedSubscription $calendar; |
| 34 | + /** @var array<string, mixed> */ |
| 35 | + private array $calendarInfo; |
| 36 | + |
| 37 | + public function __construct( |
| 38 | + CachedSubscription $calendar, |
| 39 | + array $calendarInfo, |
| 40 | + CalDavBackend $backend |
| 41 | + ) { |
| 42 | + $this->calendar = $calendar; |
| 43 | + $this->calendarInfo = $calendarInfo; |
| 44 | + $this->backend = $backend; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return string defining the technical unique key |
| 49 | + * @since 13.0.0 |
| 50 | + */ |
| 51 | + public function getKey(): string { |
| 52 | + return (string) $this->calendarInfo['id']; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * {@inheritDoc} |
| 57 | + */ |
| 58 | + public function getUri(): string { |
| 59 | + return $this->calendarInfo['uri']; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
| 64 | + * @since 13.0.0 |
| 65 | + */ |
| 66 | + public function getDisplayName(): ?string { |
| 67 | + return $this->calendarInfo['{DAV:}displayname']; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Calendar color |
| 72 | + * @since 13.0.0 |
| 73 | + */ |
| 74 | + public function getDisplayColor(): ?string { |
| 75 | + return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @param string $pattern which should match within the $searchProperties |
| 80 | + * @param array $searchProperties defines the properties within the query pattern should match |
| 81 | + * @param array $options - optional parameters: |
| 82 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
| 83 | + * @param int|null $limit - limit number of search results |
| 84 | + * @param int|null $offset - offset for paging of search results |
| 85 | + * @return array an array of events/journals/todos which are arrays of key-value-pairs |
| 86 | + * @since 13.0.0 |
| 87 | + */ |
| 88 | + public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
| 89 | + return $this->backend->search($this->calendarInfo, $pattern, $searchProperties, $options, $limit, $offset); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @return int build up using \OCP\Constants |
| 94 | + * @since 13.0.0 |
| 95 | + */ |
| 96 | + public function getPermissions(): int { |
| 97 | + $permissions = $this->calendar->getACL(); |
| 98 | + $result = 0; |
| 99 | + foreach ($permissions as $permission) { |
| 100 | + switch ($permission['privilege']) { |
| 101 | + case '{DAV:}read': |
| 102 | + $result |= Constants::PERMISSION_READ; |
| 103 | + break; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + return $result; |
| 108 | + } |
| 109 | + |
| 110 | + public function isDeleted(): bool { |
| 111 | + return false; |
| 112 | + } |
| 113 | + |
| 114 | + public function getSource(): string { |
| 115 | + return $this->calendarInfo['source']; |
| 116 | + } |
| 117 | +} |
0 commit comments