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
VEvent.php
141 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject\Component; |
| 4 | |
| 5 | use DateTimeInterface; |
| 6 | use AmeliaVendor\Sabre\VObject; |
| 7 | use AmeliaVendor\Sabre\VObject\Recur\EventIterator; |
| 8 | use AmeliaVendor\Sabre\VObject\Recur\NoInstancesException; |
| 9 | |
| 10 | /** |
| 11 | * VEvent component. |
| 12 | * |
| 13 | * This component contains some additional functionality specific for VEVENT's. |
| 14 | * |
| 15 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 16 | * @author Evert Pot (http://evertpot.com/) |
| 17 | * @license http://sabre.io/license/ Modified BSD License |
| 18 | */ |
| 19 | class VEvent extends VObject\Component |
| 20 | { |
| 21 | /** |
| 22 | * Returns true or false depending on if the event falls in the specified |
| 23 | * time-range. This is used for filtering purposes. |
| 24 | * |
| 25 | * The rules used to determine if an event falls within the specified |
| 26 | * time-range is based on the CalDAV specification. |
| 27 | * |
| 28 | * @return bool |
| 29 | */ |
| 30 | public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
| 31 | { |
| 32 | if ($this->RRULE) { |
| 33 | try { |
| 34 | $it = new EventIterator($this, null, $start->getTimezone()); |
| 35 | } catch (NoInstancesException $e) { |
| 36 | // If we've caught this exception, there are no instances |
| 37 | // for the event that fall into the specified time-range. |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | $it->fastForward($start); |
| 42 | |
| 43 | // We fast-forwarded to a spot where the end-time of the |
| 44 | // recurrence instance exceeded the start of the requested |
| 45 | // time-range. |
| 46 | // |
| 47 | // If the starttime of the recurrence did not exceed the |
| 48 | // end of the time range as well, we have a match. |
| 49 | return $it->getDTStart() < $end && $it->getDTEnd() > $start; |
| 50 | } |
| 51 | |
| 52 | $effectiveStart = $this->DTSTART->getDateTime($start->getTimezone()); |
| 53 | if (isset($this->DTEND)) { |
| 54 | // The DTEND property is considered non inclusive. So for a 3 day |
| 55 | // event in july, dtstart and dtend would have to be July 1st and |
| 56 | // July 4th respectively. |
| 57 | // |
| 58 | // See: |
| 59 | // http://tools.ietf.org/html/rfc5545#page-54 |
| 60 | $effectiveEnd = $this->DTEND->getDateTime($end->getTimezone()); |
| 61 | } elseif (isset($this->DURATION)) { |
| 62 | $effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION)); |
| 63 | } elseif (!$this->DTSTART->hasTime()) { |
| 64 | $effectiveEnd = $effectiveStart->modify('+1 day'); |
| 65 | } else { |
| 66 | $effectiveEnd = $effectiveStart; |
| 67 | } |
| 68 | |
| 69 | return |
| 70 | ($start < $effectiveEnd) && ($end > $effectiveStart) |
| 71 | ; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * This method should return a list of default property values. |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | protected function getDefaults() |
| 80 | { |
| 81 | return [ |
| 82 | 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
| 83 | 'DTSTAMP' => gmdate('Ymd\\THis\\Z'), |
| 84 | ]; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * A simple list of validation rules. |
| 89 | * |
| 90 | * This is simply a list of properties, and how many times they either |
| 91 | * must or must not appear. |
| 92 | * |
| 93 | * Possible values per property: |
| 94 | * * 0 - Must not appear. |
| 95 | * * 1 - Must appear exactly once. |
| 96 | * * + - Must appear at least once. |
| 97 | * * * - Can appear any number of times. |
| 98 | * * ? - May appear, but not more than once. |
| 99 | * |
| 100 | * @var array |
| 101 | */ |
| 102 | public function getValidationRules() |
| 103 | { |
| 104 | $hasMethod = isset($this->parent->METHOD); |
| 105 | |
| 106 | return [ |
| 107 | 'UID' => 1, |
| 108 | 'DTSTAMP' => 1, |
| 109 | 'DTSTART' => $hasMethod ? '?' : '1', |
| 110 | 'CLASS' => '?', |
| 111 | 'CREATED' => '?', |
| 112 | 'DESCRIPTION' => '?', |
| 113 | 'GEO' => '?', |
| 114 | 'LAST-MODIFIED' => '?', |
| 115 | 'LOCATION' => '?', |
| 116 | 'ORGANIZER' => '?', |
| 117 | 'PRIORITY' => '?', |
| 118 | 'SEQUENCE' => '?', |
| 119 | 'STATUS' => '?', |
| 120 | 'SUMMARY' => '?', |
| 121 | 'TRANSP' => '?', |
| 122 | 'URL' => '?', |
| 123 | 'RECURRENCE-ID' => '?', |
| 124 | 'RRULE' => '?', |
| 125 | 'DTEND' => '?', |
| 126 | 'DURATION' => '?', |
| 127 | |
| 128 | 'ATTACH' => '*', |
| 129 | 'ATTENDEE' => '*', |
| 130 | 'CATEGORIES' => '*', |
| 131 | 'COMMENT' => '*', |
| 132 | 'CONTACT' => '*', |
| 133 | 'EXDATE' => '*', |
| 134 | 'REQUEST-STATUS' => '*', |
| 135 | 'RELATED-TO' => '*', |
| 136 | 'RESOURCES' => '*', |
| 137 | 'RDATE' => '*', |
| 138 | ]; |
| 139 | } |
| 140 | } |
| 141 |