Mercurial > hg > rc1
comparison vendor/sabre/vobject/lib/Component/VEvent.php @ 7:430dbd5346f7
vendor sabre as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 09:06:10 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 6:cec75ba50afc | 7:430dbd5346f7 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject\Component; | |
| 4 | |
| 5 use Sabre\VObject; | |
| 6 use Sabre\VObject\Recur\EventIterator; | |
| 7 | |
| 8 /** | |
| 9 * VEvent component | |
| 10 * | |
| 11 * This component contains some additional functionality specific for VEVENT's. | |
| 12 * | |
| 13 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/). | |
| 14 * @author Evert Pot (http://evertpot.com/) | |
| 15 * @license http://sabre.io/license/ Modified BSD License | |
| 16 */ | |
| 17 class VEvent extends VObject\Component { | |
| 18 | |
| 19 /** | |
| 20 * Returns true or false depending on if the event falls in the specified | |
| 21 * time-range. This is used for filtering purposes. | |
| 22 * | |
| 23 * The rules used to determine if an event falls within the specified | |
| 24 * time-range is based on the CalDAV specification. | |
| 25 * | |
| 26 * @param \DateTime $start | |
| 27 * @param \DateTime $end | |
| 28 * @return bool | |
| 29 */ | |
| 30 public function isInTimeRange(\DateTime $start, \DateTime $end) { | |
| 31 | |
| 32 if ($this->RRULE) { | |
| 33 $it = new EventIterator($this); | |
| 34 $it->fastForward($start); | |
| 35 | |
| 36 // We fast-forwarded to a spot where the end-time of the | |
| 37 // recurrence instance exceeded the start of the requested | |
| 38 // time-range. | |
| 39 // | |
| 40 // If the starttime of the recurrence did not exceed the | |
| 41 // end of the time range as well, we have a match. | |
| 42 return ($it->getDTStart() < $end && $it->getDTEnd() > $start); | |
| 43 | |
| 44 } | |
| 45 | |
| 46 $effectiveStart = $this->DTSTART->getDateTime(); | |
| 47 if (isset($this->DTEND)) { | |
| 48 | |
| 49 // The DTEND property is considered non inclusive. So for a 3 day | |
| 50 // event in july, dtstart and dtend would have to be July 1st and | |
| 51 // July 4th respectively. | |
| 52 // | |
| 53 // See: | |
| 54 // http://tools.ietf.org/html/rfc5545#page-54 | |
| 55 $effectiveEnd = $this->DTEND->getDateTime(); | |
| 56 | |
| 57 } elseif (isset($this->DURATION)) { | |
| 58 $effectiveEnd = clone $effectiveStart; | |
| 59 $effectiveEnd->add(VObject\DateTimeParser::parseDuration($this->DURATION)); | |
| 60 } elseif (!$this->DTSTART->hasTime()) { | |
| 61 $effectiveEnd = clone $effectiveStart; | |
| 62 $effectiveEnd->modify('+1 day'); | |
| 63 } else { | |
| 64 $effectiveEnd = clone $effectiveStart; | |
| 65 } | |
| 66 return ( | |
| 67 ($start <= $effectiveEnd) && ($end > $effectiveStart) | |
| 68 ); | |
| 69 | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * This method should return a list of default property values. | |
| 74 * | |
| 75 * @return array | |
| 76 */ | |
| 77 protected function getDefaults() { | |
| 78 | |
| 79 return array( | |
| 80 'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(), | |
| 81 'DTSTAMP' => date('Ymd\\THis\\Z'), | |
| 82 ); | |
| 83 | |
| 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 * | |
| 99 * @var array | |
| 100 */ | |
| 101 public function getValidationRules() { | |
| 102 | |
| 103 $hasMethod = isset($this->parent->METHOD); | |
| 104 return array( | |
| 105 'UID' => 1, | |
| 106 'DTSTAMP' => 1, | |
| 107 'DTSTART' => $hasMethod?'?':'1', | |
| 108 'CLASS' => '?', | |
| 109 'CREATED' => '?', | |
| 110 'DESCRIPTION' => '?', | |
| 111 'GEO' => '?', | |
| 112 'LAST-MODIFICATION' => '?', | |
| 113 'LOCATION' => '?', | |
| 114 'ORGANIZER' => '?', | |
| 115 'PRIORITY' => '?', | |
| 116 'SEQUENCE' => '?', | |
| 117 'STATUS' => '?', | |
| 118 'SUMMARY' => '?', | |
| 119 'TRANSP' => '?', | |
| 120 'URL' => '?', | |
| 121 'RECURRENCE-ID' => '?', | |
| 122 'RRULE' => '?', | |
| 123 'DTEND' => '?', | |
| 124 'DURATION' => '?', | |
| 125 | |
| 126 'ATTACH' => '*', | |
| 127 'ATTENDEE' => '*', | |
| 128 'CATEGORIES' => '*', | |
| 129 'COMMENT' => '*', | |
| 130 'CONTACT' => '*', | |
| 131 'EXDATE' => '*', | |
| 132 'REQUEST-STATUS' => '*', | |
| 133 'RELATED-TO' => '*', | |
| 134 'RESOURCES' => '*', | |
| 135 'RDATE' => '*', | |
| 136 ); | |
| 137 | |
| 138 } | |
| 139 | |
| 140 } |
