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