3 class Sabre_CalDAV_Backend_Mock extends Sabre_CalDAV_Backend_Abstract implements Sabre_CalDAV_Backend_NotificationSupport {
7 private $notifications;
9 function __construct(array $calendars, array $calendarData, array $notifications = array()) {
11 $this->calendars = $calendars;
12 $this->calendarData = $calendarData;
13 $this->notifications = $notifications;
18 * Returns a list of calendars for a principal.
20 * Every project is an array with the following keys:
21 * * id, a unique id that will be used by other functions to modify the
22 * calendar. This can be the same as the uri or a database key.
23 * * uri, which the basename of the uri with which the calendar is
25 * * principalUri. The owner of the calendar. Almost always the same as
26 * principalUri passed to this method.
28 * Furthermore it can contain webdav properties in clark notation. A very
29 * common one is '{DAV:}displayname'.
31 * @param string $principalUri
34 function getCalendarsForUser($principalUri) {
37 foreach($this->calendars as $row) {
38 if ($row['principaluri'] == $principalUri) {
48 * Creates a new calendar for a principal.
50 * If the creation was a success, an id must be returned that can be used to reference
51 * this calendar in other methods, such as updateCalendar.
53 * This function must return a server-wide unique id that can be used
54 * later to reference the calendar.
56 * @param string $principalUri
57 * @param string $calendarUri
58 * @param array $properties
61 function createCalendar($principalUri,$calendarUri,array $properties) {
63 $id = Sabre_DAV_UUIDUtil::getUUID();
64 $this->calendars[] = array_merge(array(
66 'principaluri' => $principalUri,
67 'uri' => $calendarUri,
68 '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(array('VEVENT','VTODO')),
76 * Updates properties on this node,
78 * The properties array uses the propertyName in clark-notation as key,
79 * and the array value for the property value. In the case a property
80 * should be deleted, the property value will be null.
82 * This method must be atomic. If one property cannot be changed, the
83 * entire operation must fail.
85 * If the operation was successful, true can be returned.
86 * If the operation failed, false can be returned.
88 * Deletion of a non-existent property is always successful.
90 * Lastly, it is optional to return detailed information about any
91 * failures. In this case an array should be returned with the following
96 * '{DAV:}displayname' => null,
99 * '{DAV:}owner' => null,
103 * In this example it was forbidden to update {DAV:}displayname.
104 * (403 Forbidden), which in turn also caused {DAV:}owner to fail
105 * (424 Failed Dependency) because the request needs to be atomic.
107 * @param string $calendarId
108 * @param array $properties
111 public function updateCalendar($calendarId, array $properties) {
118 * Delete a calendar and all it's objects
120 * @param string $calendarId
123 public function deleteCalendar($calendarId) {
125 foreach($this->calendars as $k=>$calendar) {
126 if ($calendar['id'] === $calendarId) {
127 unset($this->calendars[$k]);
134 * Returns all calendar objects within a calendar object.
136 * Every item contains an array with the following keys:
137 * * id - unique identifier which will be used for subsequent updates
138 * * calendardata - The iCalendar-compatible calendar data
139 * * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
140 * * lastmodified - a timestamp of the last modification time
141 * * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
143 * * calendarid - The calendarid as it was passed to this function.
145 * Note that the etag is optional, but it's highly encouraged to return for
148 * The calendardata is also optional. If it's not returned
149 * 'getCalendarObject' will be called later, which *is* expected to return
152 * @param string $calendarId
155 public function getCalendarObjects($calendarId) {
157 if (!isset($this->calendarData[$calendarId]))
160 $objects = $this->calendarData[$calendarId];
161 foreach($objects as $uri => &$object) {
162 $object['calendarid'] = $calendarId;
163 $object['uri'] = $uri;
171 * Returns information from a single calendar object, based on it's object
174 * The returned array must have the same keys as getCalendarObjects. The
175 * 'calendardata' object is required here though, while it's not required
176 * for getCalendarObjects.
178 * @param string $calendarId
179 * @param string $objectUri
182 function getCalendarObject($calendarId,$objectUri) {
184 if (!isset($this->calendarData[$calendarId][$objectUri])) {
185 throw new Sabre_DAV_Exception_NotFound('Object could not be found');
187 $object = $this->calendarData[$calendarId][$objectUri];
188 $object['calendarid'] = $calendarId;
189 $object['uri'] = $objectUri;
195 * Creates a new calendar object.
197 * @param string $calendarId
198 * @param string $objectUri
199 * @param string $calendarData
202 function createCalendarObject($calendarId,$objectUri,$calendarData) {
204 $this->calendarData[$calendarId][$objectUri] = array(
205 'calendardata' => $calendarData,
206 'calendarid' => $calendarId,
213 * Updates an existing calendarobject, based on it's uri.
215 * @param string $calendarId
216 * @param string $objectUri
217 * @param string $calendarData
220 function updateCalendarObject($calendarId,$objectUri,$calendarData) {
222 $this->calendarData[$calendarId][$objectUri] = array(
223 'calendardata' => $calendarData,
224 'calendarid' => $calendarId,
231 * Deletes an existing calendar object.
233 * @param string $calendarId
234 * @param string $objectUri
237 function deleteCalendarObject($calendarId,$objectUri) {
239 throw new Exception('Not implemented');
245 * Returns a list of notifications for a given principal url.
247 * The returned array should only consist of implementations of
248 * Sabre_CalDAV_Notifications_INotificationType.
250 * @param string $principalUri
253 public function getNotificationsForPrincipal($principalUri) {
255 if (isset($this->notifications[$principalUri])) {
256 return $this->notifications[$principalUri];
263 * This deletes a specific notifcation.
265 * This may be called by a client once it deems a notification handled.
267 * @param string $principalUri
268 * @param Sabre_CalDAV_Notifications_INotificationType $notification
271 public function deleteNotification($principalUri, Sabre_CalDAV_Notifications_INotificationType $notification) {
273 throw new Sabre_DAV_Exception_NotImplemented('This doesn\'t work!');