3 class Sabre_CalDAV_Backend_Mock extends Sabre_CalDAV_Backend_Abstract {
8 function __construct(array $calendars, array $calendarData) {
10 $this->calendars = $calendars;
11 $this->calendarData = $calendarData;
16 * Returns a list of calendars for a principal.
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
23 * * principalUri. The owner of the calendar. Almost always the same as
24 * principalUri passed to this method.
26 * Furthermore it can contain webdav properties in clark notation. A very
27 * common one is '{DAV:}displayname'.
29 * @param string $principalUri
32 function getCalendarsForUser($principalUri) {
35 foreach($this->calendars as $row) {
36 if ($row['principaluri'] == $principalUri) {
46 * Creates a new calendar for a principal.
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.
51 * This function must return a server-wide unique id that can be used
52 * later to reference the calendar.
54 * @param string $principalUri
55 * @param string $calendarUri
56 * @param array $properties
59 function createCalendar($principalUri,$calendarUri,array $properties) {
61 throw new Exception('Not implemented');
66 * Updates properties on this node,
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.
72 * This method must be atomic. If one property cannot be changed, the
73 * entire operation must fail.
75 * If the operation was successful, true can be returned.
76 * If the operation failed, false can be returned.
78 * Deletion of a non-existent property is always successful.
80 * Lastly, it is optional to return detailed information about any
81 * failures. In this case an array should be returned with the following
86 * '{DAV:}displayname' => null,
89 * '{DAV:}owner' => null,
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.
97 * @param string $calendarId
98 * @param array $properties
101 public function updateCalendar($calendarId, array $properties) {
108 * Delete a calendar and all it's objects
110 * @param string $calendarId
113 public function deleteCalendar($calendarId) {
115 throw new Exception('Not implemented');
120 * Returns all calendar objects within a calendar object.
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.:
129 * * calendarid - The calendarid as it was passed to this function.
131 * Note that the etag is optional, but it's highly encouraged to return for
134 * The calendardata is also optional. If it's not returned
135 * 'getCalendarObject' will be called later, which *is* expected to return
138 * @param string $calendarId
141 public function getCalendarObjects($calendarId) {
143 if (!isset($this->calendarData[$calendarId]))
146 $objects = $this->calendarData[$calendarId];
147 foreach($objects as $uri => &$object) {
148 $object['calendarid'] = $calendarId;
149 $object['uri'] = $uri;
157 * Returns information from a single calendar object, based on it's object
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.
164 * @param string $calendarId
165 * @param string $objectUri
168 function getCalendarObject($calendarId,$objectUri) {
170 if (!isset($this->calendarData[$calendarId][$objectUri])) {
171 throw new Sabre_DAV_Exception_NotFound('Object could not be found');
173 $object = $this->calendarData[$calendarId][$objectUri];
174 $object['calendarid'] = $calendarId;
175 $object['uri'] = $objectUri;
181 * Creates a new calendar object.
183 * @param string $calendarId
184 * @param string $objectUri
185 * @param string $calendarData
188 function createCalendarObject($calendarId,$objectUri,$calendarData) {
190 $this->calendarData[$calendarId][$objectUri] = array(
191 'calendardata' => $calendarData,
192 'calendarid' => $calendarId,
199 * Updates an existing calendarobject, based on it's uri.
201 * @param string $calendarId
202 * @param string $objectUri
203 * @param string $calendarData
206 function updateCalendarObject($calendarId,$objectUri,$calendarData) {
208 $this->calendarData[$calendarId][$objectUri] = array(
209 'calendardata' => $calendarData,
210 'calendarid' => $calendarId,
217 * Deletes an existing calendar object.
219 * @param string $calendarId
220 * @param string $objectUri
223 function deleteCalendarObject($calendarId,$objectUri) {
225 throw new Exception('Not implemented');