ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MockSharing.php
Go to the documentation of this file.
1<?php
2
4
6use Sabre\DAV;
7
9
10 private $shares = [];
12
13 function __construct(array $calendars = [], array $calendarData = [], array $notifications = []) {
14
15 parent::__construct($calendars, $calendarData);
16 $this->notifications = $notifications;
17
18 }
19
37 function getCalendarsForUser($principalUri) {
38
39 $calendars = parent::getCalendarsForUser($principalUri);
40 foreach ($calendars as $k => $calendar) {
41
42 if (isset($calendar['share-access'])) {
43 continue;
44 }
45 if (!empty($this->shares[$calendar['id']])) {
47 } else {
49 }
51
52 }
53 return $calendars;
54
55 }
56
66 function getNotificationsForPrincipal($principalUri) {
67
68 if (isset($this->notifications[$principalUri])) {
69 return $this->notifications[$principalUri];
70 }
71 return [];
72
73 }
74
84 function deleteNotification($principalUri, NotificationInterface $notification) {
85
86 foreach ($this->notifications[$principalUri] as $key => $value) {
87 if ($notification === $value) {
88 unset($this->notifications[$principalUri][$key]);
89 }
90 }
91
92 }
93
101 function updateInvites($calendarId, array $sharees) {
102
103 if (!isset($this->shares[$calendarId])) {
104 $this->shares[$calendarId] = [];
105 }
106
107 foreach ($sharees as $sharee) {
108
109 $existingKey = null;
110 foreach ($this->shares[$calendarId] as $k => $existingSharee) {
111 if ($sharee->href === $existingSharee->href) {
112 $existingKey = $k;
113 }
114 }
115 // Just making sure we're not affecting an existing copy.
116 $sharee = clone $sharee;
117 $sharee->inviteStatus = DAV\Sharing\Plugin::INVITE_NORESPONSE;
118
119 if ($sharee->access === DAV\Sharing\Plugin::ACCESS_NOACCESS) {
120 // It's a removal
121 unset($this->shares[$calendarId][$existingKey]);
122 } elseif ($existingKey) {
123 // It's an update
124 $this->shares[$calendarId][$existingKey] = $sharee;
125 } else {
126 // It's an addition
127 $this->shares[$calendarId][] = $sharee;
128 }
129 }
130
131 // Re-numbering keys
132 $this->shares[$calendarId] = array_values($this->shares[$calendarId]);
133
134 }
135
151 function getInvites($calendarId) {
152
153 if (!isset($this->shares[$calendarId])) {
154 return [];
155 }
156
157 return $this->shares[$calendarId];
158
159 }
160
171 function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) {
172
173 // This operation basically doesn't do anything yet
174 if ($status === DAV\Sharing\Plugin::INVITE_ACCEPTED) {
175 return 'calendars/blabla/calendar';
176 }
177
178 }
179
187 function setPublishStatus($calendarId, $value) {
188
189 foreach ($this->calendars as $k => $cal) {
190 if ($cal['id'] === $calendarId) {
191 if (!$value) {
192 unset($cal['{http://calendarserver.org/ns/}publish-url']);
193 } else {
194 $cal['{http://calendarserver.org/ns/}publish-url'] = 'http://example.org/public/ ' . $calendarId . '.ics';
195 }
196 return;
197 }
198 }
199
200 throw new DAV\Exception('Calendar with id "' . $calendarId . '" not found');
201
202 }
203
204}
An exception for terminatinating execution or to throw for unit testing.
getInvites($calendarId)
Returns the list of people whom this calendar is shared with.
setPublishStatus($calendarId, $value)
Publishes a calendar.
updateInvites($calendarId, array $sharees)
Updates the list of shares.
__construct(array $calendars=[], array $calendarData=[], array $notifications=[])
Definition: MockSharing.php:13
shareReply($href, $status, $calendarUri, $inReplyTo, $summary=null)
This method is called when a user replied to a request to share.
getCalendarsForUser($principalUri)
Returns a list of calendars for a principal.
Definition: MockSharing.php:37
getNotificationsForPrincipal($principalUri)
Returns a list of notifications for a given principal url.
Definition: MockSharing.php:66
deleteNotification($principalUri, NotificationInterface $notification)
This deletes a specific notifcation.
Definition: MockSharing.php:84
Main Exception class.
Definition: Exception.php:18
$key
Definition: croninfo.php:18
Adds caldav notification support to a backend.
Adds support for sharing features to a CalDAV server.
This interface reflects a single notification type.
$summary
Definition: cron.php:24