]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CalDAV/Backend/Abstract.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CalDAV / Backend / Abstract.php
1 <?php
2
3 /**
4  * Abstract Calendaring backend. Extend this class to create your own backends.
5  *
6  * Checkout the BackendInterface for all the methods that must be implemented.
7  *
8  * @package Sabre
9  * @subpackage CalDAV
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
13  */
14 abstract class Sabre_CalDAV_Backend_Abstract implements Sabre_CalDAV_Backend_BackendInterface {
15
16     /**
17      * Updates properties for a calendar.
18      *
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.
22      *
23      * This method must be atomic. If one property cannot be changed, the
24      * entire operation must fail.
25      *
26      * If the operation was successful, true can be returned.
27      * If the operation failed, false can be returned.
28      *
29      * Deletion of a non-existent property is always successful.
30      *
31      * Lastly, it is optional to return detailed information about any
32      * failures. In this case an array should be returned with the following
33      * structure:
34      *
35      * array(
36      *   403 => array(
37      *      '{DAV:}displayname' => null,
38      *   ),
39      *   424 => array(
40      *      '{DAV:}owner' => null,
41      *   )
42      * )
43      *
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.
47      *
48      * @param mixed $calendarId
49      * @param array $mutations
50      * @return bool|array
51      */
52     public function updateCalendar($calendarId, array $mutations) {
53
54         return false;
55
56     }
57
58     /**
59      * Performs a calendar-query on the contents of this calendar.
60      *
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).
65      *
66      * This method should just return a list of (relative) urls that match this
67      * query.
68      *
69      * The list of filters are specified as an array. The exact array is
70      * documented by Sabre_CalDAV_CalendarQueryParser.
71      *
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.
75      *
76      * This method provides a default implementation, which parses *all* the
77      * iCalendar objects in the specified calendar.
78      *
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.
82      *
83      * The best way to do so is override this method and to optimize
84      * specifically for 'common filters'.
85      *
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.
90      *
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.
94      *
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
101      * to think of.
102      *
103      * @param mixed $calendarId
104      * @param array $filters
105      * @return array
106      */
107     public function calendarQuery($calendarId, array $filters) {
108
109         $result = array();
110         $objects = $this->getCalendarObjects($calendarId);
111
112         $validator = new Sabre_CalDAV_CalendarQueryValidator();
113
114         foreach($objects as $object) {
115
116             if ($this->validateFilterForObject($object, $filters)) {
117                 $result[] = $object['uri'];
118             }
119
120         }
121
122         return $result;
123
124     }
125
126     /**
127      * This method validates if a filters (as passed to calendarQuery) matches
128      * the given object.
129      *
130      * @param array $object
131      * @param array $filter
132      * @return bool
133      */
134     protected function validateFilterForObject(array $object, array $filters) {
135
136         // Unfortunately, setting the 'calendardata' here is optional. If
137         // it was excluded, we actually need another call to get this as
138         // well.
139         if (!isset($object['calendardata'])) {
140             $object = $this->getCalendarObject($object['calendarid'], $object['uri']);
141         }
142
143         $vObject = Sabre_VObject_Reader::read($object['calendardata']);
144
145         $validator = new Sabre_CalDAV_CalendarQueryValidator();
146         return $validator->validate($vObject, $filters);
147
148     }
149
150
151 }