Available.php
1 year ago
VAlarm.php
1 year ago
VAvailability.php
1 year ago
VCalendar.php
1 year ago
VCard.php
1 year ago
VEvent.php
1 year ago
VFreeBusy.php
1 year ago
VJournal.php
1 year ago
VTimeZone.php
1 year ago
VTodo.php
1 year ago
VFreeBusy.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Sabre\VObject\Component; |
| 4 | |
| 5 | use DateTimeInterface; |
| 6 | use Sabre\VObject; |
| 7 | |
| 8 | /** |
| 9 | * The VFreeBusy component. |
| 10 | * |
| 11 | * This component adds functionality to a component, specific for VFREEBUSY |
| 12 | * components. |
| 13 | * |
| 14 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 15 | * @author Evert Pot (http://evertpot.com/) |
| 16 | * @license http://sabre.io/license/ Modified BSD License |
| 17 | */ |
| 18 | class VFreeBusy extends VObject\Component |
| 19 | { |
| 20 | /** |
| 21 | * Checks based on the contained FREEBUSY information, if a timeslot is |
| 22 | * available. |
| 23 | * |
| 24 | * @return bool |
| 25 | */ |
| 26 | public function isFree(DateTimeInterface $start, DatetimeInterface $end) |
| 27 | { |
| 28 | foreach ($this->select('FREEBUSY') as $freebusy) { |
| 29 | // We are only interested in FBTYPE=BUSY (the default), |
| 30 | // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE. |
| 31 | if (isset($freebusy['FBTYPE']) && 'BUSY' !== strtoupper(substr((string) $freebusy['FBTYPE'], 0, 4))) { |
| 32 | continue; |
| 33 | } |
| 34 | |
| 35 | // The freebusy component can hold more than 1 value, separated by |
| 36 | // commas. |
| 37 | $periods = explode(',', (string) $freebusy); |
| 38 | |
| 39 | foreach ($periods as $period) { |
| 40 | // Every period is formatted as [start]/[end]. The start is an |
| 41 | // absolute UTC time, the end may be an absolute UTC time, or |
| 42 | // duration (relative) value. |
| 43 | list($busyStart, $busyEnd) = explode('/', $period); |
| 44 | |
| 45 | $busyStart = VObject\DateTimeParser::parse($busyStart); |
| 46 | $busyEnd = VObject\DateTimeParser::parse($busyEnd); |
| 47 | if ($busyEnd instanceof \DateInterval) { |
| 48 | $busyEnd = $busyStart->add($busyEnd); |
| 49 | } |
| 50 | |
| 51 | if ($start < $busyEnd && $end > $busyStart) { |
| 52 | return false; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * A simple list of validation rules. |
| 62 | * |
| 63 | * This is simply a list of properties, and how many times they either |
| 64 | * must or must not appear. |
| 65 | * |
| 66 | * Possible values per property: |
| 67 | * * 0 - Must not appear. |
| 68 | * * 1 - Must appear exactly once. |
| 69 | * * + - Must appear at least once. |
| 70 | * * * - Can appear any number of times. |
| 71 | * * ? - May appear, but not more than once. |
| 72 | * |
| 73 | * @var array |
| 74 | */ |
| 75 | public function getValidationRules() |
| 76 | { |
| 77 | return [ |
| 78 | 'UID' => 1, |
| 79 | 'DTSTAMP' => 1, |
| 80 | |
| 81 | 'CONTACT' => '?', |
| 82 | 'DTSTART' => '?', |
| 83 | 'DTEND' => '?', |
| 84 | 'ORGANIZER' => '?', |
| 85 | 'URL' => '?', |
| 86 | |
| 87 | 'ATTENDEE' => '*', |
| 88 | 'COMMENT' => '*', |
| 89 | 'FREEBUSY' => '*', |
| 90 | 'REQUEST-STATUS' => '*', |
| 91 | ]; |
| 92 | } |
| 93 | } |
| 94 |