]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CalDAV/UserCalendars.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CalDAV / UserCalendars.php
1 <?php
2
3 /**
4  * The UserCalenders class contains all calendars associated to one user
5  *
6  * @package Sabre
7  * @subpackage CalDAV
8  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9  * @author Evert Pot (http://www.rooftopsolutions.nl/) 
10  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11  */
12 class Sabre_CalDAV_UserCalendars implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
13
14     /**
15      * Principal backend
16      *
17      * @var Sabre_DAVACL_IPrincipalBackend
18      */
19     protected $principalBackend;
20
21     /**
22      * CalDAV backend
23      *
24      * @var Sabre_CalDAV_Backend_Abstract
25      */
26     protected $caldavBackend;
27
28     /**
29      * Principal information
30      *
31      * @var array
32      */
33     protected $principalInfo;
34
35     /**
36      * Constructor
37      *
38      * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
39      * @param Sabre_CalDAV_Backend_Abstract $caldavBackend
40      * @param mixed $userUri
41      */
42     public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_Abstract $caldavBackend, $userUri) {
43
44         $this->principalBackend = $principalBackend;
45         $this->caldavBackend = $caldavBackend;
46         $this->principalInfo = $principalBackend->getPrincipalByPath($userUri);
47
48     }
49
50     /**
51      * Returns the name of this object
52      *
53      * @return string
54      */
55     public function getName() {
56
57         list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalInfo['uri']);
58         return $name;
59
60     }
61
62     /**
63      * Updates the name of this object
64      *
65      * @param string $name
66      * @return void
67      */
68     public function setName($name) {
69
70         throw new Sabre_DAV_Exception_Forbidden();
71
72     }
73
74     /**
75      * Deletes this object
76      *
77      * @return void
78      */
79     public function delete() {
80
81         throw new Sabre_DAV_Exception_Forbidden();
82
83     }
84
85     /**
86      * Returns the last modification date
87      *
88      * @return int
89      */
90     public function getLastModified() {
91
92         return null;
93
94     }
95
96     /**
97      * Creates a new file under this object.
98      *
99      * This is currently not allowed
100      *
101      * @param string $filename
102      * @param resource $data
103      * @return void
104      */
105     public function createFile($filename, $data=null) {
106
107         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
108
109     }
110
111     /**
112      * Creates a new directory under this object.
113      *
114      * This is currently not allowed.
115      *
116      * @param string $filename
117      * @return void
118      */
119     public function createDirectory($filename) {
120
121         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
122
123     }
124
125     /**
126      * Returns a single calendar, by name
127      *
128      * @param string $name
129      * @todo needs optimizing
130      * @return Sabre_CalDAV_Calendar
131      */
132     public function getChild($name) {
133
134         foreach($this->getChildren() as $child) {
135             if ($name==$child->getName())
136                 return $child;
137
138         }
139         throw new Sabre_DAV_Exception_NotFound('Calendar with name \'' . $name . '\' could not be found');
140
141     }
142
143     /**
144      * Checks if a calendar exists.
145      *
146      * @param string $name
147      * @todo needs optimizing
148      * @return bool
149      */
150     public function childExists($name) {
151
152         foreach($this->getChildren() as $child) {
153             if ($name==$child->getName())
154                 return true;
155
156         }
157         return false;
158
159     }
160
161     /**
162      * Returns a list of calendars
163      *
164      * @return array
165      */
166     public function getChildren() {
167
168         $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
169         $objs = array();
170         foreach($calendars as $calendar) {
171             $objs[] = new Sabre_CalDAV_Calendar($this->principalBackend, $this->caldavBackend, $calendar);
172         }
173         $objs[] = new Sabre_CalDAV_Schedule_Outbox($this->principalInfo['uri']);
174         return $objs;
175
176     }
177
178     /**
179      * Creates a new calendar
180      *
181      * @param string $name
182      * @param array $resourceType
183      * @param array $properties
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->caldavBackend->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
235         return array(
236             array(
237                 'privilege' => '{DAV:}read',
238                 'principal' => $this->principalInfo['uri'],
239                 'protected' => true,
240             ),
241             array(
242                 'privilege' => '{DAV:}write',
243                 'principal' => $this->principalInfo['uri'],
244                 'protected' => true,
245             ),
246             array(
247                 'privilege' => '{DAV:}read',
248                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
249                 'protected' => true,
250             ),
251             array(
252                 'privilege' => '{DAV:}write',
253                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
254                 'protected' => true,
255             ),
256             array(
257                 'privilege' => '{DAV:}read',
258                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
259                 'protected' => true,
260             ),
261
262         );
263
264     }
265
266     /**
267      * Updates the ACL
268      *
269      * This method will receive a list of new ACE's.
270      *
271      * @param array $acl
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      * Returns the list of supported privileges for this node.
282      *
283      * The returned data structure is a list of nested privileges.
284      * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
285      * standard structure.
286      *
287      * If null is returned from this method, the default privilege set is used,
288      * which is fine for most common usecases.
289      *
290      * @return array|null
291      */
292     public function getSupportedPrivilegeSet() {
293
294         return null;
295
296     }
297
298 }