]> git.mxchange.org Git - friendica-addons.git/blob - dav/common/dav_user_calendars.inc.php
Merge pull request #492 from zeroadam/Addon
[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         return $objs;
173
174     }
175
176         /**
177          * Creates a new calendar
178          *
179          * @param string $name
180          * @param array $resourceType
181          * @param array $properties
182          * @throws Sabre_DAV_Exception_InvalidResourceType
183          * @return void
184          */
185     public function createExtendedCollection($name, array $resourceType, array $properties) {
186
187         if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) {
188             throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
189         }
190         $this->caldavBackends[0]->createCalendar($this->principalInfo['uri'], $name, $properties);
191
192     }
193
194     /**
195      * Returns the owner principal
196      *
197      * This must be a url to a principal, or null if there's no owner 
198      * 
199      * @return string|null
200      */
201     public function getOwner() {
202
203         return $this->principalInfo['uri'];
204
205     }
206
207     /**
208      * Returns a group principal
209      *
210      * This must be a url to a principal, or null if there's no owner
211      * 
212      * @return string|null 
213      */
214     public function getGroup() {
215
216         return null;
217
218     }
219
220     /**
221      * Returns a list of ACE's for this node.
222      *
223      * Each ACE has the following properties:
224      *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are 
225      *     currently the only supported privileges
226      *   * 'principal', a url to the principal who owns the node
227      *   * 'protected' (optional), indicating that this ACE is not allowed to 
228      *      be updated. 
229      * 
230      * @return array 
231      */
232     public function getACL() {
233         return array(
234             array(
235                 'privilege' => '{DAV:}read',
236                 'principal' => $this->principalInfo['uri'],
237                 'protected' => true,
238             ),
239             array(
240                 'privilege' => '{DAV:}write',
241                 'principal' => $this->principalInfo['uri'],
242                 'protected' => true,
243             ),
244             array(
245                 'privilege' => '{DAV:}read',
246                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
247                 'protected' => true,
248             ),
249             array(
250                 'privilege' => '{DAV:}write',
251                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
252                 'protected' => true,
253             ),
254             array(
255                 'privilege' => '{DAV:}read',
256                 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
257                 'protected' => true,
258             ),
259
260         );
261
262     }
263
264     /**
265      * Updates the ACL
266      *
267      * This method will receive a list of new ACE's. 
268      * 
269      * @param array $acl
270          * @throws Sabre_DAV_Exception_MethodNotAllowed
271      * @return void
272      */
273     public function setACL(array $acl) {
274
275         throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
276
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         function getSupportedPrivilegeSet()
293         {
294                 return null;
295         }
296 }