ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractBackend.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\CalDAV;
6 use Sabre\VObject;
7 
17 abstract class AbstractBackend implements BackendInterface {
18 
35  function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) {
36 
37  }
38 
51  function getMultipleCalendarObjects($calendarId, array $uris) {
52 
53  return array_map(function($uri) use ($calendarId) {
54  return $this->getCalendarObject($calendarId, $uri);
55  }, $uris);
56 
57  }
58 
108  function calendarQuery($calendarId, array $filters) {
109 
110  $result = [];
111  $objects = $this->getCalendarObjects($calendarId);
112 
113  foreach ($objects as $object) {
114 
115  if ($this->validateFilterForObject($object, $filters)) {
116  $result[] = $object['uri'];
117  }
118 
119  }
120 
121  return $result;
122 
123  }
124 
133  protected function validateFilterForObject(array $object, array $filters) {
134 
135  // Unfortunately, setting the 'calendardata' here is optional. If
136  // it was excluded, we actually need another call to get this as
137  // well.
138  if (!isset($object['calendardata'])) {
139  $object = $this->getCalendarObject($object['calendarid'], $object['uri']);
140  }
141 
142  $vObject = VObject\Reader::read($object['calendardata']);
143 
144  $validator = new CalDAV\CalendarQueryValidator();
145  $result = $validator->validate($vObject, $filters);
146 
147  // Destroy circular references so PHP will GC the object.
148  $vObject->destroy();
149 
150  return $result;
151 
152  }
153 
173  function getCalendarObjectByUID($principalUri, $uid) {
174 
175  // Note: this is a super slow naive implementation of this method. You
176  // are highly recommended to optimize it, if your backend allows it.
177  foreach ($this->getCalendarsForUser($principalUri) as $calendar) {
178 
179  // We must ignore calendars owned by other principals.
180  if ($calendar['principaluri'] !== $principalUri) {
181  continue;
182  }
183 
184  // Ignore calendars that are shared.
185  if (isset($calendar['{http://sabredav.org/ns}owner-principal']) && $calendar['{http://sabredav.org/ns}owner-principal'] !== $principalUri) {
186  continue;
187  }
188 
189  $results = $this->calendarQuery(
190  $calendar['id'],
191  [
192  'name' => 'VCALENDAR',
193  'prop-filters' => [],
194  'comp-filters' => [
195  [
196  'name' => 'VEVENT',
197  'is-not-defined' => false,
198  'time-range' => null,
199  'comp-filters' => [],
200  'prop-filters' => [
201  [
202  'name' => 'UID',
203  'is-not-defined' => false,
204  'time-range' => null,
205  'text-match' => [
206  'value' => $uid,
207  'negate-condition' => false,
208  'collation' => 'i;octet',
209  ],
210  'param-filters' => [],
211  ],
212  ]
213  ]
214  ],
215  ]
216  );
217  if ($results) {
218  // We have a match
219  return $calendar['uri'] . '/' . $results[0];
220  }
221 
222  }
223 
224  }
225 
226 }
calendarQuery($calendarId, array $filters)
Performs a calendar-query on the contents of this calendar.
getCalendarsForUser($principalUri)
Returns a list of calendars for a principal.
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
$result
getCalendarObjects($calendarId)
Returns all calendar objects within a calendar.
getCalendarObject($calendarId, $objectUri)
Returns information from a single calendar object, based on it&#39;s object uri.
getCalendarObjectByUID($principalUri, $uid)
Searches through all of a users calendars and calendar objects to find an object with a specific UID...
Every CalDAV backend must at least implement this interface.
getMultipleCalendarObjects($calendarId, array $uris)
Returns a list of calendar objects.
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
$results
Definition: svg-scanner.php:47
updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch)
Updates properties for a calendar.
validateFilterForObject(array $object, array $filters)
This method validates if a filter (as passed to calendarQuery) matches the given object.
Abstract Calendaring backend.