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
VTodo.php
182 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject\Component; |
| 4 | |
| 5 | use DateTimeInterface; |
| 6 | use AmeliaVendor\Sabre\VObject; |
| 7 | |
| 8 | /** |
| 9 | * VTodo component. |
| 10 | * |
| 11 | * This component contains some additional functionality specific for VTODOs. |
| 12 | * |
| 13 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 14 | * @author Evert Pot (http://evertpot.com/) |
| 15 | * @license http://sabre.io/license/ Modified BSD License |
| 16 | */ |
| 17 | class VTodo 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 | * @return bool |
| 27 | */ |
| 28 | public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) |
| 29 | { |
| 30 | $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; |
| 31 | $duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null; |
| 32 | $due = isset($this->DUE) ? $this->DUE->getDateTime() : null; |
| 33 | $completed = isset($this->COMPLETED) ? $this->COMPLETED->getDateTime() : null; |
| 34 | $created = isset($this->CREATED) ? $this->CREATED->getDateTime() : null; |
| 35 | |
| 36 | if ($dtstart) { |
| 37 | if ($duration) { |
| 38 | $effectiveEnd = $dtstart->add($duration); |
| 39 | |
| 40 | return $start <= $effectiveEnd && $end > $dtstart; |
| 41 | } elseif ($due) { |
| 42 | return |
| 43 | ($start < $due || $start <= $dtstart) && |
| 44 | ($end > $dtstart || $end >= $due); |
| 45 | } else { |
| 46 | return $start <= $dtstart && $end > $dtstart; |
| 47 | } |
| 48 | } |
| 49 | if ($due) { |
| 50 | return $start < $due && $end >= $due; |
| 51 | } |
| 52 | if ($completed && $created) { |
| 53 | return |
| 54 | ($start <= $created || $start <= $completed) && |
| 55 | ($end >= $created || $end >= $completed); |
| 56 | } |
| 57 | if ($completed) { |
| 58 | return $start <= $completed && $end >= $completed; |
| 59 | } |
| 60 | if ($created) { |
| 61 | return $end > $created; |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * A simple list of validation rules. |
| 69 | * |
| 70 | * This is simply a list of properties, and how many times they either |
| 71 | * must or must not appear. |
| 72 | * |
| 73 | * Possible values per property: |
| 74 | * * 0 - Must not appear. |
| 75 | * * 1 - Must appear exactly once. |
| 76 | * * + - Must appear at least once. |
| 77 | * * * - Can appear any number of times. |
| 78 | * * ? - May appear, but not more than once. |
| 79 | * |
| 80 | * @var array |
| 81 | */ |
| 82 | public function getValidationRules() |
| 83 | { |
| 84 | return [ |
| 85 | 'UID' => 1, |
| 86 | 'DTSTAMP' => 1, |
| 87 | |
| 88 | 'CLASS' => '?', |
| 89 | 'COMPLETED' => '?', |
| 90 | 'CREATED' => '?', |
| 91 | 'DESCRIPTION' => '?', |
| 92 | 'DTSTART' => '?', |
| 93 | 'GEO' => '?', |
| 94 | 'LAST-MODIFIED' => '?', |
| 95 | 'LOCATION' => '?', |
| 96 | 'ORGANIZER' => '?', |
| 97 | 'PERCENT' => '?', |
| 98 | 'PRIORITY' => '?', |
| 99 | 'RECURRENCE-ID' => '?', |
| 100 | 'SEQUENCE' => '?', |
| 101 | 'STATUS' => '?', |
| 102 | 'SUMMARY' => '?', |
| 103 | 'URL' => '?', |
| 104 | |
| 105 | 'RRULE' => '?', |
| 106 | 'DUE' => '?', |
| 107 | 'DURATION' => '?', |
| 108 | |
| 109 | 'ATTACH' => '*', |
| 110 | 'ATTENDEE' => '*', |
| 111 | 'CATEGORIES' => '*', |
| 112 | 'COMMENT' => '*', |
| 113 | 'CONTACT' => '*', |
| 114 | 'EXDATE' => '*', |
| 115 | 'REQUEST-STATUS' => '*', |
| 116 | 'RELATED-TO' => '*', |
| 117 | 'RESOURCES' => '*', |
| 118 | 'RDATE' => '*', |
| 119 | ]; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Validates the node for correctness. |
| 124 | * |
| 125 | * The following options are supported: |
| 126 | * Node::REPAIR - May attempt to automatically repair the problem. |
| 127 | * |
| 128 | * This method returns an array with detected problems. |
| 129 | * Every element has the following properties: |
| 130 | * |
| 131 | * * level - problem level. |
| 132 | * * message - A human-readable string describing the issue. |
| 133 | * * node - A reference to the problematic node. |
| 134 | * |
| 135 | * The level means: |
| 136 | * 1 - The issue was repaired (only happens if REPAIR was turned on) |
| 137 | * 2 - An inconsequential issue |
| 138 | * 3 - A severe issue. |
| 139 | * |
| 140 | * @param int $options |
| 141 | * |
| 142 | * @return array |
| 143 | */ |
| 144 | public function validate($options = 0) |
| 145 | { |
| 146 | $result = parent::validate($options); |
| 147 | if (isset($this->DUE) && isset($this->DTSTART)) { |
| 148 | $due = $this->DUE; |
| 149 | $dtStart = $this->DTSTART; |
| 150 | |
| 151 | if ($due->getValueType() !== $dtStart->getValueType()) { |
| 152 | $result[] = [ |
| 153 | 'level' => 3, |
| 154 | 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', |
| 155 | 'node' => $due, |
| 156 | ]; |
| 157 | } elseif ($due->getDateTime() < $dtStart->getDateTime()) { |
| 158 | $result[] = [ |
| 159 | 'level' => 3, |
| 160 | 'message' => 'DUE must occur after DTSTART', |
| 161 | 'node' => $due, |
| 162 | ]; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return $result; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * This method should return a list of default property values. |
| 171 | * |
| 172 | * @return array |
| 173 | */ |
| 174 | protected function getDefaults() |
| 175 | { |
| 176 | return [ |
| 177 | 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), |
| 178 | 'DTSTAMP' => date('Ymd\\THis\\Z'), |
| 179 | ]; |
| 180 | } |
| 181 | } |
| 182 |