1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Backend; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehler/** 6*a1a3b679SAndreas Boehler * Every CalDAV backend must at least implement this interface. 7*a1a3b679SAndreas Boehler * 8*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 9*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 10*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 11*a1a3b679SAndreas Boehler */ 12*a1a3b679SAndreas Boehlerinterface BackendInterface { 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler /** 15*a1a3b679SAndreas Boehler * Returns a list of calendars for a principal. 16*a1a3b679SAndreas Boehler * 17*a1a3b679SAndreas Boehler * Every project is an array with the following keys: 18*a1a3b679SAndreas Boehler * * id, a unique id that will be used by other functions to modify the 19*a1a3b679SAndreas Boehler * calendar. This can be the same as the uri or a database key. 20*a1a3b679SAndreas Boehler * * uri, which is the basename of the uri with which the calendar is 21*a1a3b679SAndreas Boehler * accessed. 22*a1a3b679SAndreas Boehler * * principaluri. The owner of the calendar. Almost always the same as 23*a1a3b679SAndreas Boehler * principalUri passed to this method. 24*a1a3b679SAndreas Boehler * 25*a1a3b679SAndreas Boehler * Furthermore it can contain webdav properties in clark notation. A very 26*a1a3b679SAndreas Boehler * common one is '{DAV:}displayname'. 27*a1a3b679SAndreas Boehler * 28*a1a3b679SAndreas Boehler * Many clients also require: 29*a1a3b679SAndreas Boehler * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set 30*a1a3b679SAndreas Boehler * For this property, you can just return an instance of 31*a1a3b679SAndreas Boehler * Sabre\CalDAV\Property\SupportedCalendarComponentSet. 32*a1a3b679SAndreas Boehler * 33*a1a3b679SAndreas Boehler * If you return {http://sabredav.org/ns}read-only and set the value to 1, 34*a1a3b679SAndreas Boehler * ACL will automatically be put in read-only mode. 35*a1a3b679SAndreas Boehler * 36*a1a3b679SAndreas Boehler * @param string $principalUri 37*a1a3b679SAndreas Boehler * @return array 38*a1a3b679SAndreas Boehler */ 39*a1a3b679SAndreas Boehler function getCalendarsForUser($principalUri); 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler /** 42*a1a3b679SAndreas Boehler * Creates a new calendar for a principal. 43*a1a3b679SAndreas Boehler * 44*a1a3b679SAndreas Boehler * If the creation was a success, an id must be returned that can be used to 45*a1a3b679SAndreas Boehler * reference this calendar in other methods, such as updateCalendar. 46*a1a3b679SAndreas Boehler * 47*a1a3b679SAndreas Boehler * @param string $principalUri 48*a1a3b679SAndreas Boehler * @param string $calendarUri 49*a1a3b679SAndreas Boehler * @param array $properties 50*a1a3b679SAndreas Boehler * @return void 51*a1a3b679SAndreas Boehler */ 52*a1a3b679SAndreas Boehler function createCalendar($principalUri, $calendarUri, array $properties); 53*a1a3b679SAndreas Boehler 54*a1a3b679SAndreas Boehler /** 55*a1a3b679SAndreas Boehler * Updates properties for a calendar. 56*a1a3b679SAndreas Boehler * 57*a1a3b679SAndreas Boehler * The list of mutations is stored in a Sabre\DAV\PropPatch object. 58*a1a3b679SAndreas Boehler * To do the actual updates, you must tell this object which properties 59*a1a3b679SAndreas Boehler * you're going to process with the handle() method. 60*a1a3b679SAndreas Boehler * 61*a1a3b679SAndreas Boehler * Calling the handle method is like telling the PropPatch object "I 62*a1a3b679SAndreas Boehler * promise I can handle updating this property". 63*a1a3b679SAndreas Boehler * 64*a1a3b679SAndreas Boehler * Read the PropPatch documentation for more info and examples. 65*a1a3b679SAndreas Boehler * 66*a1a3b679SAndreas Boehler * @param string $path 67*a1a3b679SAndreas Boehler * @param \Sabre\DAV\PropPatch $propPatch 68*a1a3b679SAndreas Boehler * @return void 69*a1a3b679SAndreas Boehler */ 70*a1a3b679SAndreas Boehler function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch); 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler /** 73*a1a3b679SAndreas Boehler * Delete a calendar and all its objects 74*a1a3b679SAndreas Boehler * 75*a1a3b679SAndreas Boehler * @param mixed $calendarId 76*a1a3b679SAndreas Boehler * @return void 77*a1a3b679SAndreas Boehler */ 78*a1a3b679SAndreas Boehler function deleteCalendar($calendarId); 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler /** 81*a1a3b679SAndreas Boehler * Returns all calendar objects within a calendar. 82*a1a3b679SAndreas Boehler * 83*a1a3b679SAndreas Boehler * Every item contains an array with the following keys: 84*a1a3b679SAndreas Boehler * * calendardata - The iCalendar-compatible calendar data 85*a1a3b679SAndreas Boehler * * uri - a unique key which will be used to construct the uri. This can 86*a1a3b679SAndreas Boehler * be any arbitrary string, but making sure it ends with '.ics' is a 87*a1a3b679SAndreas Boehler * good idea. This is only the basename, or filename, not the full 88*a1a3b679SAndreas Boehler * path. 89*a1a3b679SAndreas Boehler * * lastmodified - a timestamp of the last modification time 90*a1a3b679SAndreas Boehler * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: 91*a1a3b679SAndreas Boehler * '"abcdef"') 92*a1a3b679SAndreas Boehler * * size - The size of the calendar objects, in bytes. 93*a1a3b679SAndreas Boehler * * component - optional, a string containing the type of object, such 94*a1a3b679SAndreas Boehler * as 'vevent' or 'vtodo'. If specified, this will be used to populate 95*a1a3b679SAndreas Boehler * the Content-Type header. 96*a1a3b679SAndreas Boehler * 97*a1a3b679SAndreas Boehler * Note that the etag is optional, but it's highly encouraged to return for 98*a1a3b679SAndreas Boehler * speed reasons. 99*a1a3b679SAndreas Boehler * 100*a1a3b679SAndreas Boehler * The calendardata is also optional. If it's not returned 101*a1a3b679SAndreas Boehler * 'getCalendarObject' will be called later, which *is* expected to return 102*a1a3b679SAndreas Boehler * calendardata. 103*a1a3b679SAndreas Boehler * 104*a1a3b679SAndreas Boehler * If neither etag or size are specified, the calendardata will be 105*a1a3b679SAndreas Boehler * used/fetched to determine these numbers. If both are specified the 106*a1a3b679SAndreas Boehler * amount of times this is needed is reduced by a great degree. 107*a1a3b679SAndreas Boehler * 108*a1a3b679SAndreas Boehler * @param mixed $calendarId 109*a1a3b679SAndreas Boehler * @return array 110*a1a3b679SAndreas Boehler */ 111*a1a3b679SAndreas Boehler function getCalendarObjects($calendarId); 112*a1a3b679SAndreas Boehler 113*a1a3b679SAndreas Boehler /** 114*a1a3b679SAndreas Boehler * Returns information from a single calendar object, based on it's object 115*a1a3b679SAndreas Boehler * uri. 116*a1a3b679SAndreas Boehler * 117*a1a3b679SAndreas Boehler * The object uri is only the basename, or filename and not a full path. 118*a1a3b679SAndreas Boehler * 119*a1a3b679SAndreas Boehler * The returned array must have the same keys as getCalendarObjects. The 120*a1a3b679SAndreas Boehler * 'calendardata' object is required here though, while it's not required 121*a1a3b679SAndreas Boehler * for getCalendarObjects. 122*a1a3b679SAndreas Boehler * 123*a1a3b679SAndreas Boehler * This method must return null if the object did not exist. 124*a1a3b679SAndreas Boehler * 125*a1a3b679SAndreas Boehler * @param mixed $calendarId 126*a1a3b679SAndreas Boehler * @param string $objectUri 127*a1a3b679SAndreas Boehler * @return array|null 128*a1a3b679SAndreas Boehler */ 129*a1a3b679SAndreas Boehler function getCalendarObject($calendarId, $objectUri); 130*a1a3b679SAndreas Boehler 131*a1a3b679SAndreas Boehler /** 132*a1a3b679SAndreas Boehler * Returns a list of calendar objects. 133*a1a3b679SAndreas Boehler * 134*a1a3b679SAndreas Boehler * This method should work identical to getCalendarObject, but instead 135*a1a3b679SAndreas Boehler * return all the calendar objects in the list as an array. 136*a1a3b679SAndreas Boehler * 137*a1a3b679SAndreas Boehler * If the backend supports this, it may allow for some speed-ups. 138*a1a3b679SAndreas Boehler * 139*a1a3b679SAndreas Boehler * @param mixed $calendarId 140*a1a3b679SAndreas Boehler * @param array $uris 141*a1a3b679SAndreas Boehler * @return array 142*a1a3b679SAndreas Boehler */ 143*a1a3b679SAndreas Boehler function getMultipleCalendarObjects($calendarId, array $uris); 144*a1a3b679SAndreas Boehler 145*a1a3b679SAndreas Boehler /** 146*a1a3b679SAndreas Boehler * Creates a new calendar object. 147*a1a3b679SAndreas Boehler * 148*a1a3b679SAndreas Boehler * The object uri is only the basename, or filename and not a full path. 149*a1a3b679SAndreas Boehler * 150*a1a3b679SAndreas Boehler * It is possible to return an etag from this function, which will be used 151*a1a3b679SAndreas Boehler * in the response to this PUT request. Note that the ETag must be 152*a1a3b679SAndreas Boehler * surrounded by double-quotes. 153*a1a3b679SAndreas Boehler * 154*a1a3b679SAndreas Boehler * However, you should only really return this ETag if you don't mangle the 155*a1a3b679SAndreas Boehler * calendar-data. If the result of a subsequent GET to this object is not 156*a1a3b679SAndreas Boehler * the exact same as this request body, you should omit the ETag. 157*a1a3b679SAndreas Boehler * 158*a1a3b679SAndreas Boehler * @param mixed $calendarId 159*a1a3b679SAndreas Boehler * @param string $objectUri 160*a1a3b679SAndreas Boehler * @param string $calendarData 161*a1a3b679SAndreas Boehler * @return string|null 162*a1a3b679SAndreas Boehler */ 163*a1a3b679SAndreas Boehler function createCalendarObject($calendarId, $objectUri, $calendarData); 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler /** 166*a1a3b679SAndreas Boehler * Updates an existing calendarobject, based on it's uri. 167*a1a3b679SAndreas Boehler * 168*a1a3b679SAndreas Boehler * The object uri is only the basename, or filename and not a full path. 169*a1a3b679SAndreas Boehler * 170*a1a3b679SAndreas Boehler * It is possible return an etag from this function, which will be used in 171*a1a3b679SAndreas Boehler * the response to this PUT request. Note that the ETag must be surrounded 172*a1a3b679SAndreas Boehler * by double-quotes. 173*a1a3b679SAndreas Boehler * 174*a1a3b679SAndreas Boehler * However, you should only really return this ETag if you don't mangle the 175*a1a3b679SAndreas Boehler * calendar-data. If the result of a subsequent GET to this object is not 176*a1a3b679SAndreas Boehler * the exact same as this request body, you should omit the ETag. 177*a1a3b679SAndreas Boehler * 178*a1a3b679SAndreas Boehler * @param mixed $calendarId 179*a1a3b679SAndreas Boehler * @param string $objectUri 180*a1a3b679SAndreas Boehler * @param string $calendarData 181*a1a3b679SAndreas Boehler * @return string|null 182*a1a3b679SAndreas Boehler */ 183*a1a3b679SAndreas Boehler function updateCalendarObject($calendarId, $objectUri, $calendarData); 184*a1a3b679SAndreas Boehler 185*a1a3b679SAndreas Boehler /** 186*a1a3b679SAndreas Boehler * Deletes an existing calendar object. 187*a1a3b679SAndreas Boehler * 188*a1a3b679SAndreas Boehler * The object uri is only the basename, or filename and not a full path. 189*a1a3b679SAndreas Boehler * 190*a1a3b679SAndreas Boehler * @param mixed $calendarId 191*a1a3b679SAndreas Boehler * @param string $objectUri 192*a1a3b679SAndreas Boehler * @return void 193*a1a3b679SAndreas Boehler */ 194*a1a3b679SAndreas Boehler function deleteCalendarObject($calendarId, $objectUri); 195*a1a3b679SAndreas Boehler 196*a1a3b679SAndreas Boehler /** 197*a1a3b679SAndreas Boehler * Performs a calendar-query on the contents of this calendar. 198*a1a3b679SAndreas Boehler * 199*a1a3b679SAndreas Boehler * The calendar-query is defined in RFC4791 : CalDAV. Using the 200*a1a3b679SAndreas Boehler * calendar-query it is possible for a client to request a specific set of 201*a1a3b679SAndreas Boehler * object, based on contents of iCalendar properties, date-ranges and 202*a1a3b679SAndreas Boehler * iCalendar component types (VTODO, VEVENT). 203*a1a3b679SAndreas Boehler * 204*a1a3b679SAndreas Boehler * This method should just return a list of (relative) urls that match this 205*a1a3b679SAndreas Boehler * query. 206*a1a3b679SAndreas Boehler * 207*a1a3b679SAndreas Boehler * The list of filters are specified as an array. The exact array is 208*a1a3b679SAndreas Boehler * documented by Sabre\CalDAV\CalendarQueryParser. 209*a1a3b679SAndreas Boehler * 210*a1a3b679SAndreas Boehler * Note that it is extremely likely that getCalendarObject for every path 211*a1a3b679SAndreas Boehler * returned from this method will be called almost immediately after. You 212*a1a3b679SAndreas Boehler * may want to anticipate this to speed up these requests. 213*a1a3b679SAndreas Boehler * 214*a1a3b679SAndreas Boehler * This method provides a default implementation, which parses *all* the 215*a1a3b679SAndreas Boehler * iCalendar objects in the specified calendar. 216*a1a3b679SAndreas Boehler * 217*a1a3b679SAndreas Boehler * This default may well be good enough for personal use, and calendars 218*a1a3b679SAndreas Boehler * that aren't very large. But if you anticipate high usage, big calendars 219*a1a3b679SAndreas Boehler * or high loads, you are strongly adviced to optimize certain paths. 220*a1a3b679SAndreas Boehler * 221*a1a3b679SAndreas Boehler * The best way to do so is override this method and to optimize 222*a1a3b679SAndreas Boehler * specifically for 'common filters'. 223*a1a3b679SAndreas Boehler * 224*a1a3b679SAndreas Boehler * Requests that are extremely common are: 225*a1a3b679SAndreas Boehler * * requests for just VEVENTS 226*a1a3b679SAndreas Boehler * * requests for just VTODO 227*a1a3b679SAndreas Boehler * * requests with a time-range-filter on either VEVENT or VTODO. 228*a1a3b679SAndreas Boehler * 229*a1a3b679SAndreas Boehler * ..and combinations of these requests. It may not be worth it to try to 230*a1a3b679SAndreas Boehler * handle every possible situation and just rely on the (relatively 231*a1a3b679SAndreas Boehler * easy to use) CalendarQueryValidator to handle the rest. 232*a1a3b679SAndreas Boehler * 233*a1a3b679SAndreas Boehler * Note that especially time-range-filters may be difficult to parse. A 234*a1a3b679SAndreas Boehler * time-range filter specified on a VEVENT must for instance also handle 235*a1a3b679SAndreas Boehler * recurrence rules correctly. 236*a1a3b679SAndreas Boehler * A good example of how to interprete all these filters can also simply 237*a1a3b679SAndreas Boehler * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct 238*a1a3b679SAndreas Boehler * as possible, so it gives you a good idea on what type of stuff you need 239*a1a3b679SAndreas Boehler * to think of. 240*a1a3b679SAndreas Boehler * 241*a1a3b679SAndreas Boehler * @param mixed $calendarId 242*a1a3b679SAndreas Boehler * @param array $filters 243*a1a3b679SAndreas Boehler * @return array 244*a1a3b679SAndreas Boehler */ 245*a1a3b679SAndreas Boehler function calendarQuery($calendarId, array $filters); 246*a1a3b679SAndreas Boehler 247*a1a3b679SAndreas Boehler /** 248*a1a3b679SAndreas Boehler * Searches through all of a users calendars and calendar objects to find 249*a1a3b679SAndreas Boehler * an object with a specific UID. 250*a1a3b679SAndreas Boehler * 251*a1a3b679SAndreas Boehler * This method should return the path to this object, relative to the 252*a1a3b679SAndreas Boehler * calendar home, so this path usually only contains two parts: 253*a1a3b679SAndreas Boehler * 254*a1a3b679SAndreas Boehler * calendarpath/objectpath.ics 255*a1a3b679SAndreas Boehler * 256*a1a3b679SAndreas Boehler * If the uid is not found, return null. 257*a1a3b679SAndreas Boehler * 258*a1a3b679SAndreas Boehler * This method should only consider * objects that the principal owns, so 259*a1a3b679SAndreas Boehler * any calendars owned by other principals that also appear in this 260*a1a3b679SAndreas Boehler * collection should be ignored. 261*a1a3b679SAndreas Boehler * 262*a1a3b679SAndreas Boehler * @param string $principalUri 263*a1a3b679SAndreas Boehler * @param string $uid 264*a1a3b679SAndreas Boehler * @return string|null 265*a1a3b679SAndreas Boehler */ 266*a1a3b679SAndreas Boehler function getCalendarObjectByUID($principalUri, $uid); 267*a1a3b679SAndreas Boehler 268*a1a3b679SAndreas Boehler} 269