@@ -31,256 +31,256 @@ |
||
| 31 | 31 | use function Sabre\Uri\split as uriSplit; |
| 32 | 32 | |
| 33 | 33 | class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled { |
| 34 | - public function __construct( |
|
| 35 | - private Calendar $calendar, |
|
| 36 | - /** @var array<string, mixed> */ |
|
| 37 | - private array $calendarInfo, |
|
| 38 | - private CalDavBackend $backend, |
|
| 39 | - ) { |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return string defining the technical unique key |
|
| 44 | - * @since 13.0.0 |
|
| 45 | - */ |
|
| 46 | - public function getKey(): string { |
|
| 47 | - return (string)$this->calendarInfo['id']; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * {@inheritDoc} |
|
| 52 | - */ |
|
| 53 | - public function getUri(): string { |
|
| 54 | - return $this->calendarInfo['uri']; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 59 | - * @since 13.0.0 |
|
| 60 | - */ |
|
| 61 | - public function getDisplayName(): ?string { |
|
| 62 | - return $this->calendarInfo['{DAV:}displayname']; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Calendar color |
|
| 67 | - * @since 13.0.0 |
|
| 68 | - */ |
|
| 69 | - public function getDisplayColor(): ?string { |
|
| 70 | - return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function getSchedulingTransparency(): ?ScheduleCalendarTransp { |
|
| 74 | - return $this->calendarInfo['{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}schedule-calendar-transp']; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function getSchedulingTimezone(): ?VTimeZone { |
|
| 78 | - $tzProp = '{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}calendar-timezone'; |
|
| 79 | - if (!isset($this->calendarInfo[$tzProp])) { |
|
| 80 | - return null; |
|
| 81 | - } |
|
| 82 | - // This property contains a VCALENDAR with a single VTIMEZONE |
|
| 83 | - /** @var string $timezoneProp */ |
|
| 84 | - $timezoneProp = $this->calendarInfo[$tzProp]; |
|
| 85 | - /** @var VCalendar $vobj */ |
|
| 86 | - $vobj = Reader::read($timezoneProp); |
|
| 87 | - $components = $vobj->getComponents(); |
|
| 88 | - if (empty($components)) { |
|
| 89 | - return null; |
|
| 90 | - } |
|
| 91 | - /** @var VTimeZone $vtimezone */ |
|
| 92 | - $vtimezone = $components[0]; |
|
| 93 | - return $vtimezone; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 97 | - return $this->backend->search($this->calendarInfo, $pattern, |
|
| 98 | - $searchProperties, $options, $limit, $offset); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return int build up using \OCP\Constants |
|
| 103 | - * @since 13.0.0 |
|
| 104 | - */ |
|
| 105 | - public function getPermissions(): int { |
|
| 106 | - $permissions = $this->calendar->getACL(); |
|
| 107 | - $result = 0; |
|
| 108 | - foreach ($permissions as $permission) { |
|
| 109 | - if ($this->calendarInfo['principaluri'] !== $permission['principal']) { |
|
| 110 | - continue; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - switch ($permission['privilege']) { |
|
| 114 | - case '{DAV:}read': |
|
| 115 | - $result |= Constants::PERMISSION_READ; |
|
| 116 | - break; |
|
| 117 | - case '{DAV:}write': |
|
| 118 | - $result |= Constants::PERMISSION_CREATE; |
|
| 119 | - $result |= Constants::PERMISSION_UPDATE; |
|
| 120 | - break; |
|
| 121 | - case '{DAV:}all': |
|
| 122 | - $result |= Constants::PERMISSION_ALL; |
|
| 123 | - break; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $result; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @since 32.0.0 |
|
| 132 | - */ |
|
| 133 | - public function isEnabled(): bool { |
|
| 134 | - return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @since 31.0.0 |
|
| 139 | - */ |
|
| 140 | - public function isWritable(): bool { |
|
| 141 | - return $this->calendar->canWrite(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @since 26.0.0 |
|
| 146 | - */ |
|
| 147 | - public function isDeleted(): bool { |
|
| 148 | - return $this->calendar->isDeleted(); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @since 31.0.0 |
|
| 153 | - */ |
|
| 154 | - public function isShared(): bool { |
|
| 155 | - return $this->calendar->isShared(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Create a new calendar event for this calendar |
|
| 160 | - * by way of an ICS string |
|
| 161 | - * |
|
| 162 | - * @param string $name the file name - needs to contain the .ics ending |
|
| 163 | - * @param string $calendarData a string containing a valid VEVENT ics |
|
| 164 | - * |
|
| 165 | - * @throws CalendarException |
|
| 166 | - */ |
|
| 167 | - public function createFromString(string $name, string $calendarData): void { |
|
| 168 | - $server = new InvitationResponseServer(false); |
|
| 169 | - |
|
| 170 | - /** @var CustomPrincipalPlugin $plugin */ |
|
| 171 | - $plugin = $server->getServer()->getPlugin('auth'); |
|
| 172 | - // we're working around the previous implementation |
|
| 173 | - // that only allowed the public system principal to be used |
|
| 174 | - // so set the custom principal here |
|
| 175 | - $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 176 | - |
|
| 177 | - if (empty($this->calendarInfo['uri'])) { |
|
| 178 | - throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Build full calendar path |
|
| 182 | - [, $user] = uriSplit($this->calendar->getPrincipalURI()); |
|
| 183 | - $fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name); |
|
| 184 | - |
|
| 185 | - // Force calendar change URI |
|
| 186 | - /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 187 | - $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 188 | - $schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename); |
|
| 189 | - |
|
| 190 | - $stream = fopen('php://memory', 'rb+'); |
|
| 191 | - fwrite($stream, $calendarData); |
|
| 192 | - rewind($stream); |
|
| 193 | - try { |
|
| 194 | - $server->getServer()->createFile($fullCalendarFilename, $stream); |
|
| 195 | - } catch (Conflict $e) { |
|
| 196 | - throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e); |
|
| 197 | - } finally { |
|
| 198 | - fclose($stream); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @throws CalendarException |
|
| 204 | - */ |
|
| 205 | - public function handleIMipMessage(string $name, string $calendarData): void { |
|
| 206 | - $server = $this->getInvitationResponseServer(); |
|
| 207 | - |
|
| 208 | - /** @var CustomPrincipalPlugin $plugin */ |
|
| 209 | - $plugin = $server->getServer()->getPlugin('auth'); |
|
| 210 | - // we're working around the previous implementation |
|
| 211 | - // that only allowed the public system principal to be used |
|
| 212 | - // so set the custom principal here |
|
| 213 | - $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 214 | - |
|
| 215 | - if (empty($this->calendarInfo['uri'])) { |
|
| 216 | - throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 217 | - } |
|
| 218 | - // Force calendar change URI |
|
| 219 | - /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 220 | - $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 221 | - // Let sabre handle the rest |
|
| 222 | - $iTipMessage = new Message(); |
|
| 223 | - /** @var VCalendar $vObject */ |
|
| 224 | - $vObject = Reader::read($calendarData); |
|
| 225 | - /** @var VEvent $vEvent */ |
|
| 226 | - $vEvent = $vObject->{'VEVENT'}; |
|
| 227 | - |
|
| 228 | - if ($vObject->{'METHOD'} === null) { |
|
| 229 | - throw new CalendarException('No Method provided for scheduling data. Could not process message'); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if (!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) { |
|
| 233 | - throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL'); |
|
| 234 | - } |
|
| 235 | - $organizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 236 | - $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 237 | - |
|
| 238 | - $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 239 | - if ($iTipMessage->method === 'REQUEST') { |
|
| 240 | - $iTipMessage->sender = $organizer; |
|
| 241 | - $iTipMessage->recipient = $attendee; |
|
| 242 | - } elseif ($iTipMessage->method === 'REPLY') { |
|
| 243 | - if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) { |
|
| 244 | - $iTipMessage->recipient = $organizer; |
|
| 245 | - } else { |
|
| 246 | - $iTipMessage->recipient = $attendee; |
|
| 247 | - } |
|
| 248 | - $iTipMessage->sender = $attendee; |
|
| 249 | - } elseif ($iTipMessage->method === 'CANCEL') { |
|
| 250 | - $iTipMessage->recipient = $attendee; |
|
| 251 | - $iTipMessage->sender = $organizer; |
|
| 252 | - } |
|
| 253 | - $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 254 | - $iTipMessage->component = 'VEVENT'; |
|
| 255 | - $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 256 | - $iTipMessage->message = $vObject; |
|
| 257 | - $server->server->emit('schedule', [$iTipMessage]); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - public function getInvitationResponseServer(): InvitationResponseServer { |
|
| 261 | - return new InvitationResponseServer(false); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Export objects |
|
| 266 | - * |
|
| 267 | - * @since 32.0.0 |
|
| 268 | - * |
|
| 269 | - * @return Generator<mixed, \Sabre\VObject\Component\VCalendar, mixed, mixed> |
|
| 270 | - */ |
|
| 271 | - public function export(?CalendarExportOptions $options = null): Generator { |
|
| 272 | - foreach ( |
|
| 273 | - $this->backend->exportCalendar( |
|
| 274 | - $this->calendarInfo['id'], |
|
| 275 | - $this->backend::CALENDAR_TYPE_CALENDAR, |
|
| 276 | - $options |
|
| 277 | - ) as $event |
|
| 278 | - ) { |
|
| 279 | - $vObject = Reader::read($event['calendardata']); |
|
| 280 | - if ($vObject instanceof VCalendar) { |
|
| 281 | - yield $vObject; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 34 | + public function __construct( |
|
| 35 | + private Calendar $calendar, |
|
| 36 | + /** @var array<string, mixed> */ |
|
| 37 | + private array $calendarInfo, |
|
| 38 | + private CalDavBackend $backend, |
|
| 39 | + ) { |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return string defining the technical unique key |
|
| 44 | + * @since 13.0.0 |
|
| 45 | + */ |
|
| 46 | + public function getKey(): string { |
|
| 47 | + return (string)$this->calendarInfo['id']; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * {@inheritDoc} |
|
| 52 | + */ |
|
| 53 | + public function getUri(): string { |
|
| 54 | + return $this->calendarInfo['uri']; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 59 | + * @since 13.0.0 |
|
| 60 | + */ |
|
| 61 | + public function getDisplayName(): ?string { |
|
| 62 | + return $this->calendarInfo['{DAV:}displayname']; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Calendar color |
|
| 67 | + * @since 13.0.0 |
|
| 68 | + */ |
|
| 69 | + public function getDisplayColor(): ?string { |
|
| 70 | + return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function getSchedulingTransparency(): ?ScheduleCalendarTransp { |
|
| 74 | + return $this->calendarInfo['{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}schedule-calendar-transp']; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function getSchedulingTimezone(): ?VTimeZone { |
|
| 78 | + $tzProp = '{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}calendar-timezone'; |
|
| 79 | + if (!isset($this->calendarInfo[$tzProp])) { |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | + // This property contains a VCALENDAR with a single VTIMEZONE |
|
| 83 | + /** @var string $timezoneProp */ |
|
| 84 | + $timezoneProp = $this->calendarInfo[$tzProp]; |
|
| 85 | + /** @var VCalendar $vobj */ |
|
| 86 | + $vobj = Reader::read($timezoneProp); |
|
| 87 | + $components = $vobj->getComponents(); |
|
| 88 | + if (empty($components)) { |
|
| 89 | + return null; |
|
| 90 | + } |
|
| 91 | + /** @var VTimeZone $vtimezone */ |
|
| 92 | + $vtimezone = $components[0]; |
|
| 93 | + return $vtimezone; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 97 | + return $this->backend->search($this->calendarInfo, $pattern, |
|
| 98 | + $searchProperties, $options, $limit, $offset); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return int build up using \OCP\Constants |
|
| 103 | + * @since 13.0.0 |
|
| 104 | + */ |
|
| 105 | + public function getPermissions(): int { |
|
| 106 | + $permissions = $this->calendar->getACL(); |
|
| 107 | + $result = 0; |
|
| 108 | + foreach ($permissions as $permission) { |
|
| 109 | + if ($this->calendarInfo['principaluri'] !== $permission['principal']) { |
|
| 110 | + continue; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + switch ($permission['privilege']) { |
|
| 114 | + case '{DAV:}read': |
|
| 115 | + $result |= Constants::PERMISSION_READ; |
|
| 116 | + break; |
|
| 117 | + case '{DAV:}write': |
|
| 118 | + $result |= Constants::PERMISSION_CREATE; |
|
| 119 | + $result |= Constants::PERMISSION_UPDATE; |
|
| 120 | + break; |
|
| 121 | + case '{DAV:}all': |
|
| 122 | + $result |= Constants::PERMISSION_ALL; |
|
| 123 | + break; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $result; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @since 32.0.0 |
|
| 132 | + */ |
|
| 133 | + public function isEnabled(): bool { |
|
| 134 | + return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @since 31.0.0 |
|
| 139 | + */ |
|
| 140 | + public function isWritable(): bool { |
|
| 141 | + return $this->calendar->canWrite(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @since 26.0.0 |
|
| 146 | + */ |
|
| 147 | + public function isDeleted(): bool { |
|
| 148 | + return $this->calendar->isDeleted(); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @since 31.0.0 |
|
| 153 | + */ |
|
| 154 | + public function isShared(): bool { |
|
| 155 | + return $this->calendar->isShared(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Create a new calendar event for this calendar |
|
| 160 | + * by way of an ICS string |
|
| 161 | + * |
|
| 162 | + * @param string $name the file name - needs to contain the .ics ending |
|
| 163 | + * @param string $calendarData a string containing a valid VEVENT ics |
|
| 164 | + * |
|
| 165 | + * @throws CalendarException |
|
| 166 | + */ |
|
| 167 | + public function createFromString(string $name, string $calendarData): void { |
|
| 168 | + $server = new InvitationResponseServer(false); |
|
| 169 | + |
|
| 170 | + /** @var CustomPrincipalPlugin $plugin */ |
|
| 171 | + $plugin = $server->getServer()->getPlugin('auth'); |
|
| 172 | + // we're working around the previous implementation |
|
| 173 | + // that only allowed the public system principal to be used |
|
| 174 | + // so set the custom principal here |
|
| 175 | + $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 176 | + |
|
| 177 | + if (empty($this->calendarInfo['uri'])) { |
|
| 178 | + throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Build full calendar path |
|
| 182 | + [, $user] = uriSplit($this->calendar->getPrincipalURI()); |
|
| 183 | + $fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name); |
|
| 184 | + |
|
| 185 | + // Force calendar change URI |
|
| 186 | + /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 187 | + $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 188 | + $schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename); |
|
| 189 | + |
|
| 190 | + $stream = fopen('php://memory', 'rb+'); |
|
| 191 | + fwrite($stream, $calendarData); |
|
| 192 | + rewind($stream); |
|
| 193 | + try { |
|
| 194 | + $server->getServer()->createFile($fullCalendarFilename, $stream); |
|
| 195 | + } catch (Conflict $e) { |
|
| 196 | + throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e); |
|
| 197 | + } finally { |
|
| 198 | + fclose($stream); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @throws CalendarException |
|
| 204 | + */ |
|
| 205 | + public function handleIMipMessage(string $name, string $calendarData): void { |
|
| 206 | + $server = $this->getInvitationResponseServer(); |
|
| 207 | + |
|
| 208 | + /** @var CustomPrincipalPlugin $plugin */ |
|
| 209 | + $plugin = $server->getServer()->getPlugin('auth'); |
|
| 210 | + // we're working around the previous implementation |
|
| 211 | + // that only allowed the public system principal to be used |
|
| 212 | + // so set the custom principal here |
|
| 213 | + $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 214 | + |
|
| 215 | + if (empty($this->calendarInfo['uri'])) { |
|
| 216 | + throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 217 | + } |
|
| 218 | + // Force calendar change URI |
|
| 219 | + /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 220 | + $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 221 | + // Let sabre handle the rest |
|
| 222 | + $iTipMessage = new Message(); |
|
| 223 | + /** @var VCalendar $vObject */ |
|
| 224 | + $vObject = Reader::read($calendarData); |
|
| 225 | + /** @var VEvent $vEvent */ |
|
| 226 | + $vEvent = $vObject->{'VEVENT'}; |
|
| 227 | + |
|
| 228 | + if ($vObject->{'METHOD'} === null) { |
|
| 229 | + throw new CalendarException('No Method provided for scheduling data. Could not process message'); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if (!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) { |
|
| 233 | + throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL'); |
|
| 234 | + } |
|
| 235 | + $organizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 236 | + $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 237 | + |
|
| 238 | + $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 239 | + if ($iTipMessage->method === 'REQUEST') { |
|
| 240 | + $iTipMessage->sender = $organizer; |
|
| 241 | + $iTipMessage->recipient = $attendee; |
|
| 242 | + } elseif ($iTipMessage->method === 'REPLY') { |
|
| 243 | + if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) { |
|
| 244 | + $iTipMessage->recipient = $organizer; |
|
| 245 | + } else { |
|
| 246 | + $iTipMessage->recipient = $attendee; |
|
| 247 | + } |
|
| 248 | + $iTipMessage->sender = $attendee; |
|
| 249 | + } elseif ($iTipMessage->method === 'CANCEL') { |
|
| 250 | + $iTipMessage->recipient = $attendee; |
|
| 251 | + $iTipMessage->sender = $organizer; |
|
| 252 | + } |
|
| 253 | + $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 254 | + $iTipMessage->component = 'VEVENT'; |
|
| 255 | + $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 256 | + $iTipMessage->message = $vObject; |
|
| 257 | + $server->server->emit('schedule', [$iTipMessage]); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + public function getInvitationResponseServer(): InvitationResponseServer { |
|
| 261 | + return new InvitationResponseServer(false); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Export objects |
|
| 266 | + * |
|
| 267 | + * @since 32.0.0 |
|
| 268 | + * |
|
| 269 | + * @return Generator<mixed, \Sabre\VObject\Component\VCalendar, mixed, mixed> |
|
| 270 | + */ |
|
| 271 | + public function export(?CalendarExportOptions $options = null): Generator { |
|
| 272 | + foreach ( |
|
| 273 | + $this->backend->exportCalendar( |
|
| 274 | + $this->calendarInfo['id'], |
|
| 275 | + $this->backend::CALENDAR_TYPE_CALENDAR, |
|
| 276 | + $options |
|
| 277 | + ) as $event |
|
| 278 | + ) { |
|
| 279 | + $vObject = Reader::read($event['calendardata']); |
|
| 280 | + if ($vObject instanceof VCalendar) { |
|
| 281 | + yield $vObject; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | } |
@@ -16,87 +16,87 @@ |
||
| 16 | 16 | |
| 17 | 17 | class CachedSubscriptionImpl implements ICalendar, ICalendarIsEnabled, ICalendarIsShared, ICalendarIsWritable { |
| 18 | 18 | |
| 19 | - public function __construct( |
|
| 20 | - private CachedSubscription $calendar, |
|
| 21 | - /** @var array<string, mixed> */ |
|
| 22 | - private array $calendarInfo, |
|
| 23 | - private CalDavBackend $backend, |
|
| 24 | - ) { |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @return string defining the technical unique key |
|
| 29 | - * @since 13.0.0 |
|
| 30 | - */ |
|
| 31 | - public function getKey(): string { |
|
| 32 | - return (string)$this->calendarInfo['id']; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * {@inheritDoc} |
|
| 37 | - */ |
|
| 38 | - public function getUri(): string { |
|
| 39 | - return $this->calendarInfo['uri']; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 44 | - * @since 13.0.0 |
|
| 45 | - */ |
|
| 46 | - public function getDisplayName(): ?string { |
|
| 47 | - return $this->calendarInfo['{DAV:}displayname']; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Calendar color |
|
| 52 | - * @since 13.0.0 |
|
| 53 | - */ |
|
| 54 | - public function getDisplayColor(): ?string { |
|
| 55 | - return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 59 | - return $this->backend->search($this->calendarInfo, $pattern, $searchProperties, $options, $limit, $offset); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return int build up using \OCP\Constants |
|
| 64 | - * @since 13.0.0 |
|
| 65 | - */ |
|
| 66 | - public function getPermissions(): int { |
|
| 67 | - $permissions = $this->calendar->getACL(); |
|
| 68 | - $result = 0; |
|
| 69 | - foreach ($permissions as $permission) { |
|
| 70 | - switch ($permission['privilege']) { |
|
| 71 | - case '{DAV:}read': |
|
| 72 | - $result |= Constants::PERMISSION_READ; |
|
| 73 | - break; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $result; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @since 32.0.0 |
|
| 82 | - */ |
|
| 83 | - public function isEnabled(): bool { |
|
| 84 | - return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function isWritable(): bool { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function isDeleted(): bool { |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function isShared(): bool { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function getSource(): string { |
|
| 100 | - return $this->calendarInfo['source']; |
|
| 101 | - } |
|
| 19 | + public function __construct( |
|
| 20 | + private CachedSubscription $calendar, |
|
| 21 | + /** @var array<string, mixed> */ |
|
| 22 | + private array $calendarInfo, |
|
| 23 | + private CalDavBackend $backend, |
|
| 24 | + ) { |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @return string defining the technical unique key |
|
| 29 | + * @since 13.0.0 |
|
| 30 | + */ |
|
| 31 | + public function getKey(): string { |
|
| 32 | + return (string)$this->calendarInfo['id']; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * {@inheritDoc} |
|
| 37 | + */ |
|
| 38 | + public function getUri(): string { |
|
| 39 | + return $this->calendarInfo['uri']; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 44 | + * @since 13.0.0 |
|
| 45 | + */ |
|
| 46 | + public function getDisplayName(): ?string { |
|
| 47 | + return $this->calendarInfo['{DAV:}displayname']; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Calendar color |
|
| 52 | + * @since 13.0.0 |
|
| 53 | + */ |
|
| 54 | + public function getDisplayColor(): ?string { |
|
| 55 | + return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 59 | + return $this->backend->search($this->calendarInfo, $pattern, $searchProperties, $options, $limit, $offset); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return int build up using \OCP\Constants |
|
| 64 | + * @since 13.0.0 |
|
| 65 | + */ |
|
| 66 | + public function getPermissions(): int { |
|
| 67 | + $permissions = $this->calendar->getACL(); |
|
| 68 | + $result = 0; |
|
| 69 | + foreach ($permissions as $permission) { |
|
| 70 | + switch ($permission['privilege']) { |
|
| 71 | + case '{DAV:}read': |
|
| 72 | + $result |= Constants::PERMISSION_READ; |
|
| 73 | + break; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $result; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @since 32.0.0 |
|
| 82 | + */ |
|
| 83 | + public function isEnabled(): bool { |
|
| 84 | + return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function isWritable(): bool { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function isDeleted(): bool { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function isShared(): bool { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function getSource(): string { |
|
| 100 | + return $this->calendarInfo['source']; |
|
| 101 | + } |
|
| 102 | 102 | } |