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