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