]> git.mxchange.org Git - friendica-addons.git/blob - dav/common/dav_user_calendars.inc.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / dav / common / dav_user_calendars.inc.php
1 <?php
2
3
4 class Sabre_CalDAV_AnimexxUserCalendars implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
5
6     /**
7      * Principal backend 
8      * 
9      * @var Sabre_DAVACL_IPrincipalBackend
10      */
11     protected $principalBackend;
12
13     /**
14      * CalDAV backends
15      * 
16      * @var array|Sabre_CalDAV_Backend_Common[]
17      */
18     protected $caldavBackends;
19
20     /**
21      * Principal information 
22      * 
23      * @var array 
24      */
25     protected $principalInfo;
26     
27     /**
28      * Constructor 
29      * 
30      * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
31      * @param array|Sabre_CalDAV_Backend_Common[] $caldavBackends
32      * @param mixed $userUri 
33      */
34     public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, $caldavBackends, $userUri) {
35
36         $this->principalBackend = $principalBackend;
37         $this->caldavBackends = $caldavBackends;
38         $this->principalInfo = $principalBackend->getPrincipalByPath($userUri);
39        
40     }
41
42     /**
43      * Returns the name of this object 
44      * 
45      * @return string
46      */
47     public function getName() {
48       
49         list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalInfo['uri']);
50         return $name; 
51
52     }
53
54         /**
55          * Updates the name of this object
56          *
57          * @param string $name
58          * @throws Sabre_DAV_Exception_Forbidden
59          * @return void
60          */
61     public function setName($name) {
62
63         throw new Sabre_DAV_Exception_Forbidden();
64
65     }
66
67         /**
68          * Deletes this object
69          *
70          * @throws Sabre_DAV_Exception_Forbidden
71          * @return void
72          */
73     public function delete() {
74
75         throw new Sabre_DAV_Exception_Forbidden();
76
77     }
78
79     /**
80      * Returns the last modification date 
81      * 
82      * @return int 
83      */
84     public function getLastModified() {
85
86         return null; 
87
88     }
89
90         /**
91          * Creates a new file under this object.
92          *
93          * This is currently not allowed
94          *
95          * @param string $filename
96          * @param resource $data
97          * @throws Sabre_DAV_Exception_MethodNotAllowed
98          * @return null|string|void
99          */
100     public function createFile($filename, $data=null) {
101
102         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
103
104     }
105
106         /**
107          * Creates a new directory under this object.
108          *
109          * This is currently not allowed.
110          *
111          * @param string $filename
112          * @throws Sabre_DAV_Exception_MethodNotAllowed
113          * @return void
114          */
115     public function createDirectory($filename) {
116
117         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
118
119     }
120
121         /**
122          * Returns a single calendar, by name
123          *
124          * @param string $name
125          * @throws Sabre_DAV_Exception_NotFound
126          * @todo needs optimizing
127          * @return \Sabre_CalDAV_Calendar|\Sabre_DAV_INode
128          */
129     public function getChild($name) {
130
131         foreach($this->getChildren() as $child) {
132             if ($name==$child->getName())
133                 return $child;
134
135         }
136         throw new Sabre_DAV_Exception_NotFound('Calendar with name \'' . $name . '\' could not be found');
137
138     }
139
140     /**
141      * Checks if a calendar exists.
142      * 
143      * @param string $name
144      * @todo needs optimizing
145      * @return bool 
146      */
147     public function childExists($name) {
148
149         foreach($this->getChildren() as $child) {
150             if ($name==$child->getName())
151                 return true; 
152
153         }
154         return false;
155
156     }
157
158         /**
159          * Returns a list of calendars
160          *
161          * @return array|\Sabre_DAV_INode[]
162          */
163      
164     public function getChildren() {
165                 $objs = array();
166                 foreach ($this->caldavBackends as $backend) {
167                         $calendars = $backend->getCalendarsForUser($this->principalInfo["uri"]);
168                 foreach($calendars as $calendar) {
169                 $objs[] = new $calendar["calendar_class"]($this->principalBackend, $backend, $calendar);
170                 }
171                 }
172         //$objs[] = new Sabre_CalDAV_AnimexxUserZirkelCalendars($this->principalBackend, $this->caldavBackend, $this->username);
173         return $objs;
174
175     }
176
177         /**
178          * Creates a new calendar
179          *
180          * @param string $name
181          * @param array $resourceType
182          * @param array $properties
183          * @throws Sabre_DAV_Exception_InvalidResourceType
184          * @return void
185          */
186     public function createExtendedCollection($name, array $resourceType, array $properties) {
187
188         if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) {
189             throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
190         }
191         $this->caldavBackends[0]->createCalendar($this->principalInfo['uri'], $name, $properties);
192
193     }
194
195     /**
196      * Returns the owner principal
197      *
198      * This must be a url to a principal, or null if there's no owner 
199      * 
200      * @return string|null
201      */
202     public function getOwner() {
203
204         return $this->principalInfo['uri'];
205
206     }
207
208     /**
209      * Returns a group principal
210      *
211      * This must be a url to a principal, or null if there's no owner
212      * 
213      * @return string|null 
214      */
215     public function getGroup() {
216
217         return null;
218
219     }
220
221     /**
222      * Returns a list of ACE's for this node.
223      *
224      * Each ACE has the following properties:
225      *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are 
226      *     currently the only supported privileges
227      *   * 'principal', a url to the principal who owns the node
228      *   * 'protected' (optional), indicating that this ACE is not allowed to 
229      *      be updated. 
230      * 
231      * @return array 
232      */
233     public function getACL() {
234         return array(
235             array(
236                 'privilege' => '{DAV:}read',
237                 'principal' => $this->principalInfo['uri'],
238                 'protected' => true,
239             ),
240             array(
241                 'privilege' => '{DAV:}write',
242                 'principal' => $this->principalInfo['uri'],
243                 'protected' => true,
244             ),
245             array(
246                 'privilege' => '{DAV:}read',
247                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
248                 'protected' => true,
249             ),
250             array(
251                 'privilege' => '{DAV:}write',
252                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
253                 'protected' => true,
254             ),
255             array(
256                 'privilege' => '{DAV:}read',
257                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
258                 'protected' => true,
259             ),
260
261         );
262
263     }
264
265     /**
266      * Updates the ACL
267      *
268      * This method will receive a list of new ACE's. 
269      * 
270      * @param array $acl
271          * @throws Sabre_DAV_Exception_MethodNotAllowed
272      * @return void
273      */
274     public function setACL(array $acl) {
275
276         throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
277
278     }
279
280
281         /**
282          * Returns the list of supported privileges for this node.
283          *
284          * The returned data structure is a list of nested privileges.
285          * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
286          * standard structure.
287          *
288          * If null is returned from this method, the default privilege set is used,
289          * which is fine for most common usecases.
290          *
291          * @return array|null
292          */
293         function getSupportedPrivilegeSet()
294         {
295                 return null;
296         }
297 }