ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VFreeBusy.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Sabre\VObject;
7 
19 
29  function isFree(DateTimeInterface $start, DatetimeInterface $end) {
30 
31  foreach ($this->select('FREEBUSY') as $freebusy) {
32 
33  // We are only interested in FBTYPE=BUSY (the default),
34  // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
35  if (isset($freebusy['FBTYPE']) && strtoupper(substr((string)$freebusy['FBTYPE'], 0, 4)) !== 'BUSY') {
36  continue;
37  }
38 
39  // The freebusy component can hold more than 1 value, separated by
40  // commas.
41  $periods = explode(',', (string)$freebusy);
42 
43  foreach ($periods as $period) {
44  // Every period is formatted as [start]/[end]. The start is an
45  // absolute UTC time, the end may be an absolute UTC time, or
46  // duration (relative) value.
47  list($busyStart, $busyEnd) = explode('/', $period);
48 
49  $busyStart = VObject\DateTimeParser::parse($busyStart);
50  $busyEnd = VObject\DateTimeParser::parse($busyEnd);
51  if ($busyEnd instanceof \DateInterval) {
52  $busyEnd = $busyStart->add($busyEnd);
53  }
54 
55  if ($start < $busyEnd && $end > $busyStart) {
56  return false;
57  }
58 
59  }
60 
61  }
62 
63  return true;
64 
65  }
66 
82  function getValidationRules() {
83 
84  return [
85  'UID' => 1,
86  'DTSTAMP' => 1,
87 
88  'CONTACT' => '?',
89  'DTSTART' => '?',
90  'DTEND' => '?',
91  'ORGANIZER' => '?',
92  'URL' => '?',
93 
94  'ATTENDEE' => '*',
95  'COMMENT' => '*',
96  'FREEBUSY' => '*',
97  'REQUEST-STATUS' => '*',
98  ];
99 
100  }
101 
102 }
The VFreeBusy component.
Definition: VFreeBusy.php:18
static parse($date, $referenceTz=null)
Parses either a Date or DateTime, or Duration value.
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
$start
Definition: bench.php:8
isFree(DateTimeInterface $start, DatetimeInterface $end)
Checks based on the contained FREEBUSY information, if a timeslot is available.
Definition: VFreeBusy.php:29