Available.php
6 months ago
VAlarm.php
6 months ago
VAvailability.php
6 months ago
VCalendar.php
6 months ago
VCard.php
6 months ago
VEvent.php
6 months ago
VFreeBusy.php
6 months ago
VJournal.php
6 months ago
VTimeZone.php
6 months ago
VTodo.php
6 months ago
VAvailability.php
150 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject\Component; |
| 4 | |
| 5 | use DateTimeInterface; |
| 6 | use AmeliaVendor\Sabre\VObject; |
| 7 | |
| 8 | /** |
| 9 | * The VAvailability component. |
| 10 | * |
| 11 | * This component adds functionality to a component, specific for VAVAILABILITY |
| 12 | * components. |
| 13 | * |
| 14 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 15 | * @author Ivan Enderlin |
| 16 | * @license http://sabre.io/license/ Modified BSD License |
| 17 | */ |
| 18 | class VAvailability extends VObject\Component |
| 19 | { |
| 20 | /** |
| 21 | * Returns true or false depending on if the event falls in the specified |
| 22 | * time-range. This is used for filtering purposes. |
| 23 | * |
| 24 | * The rules used to determine if an event falls within the specified |
| 25 | * time-range is based on: |
| 26 | * |
| 27 | * https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1 |
| 28 | * |
| 29 | * @return bool |
| 30 | */ |
| 31 | public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
| 32 | { |
| 33 | list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd(); |
| 34 | |
| 35 | return |
| 36 | (is_null($effectiveStart) || $start < $effectiveEnd) && |
| 37 | (is_null($effectiveEnd) || $end > $effectiveStart) |
| 38 | ; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the 'effective start' and 'effective end' of this VAVAILABILITY |
| 43 | * component. |
| 44 | * |
| 45 | * We use the DTSTART and DTEND or DURATION to determine this. |
| 46 | * |
| 47 | * The returned value is an array containing DateTimeImmutable instances. |
| 48 | * If either the start or end is 'unbounded' its value will be null |
| 49 | * instead. |
| 50 | * |
| 51 | * @return array |
| 52 | */ |
| 53 | public function getEffectiveStartEnd() |
| 54 | { |
| 55 | $effectiveStart = null; |
| 56 | $effectiveEnd = null; |
| 57 | |
| 58 | if (isset($this->DTSTART)) { |
| 59 | $effectiveStart = $this->DTSTART->getDateTime(); |
| 60 | } |
| 61 | if (isset($this->DTEND)) { |
| 62 | $effectiveEnd = $this->DTEND->getDateTime(); |
| 63 | } elseif ($effectiveStart && isset($this->DURATION)) { |
| 64 | $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
| 65 | } |
| 66 | |
| 67 | return [$effectiveStart, $effectiveEnd]; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * A simple list of validation rules. |
| 72 | * |
| 73 | * This is simply a list of properties, and how many times they either |
| 74 | * must or must not appear. |
| 75 | * |
| 76 | * Possible values per property: |
| 77 | * * 0 - Must not appear. |
| 78 | * * 1 - Must appear exactly once. |
| 79 | * * + - Must appear at least once. |
| 80 | * * * - Can appear any number of times. |
| 81 | * * ? - May appear, but not more than once. |
| 82 | * |
| 83 | * @var array |
| 84 | */ |
| 85 | public function getValidationRules() |
| 86 | { |
| 87 | return [ |
| 88 | 'UID' => 1, |
| 89 | 'DTSTAMP' => 1, |
| 90 | |
| 91 | 'BUSYTYPE' => '?', |
| 92 | 'CLASS' => '?', |
| 93 | 'CREATED' => '?', |
| 94 | 'DESCRIPTION' => '?', |
| 95 | 'DTSTART' => '?', |
| 96 | 'LAST-MODIFIED' => '?', |
| 97 | 'ORGANIZER' => '?', |
| 98 | 'PRIORITY' => '?', |
| 99 | 'SEQUENCE' => '?', |
| 100 | 'SUMMARY' => '?', |
| 101 | 'URL' => '?', |
| 102 | 'DTEND' => '?', |
| 103 | 'DURATION' => '?', |
| 104 | |
| 105 | 'CATEGORIES' => '*', |
| 106 | 'COMMENT' => '*', |
| 107 | 'CONTACT' => '*', |
| 108 | ]; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Validates the node for correctness. |
| 113 | * |
| 114 | * The following options are supported: |
| 115 | * Node::REPAIR - May attempt to automatically repair the problem. |
| 116 | * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. |
| 117 | * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes. |
| 118 | * |
| 119 | * This method returns an array with detected problems. |
| 120 | * Every element has the following properties: |
| 121 | * |
| 122 | * * level - problem level. |
| 123 | * * message - A human-readable string describing the issue. |
| 124 | * * node - A reference to the problematic node. |
| 125 | * |
| 126 | * The level means: |
| 127 | * 1 - The issue was repaired (only happens if REPAIR was turned on). |
| 128 | * 2 - A warning. |
| 129 | * 3 - An error. |
| 130 | * |
| 131 | * @param int $options |
| 132 | * |
| 133 | * @return array |
| 134 | */ |
| 135 | public function validate($options = 0) |
| 136 | { |
| 137 | $result = parent::validate($options); |
| 138 | |
| 139 | if (isset($this->DTEND) && isset($this->DURATION)) { |
| 140 | $result[] = [ |
| 141 | 'level' => 3, |
| 142 | 'message' => 'DTEND and DURATION cannot both be present', |
| 143 | 'node' => $this, |
| 144 | ]; |
| 145 | } |
| 146 | |
| 147 | return $result; |
| 148 | } |
| 149 | } |
| 150 |