ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VTodo.php
Go to the documentation of this file.
1<?php
2
4
5use DateTimeInterface;
7
17class VTodo extends VObject\Component {
18
31 function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) {
32
33 $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null;
34 $duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null;
35 $due = isset($this->DUE) ? $this->DUE->getDateTime() : null;
36 $completed = isset($this->COMPLETED) ? $this->COMPLETED->getDateTime() : null;
37 $created = isset($this->CREATED) ? $this->CREATED->getDateTime() : null;
38
39 if ($dtstart) {
40 if ($duration) {
41 $effectiveEnd = $dtstart->add($duration);
42 return $start <= $effectiveEnd && $end > $dtstart;
43 } elseif ($due) {
44 return
45 ($start < $due || $start <= $dtstart) &&
46 ($end > $dtstart || $end >= $due);
47 } else {
48 return $start <= $dtstart && $end > $dtstart;
49 }
50 }
51 if ($due) {
52 return ($start < $due && $end >= $due);
53 }
54 if ($completed && $created) {
55 return
56 ($start <= $created || $start <= $completed) &&
57 ($end >= $created || $end >= $completed);
58 }
59 if ($completed) {
60 return ($start <= $completed && $end >= $completed);
61 }
62 if ($created) {
63 return ($end > $created);
64 }
65 return true;
66
67 }
68
84 function getValidationRules() {
85
86 return [
87 'UID' => 1,
88 'DTSTAMP' => 1,
89
90 'CLASS' => '?',
91 'COMPLETED' => '?',
92 'CREATED' => '?',
93 'DESCRIPTION' => '?',
94 'DTSTART' => '?',
95 'GEO' => '?',
96 'LAST-MODIFIED' => '?',
97 'LOCATION' => '?',
98 'ORGANIZER' => '?',
99 'PERCENT' => '?',
100 'PRIORITY' => '?',
101 'RECURRENCE-ID' => '?',
102 'SEQUENCE' => '?',
103 'STATUS' => '?',
104 'SUMMARY' => '?',
105 'URL' => '?',
106
107 'RRULE' => '?',
108 'DUE' => '?',
109 'DURATION' => '?',
110
111 'ATTACH' => '*',
112 'ATTENDEE' => '*',
113 'CATEGORIES' => '*',
114 'COMMENT' => '*',
115 'CONTACT' => '*',
116 'EXDATE' => '*',
117 'REQUEST-STATUS' => '*',
118 'RELATED-TO' => '*',
119 'RESOURCES' => '*',
120 'RDATE' => '*',
121 ];
122
123 }
124
147 function validate($options = 0) {
148
149 $result = parent::validate($options);
150 if (isset($this->DUE) && isset($this->DTSTART)) {
151
152 $due = $this->DUE;
153 $dtStart = $this->DTSTART;
154
155 if ($due->getValueType() !== $dtStart->getValueType()) {
156
157 $result[] = [
158 'level' => 3,
159 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART',
160 'node' => $due,
161 ];
162
163 } elseif ($due->getDateTime() < $dtStart->getDateTime()) {
164
165 $result[] = [
166 'level' => 3,
167 'message' => 'DUE must occur after DTSTART',
168 'node' => $due,
169 ];
170
171 }
172
173 }
174
175 return $result;
176
177 }
178
184 protected function getDefaults() {
185
186 return [
187 'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
188 'DTSTAMP' => date('Ymd\\THis\\Z'),
189 ];
190
191 }
192
193}
$result
const COMPLETED
An exception for terminatinating execution or to throw for unit testing.
VTodo component.
Definition: VTodo.php:17
isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
Returns true or false depending on if the event falls in the specified time-range.
Definition: VTodo.php:31
getDefaults()
This method should return a list of default property values.
Definition: VTodo.php:184
validate($options=0)
Validates the node for correctness.
Definition: VTodo.php:147
static parseDuration($duration, $asString=false)
Parses an iCalendar (RFC5545) formatted duration value.
static getUUID()
Returns a pseudo-random v4 UUID.
Definition: UUIDUtil.php:27
$start
Definition: bench.php:8