4 * Abstract Calendaring backend. Extend this class to create your own backends.
6 * Checkout the BackendInterface for all the methods that must be implemented.
10 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11 * @author Evert Pot (http://www.rooftopsolutions.nl/)
12 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14 abstract class Sabre_CalDAV_Backend_Abstract implements Sabre_CalDAV_Backend_BackendInterface {
17 * Updates properties for a calendar.
19 * The mutations array uses the propertyName in clark-notation as key,
20 * and the array value for the property value. In the case a property
21 * should be deleted, the property value will be null.
23 * This method must be atomic. If one property cannot be changed, the
24 * entire operation must fail.
26 * If the operation was successful, true can be returned.
27 * If the operation failed, false can be returned.
29 * Deletion of a non-existent property is always successful.
31 * Lastly, it is optional to return detailed information about any
32 * failures. In this case an array should be returned with the following
37 * '{DAV:}displayname' => null,
40 * '{DAV:}owner' => null,
44 * In this example it was forbidden to update {DAV:}displayname.
45 * (403 Forbidden), which in turn also caused {DAV:}owner to fail
46 * (424 Failed Dependency) because the request needs to be atomic.
48 * @param mixed $calendarId
49 * @param array $mutations
52 public function updateCalendar($calendarId, array $mutations) {
59 * Performs a calendar-query on the contents of this calendar.
61 * The calendar-query is defined in RFC4791 : CalDAV. Using the
62 * calendar-query it is possible for a client to request a specific set of
63 * object, based on contents of iCalendar properties, date-ranges and
64 * iCalendar component types (VTODO, VEVENT).
66 * This method should just return a list of (relative) urls that match this
69 * The list of filters are specified as an array. The exact array is
70 * documented by Sabre_CalDAV_CalendarQueryParser.
72 * Note that it is extremely likely that getCalendarObject for every path
73 * returned from this method will be called almost immediately after. You
74 * may want to anticipate this to speed up these requests.
76 * This method provides a default implementation, which parses *all* the
77 * iCalendar objects in the specified calendar.
79 * This default may well be good enough for personal use, and calendars
80 * that aren't very large. But if you anticipate high usage, big calendars
81 * or high loads, you are strongly adviced to optimize certain paths.
83 * The best way to do so is override this method and to optimize
84 * specifically for 'common filters'.
86 * Requests that are extremely common are:
87 * * requests for just VEVENTS
88 * * requests for just VTODO
89 * * requests with a time-range-filter on either VEVENT or VTODO.
91 * ..and combinations of these requests. It may not be worth it to try to
92 * handle every possible situation and just rely on the (relatively
93 * easy to use) CalendarQueryValidator to handle the rest.
95 * Note that especially time-range-filters may be difficult to parse. A
96 * time-range filter specified on a VEVENT must for instance also handle
97 * recurrence rules correctly.
98 * A good example of how to interprete all these filters can also simply
99 * be found in Sabre_CalDAV_CalendarQueryFilter. This class is as correct
100 * as possible, so it gives you a good idea on what type of stuff you need
103 * @param mixed $calendarId
104 * @param array $filters
107 public function calendarQuery($calendarId, array $filters) {
110 $objects = $this->getCalendarObjects($calendarId);
112 $validator = new Sabre_CalDAV_CalendarQueryValidator();
114 foreach($objects as $object) {
116 if ($this->validateFilterForObject($object, $filters)) {
117 $result[] = $object['uri'];
127 * This method validates if a filters (as passed to calendarQuery) matches
130 * @param array $object
131 * @param array $filter
134 protected function validateFilterForObject(array $object, array $filters) {
136 // Unfortunately, setting the 'calendardata' here is optional. If
137 // it was excluded, we actually need another call to get this as
139 if (!isset($object['calendardata'])) {
140 $object = $this->getCalendarObject($object['calendarid'], $object['uri']);
143 $vObject = Sabre_VObject_Reader::read($object['calendardata']);
145 $validator = new Sabre_CalDAV_CalendarQueryValidator();
146 return $validator->validate($vObject, $filters);