]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/Backend/Mock.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / Backend / Mock.php
1 <?php
2
3 class Sabre_CalDAV_Backend_Mock extends Sabre_CalDAV_Backend_Abstract {
4
5     private $calendarData;
6     private $calendars;
7
8     function __construct(array $calendars, array $calendarData) {
9
10         $this->calendars = $calendars;
11         $this->calendarData = $calendarData;
12
13     }
14
15     /**
16      * Returns a list of calendars for a principal.
17      *
18      * Every project is an array with the following keys:
19      *  * id, a unique id that will be used by other functions to modify the
20      *    calendar. This can be the same as the uri or a database key.
21      *  * uri, which the basename of the uri with which the calendar is
22      *    accessed.
23      *  * principalUri. The owner of the calendar. Almost always the same as
24      *    principalUri passed to this method.
25      *
26      * Furthermore it can contain webdav properties in clark notation. A very
27      * common one is '{DAV:}displayname'.
28      *
29      * @param string $principalUri
30      * @return array
31      */
32     function getCalendarsForUser($principalUri) {
33
34         $r = array();
35         foreach($this->calendars as $row) {
36             if ($row['principaluri'] == $principalUri) {
37                 $r[] = $row;
38             }
39         }
40
41         return $r;
42
43     }
44
45     /**
46      * Creates a new calendar for a principal.
47      *
48      * If the creation was a success, an id must be returned that can be used to reference
49      * this calendar in other methods, such as updateCalendar.
50      *
51      * This function must return a server-wide unique id that can be used
52      * later to reference the calendar.
53      *
54      * @param string $principalUri
55      * @param string $calendarUri
56      * @param array $properties
57      * @return string|int
58      */
59     function createCalendar($principalUri,$calendarUri,array $properties) {
60
61         throw new Exception('Not implemented');
62
63     }
64
65     /**
66      * Updates properties on this node,
67      *
68      * The properties array uses the propertyName in clark-notation as key,
69      * and the array value for the property value. In the case a property
70      * should be deleted, the property value will be null.
71      *
72      * This method must be atomic. If one property cannot be changed, the
73      * entire operation must fail.
74      *
75      * If the operation was successful, true can be returned.
76      * If the operation failed, false can be returned.
77      *
78      * Deletion of a non-existent property is always successful.
79      *
80      * Lastly, it is optional to return detailed information about any
81      * failures. In this case an array should be returned with the following
82      * structure:
83      *
84      * array(
85      *   403 => array(
86      *      '{DAV:}displayname' => null,
87      *   ),
88      *   424 => array(
89      *      '{DAV:}owner' => null,
90      *   )
91      * )
92      *
93      * In this example it was forbidden to update {DAV:}displayname.
94      * (403 Forbidden), which in turn also caused {DAV:}owner to fail
95      * (424 Failed Dependency) because the request needs to be atomic.
96      *
97      * @param string $calendarId
98      * @param array $properties
99      * @return bool|array
100      */
101     public function updateCalendar($calendarId, array $properties) {
102
103         return false;
104
105     }
106
107     /**
108      * Delete a calendar and all it's objects
109      *
110      * @param string $calendarId
111      * @return void
112      */
113     public function deleteCalendar($calendarId) {
114
115         throw new Exception('Not implemented');
116
117     }
118
119     /**
120      * Returns all calendar objects within a calendar object.
121      *
122      * Every item contains an array with the following keys:
123      *   * id - unique identifier which will be used for subsequent updates
124      *   * calendardata - The iCalendar-compatible calendar data
125      *   * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
126      *   * lastmodified - a timestamp of the last modification time
127      *   * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
128      *   '  "abcdef"')
129      *   * calendarid - The calendarid as it was passed to this function.
130      *
131      * Note that the etag is optional, but it's highly encouraged to return for
132      * speed reasons.
133      *
134      * The calendardata is also optional. If it's not returned
135      * 'getCalendarObject' will be called later, which *is* expected to return
136      * calendardata.
137      *
138      * @param string $calendarId
139      * @return array
140      */
141     public function getCalendarObjects($calendarId) {
142
143         if (!isset($this->calendarData[$calendarId]))
144             return array();
145
146         $objects = $this->calendarData[$calendarId];
147         foreach($objects as $uri => &$object) {
148             $object['calendarid'] = $calendarId;
149             $object['uri'] = $uri;
150
151         }
152         return $objects;
153
154     }
155
156     /**
157      * Returns information from a single calendar object, based on it's object
158      * uri.
159      *
160      * The returned array must have the same keys as getCalendarObjects. The
161      * 'calendardata' object is required here though, while it's not required
162      * for getCalendarObjects.
163      *
164      * @param string $calendarId
165      * @param string $objectUri
166      * @return array
167      */
168     function getCalendarObject($calendarId,$objectUri) {
169
170         if (!isset($this->calendarData[$calendarId][$objectUri])) {
171             throw new Sabre_DAV_Exception_NotFound('Object could not be found');
172         }
173         $object = $this->calendarData[$calendarId][$objectUri];
174         $object['calendarid'] = $calendarId;
175         $object['uri'] = $objectUri;
176         return $object;
177
178     }
179
180     /**
181      * Creates a new calendar object.
182      *
183      * @param string $calendarId
184      * @param string $objectUri
185      * @param string $calendarData
186      * @return void
187      */
188     function createCalendarObject($calendarId,$objectUri,$calendarData) {
189
190         $this->calendarData[$calendarId][$objectUri] = array(
191             'calendardata' => $calendarData,
192             'calendarid' => $calendarId,
193             'uri' => $objectUri,
194         );
195
196     }
197
198     /**
199      * Updates an existing calendarobject, based on it's uri.
200      *
201      * @param string $calendarId
202      * @param string $objectUri
203      * @param string $calendarData
204      * @return void
205      */
206     function updateCalendarObject($calendarId,$objectUri,$calendarData) {
207
208         $this->calendarData[$calendarId][$objectUri] = array(
209             'calendardata' => $calendarData,
210             'calendarid' => $calendarId,
211             'uri' => $objectUri,
212         );
213
214     }
215
216     /**
217      * Deletes an existing calendar object.
218      *
219      * @param string $calendarId
220      * @param string $objectUri
221      * @return void
222      */
223     function deleteCalendarObject($calendarId,$objectUri) {
224
225         throw new Exception('Not implemented');
226
227
228     }
229
230 }