comparison vendor/sabre/vobject/lib/Component/VTodo.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
7 /**
8 * VTodo component
9 *
10 * This component contains some additional functionality specific for VTODOs.
11 *
12 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
13 * @author Evert Pot (http://evertpot.com/)
14 * @license http://sabre.io/license/ Modified BSD License
15 */
16 class VTodo extends VObject\Component {
17
18 /**
19 * Returns true or false depending on if the event falls in the specified
20 * time-range. This is used for filtering purposes.
21 *
22 * The rules used to determine if an event falls within the specified
23 * time-range is based on the CalDAV specification.
24 *
25 * @param DateTime $start
26 * @param DateTime $end
27 * @return bool
28 */
29 public function isInTimeRange(\DateTime $start, \DateTime $end) {
30
31 $dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
32 $duration = isset($this->DURATION)?VObject\DateTimeParser::parseDuration($this->DURATION):null;
33 $due = isset($this->DUE)?$this->DUE->getDateTime():null;
34 $completed = isset($this->COMPLETED)?$this->COMPLETED->getDateTime():null;
35 $created = isset($this->CREATED)?$this->CREATED->getDateTime():null;
36
37 if ($dtstart) {
38 if ($duration) {
39 $effectiveEnd = clone $dtstart;
40 $effectiveEnd->add($duration);
41 return $start <= $effectiveEnd && $end > $dtstart;
42 } elseif ($due) {
43 return
44 ($start < $due || $start <= $dtstart) &&
45 ($end > $dtstart || $end >= $due);
46 } else {
47 return $start <= $dtstart && $end > $dtstart;
48 }
49 }
50 if ($due) {
51 return ($start < $due && $end >= $due);
52 }
53 if ($completed && $created) {
54 return
55 ($start <= $created || $start <= $completed) &&
56 ($end >= $created || $end >= $completed);
57 }
58 if ($completed) {
59 return ($start <= $completed && $end >= $completed);
60 }
61 if ($created) {
62 return ($end > $created);
63 }
64 return true;
65
66 }
67
68 /**
69 * A simple list of validation rules.
70 *
71 * This is simply a list of properties, and how many times they either
72 * must or must not appear.
73 *
74 * Possible values per property:
75 * * 0 - Must not appear.
76 * * 1 - Must appear exactly once.
77 * * + - Must appear at least once.
78 * * * - Can appear any number of times.
79 *
80 * @var array
81 */
82 public function getValidationRules() {
83
84 return array(
85 'UID' => 1,
86 'DTSTAMP' => 1,
87
88 'CLASS' => '?',
89 'COMPLETED' => '?',
90 'CREATED' => '?',
91 'DESCRIPTION' => '?',
92 'DTSTART' => '?',
93 'GEO' => '?',
94 'LAST-MODIFICATION' => '?',
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 /**
124 * Validates the node for correctness.
125 *
126 * The following options are supported:
127 * Node::REPAIR - May attempt to automatically repair the problem.
128 *
129 * This method returns an array with detected problems.
130 * Every element has the following properties:
131 *
132 * * level - problem level.
133 * * message - A human-readable string describing the issue.
134 * * node - A reference to the problematic node.
135 *
136 * The level means:
137 * 1 - The issue was repaired (only happens if REPAIR was turned on)
138 * 2 - An inconsequential issue
139 * 3 - A severe issue.
140 *
141 * @param int $options
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
149 $due = $this->DUE;
150 $dtStart = $this->DTSTART;
151
152 if ($due->getValueType() !== $dtStart->getValueType()) {
153
154 $result[] = array(
155 'level' => 3,
156 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART',
157 'node' => $due,
158 );
159
160 } elseif ($due->getDateTime() < $dtStart->getDateTime()) {
161
162 $result[] = array(
163 'level' => 3,
164 'message' => 'DUE must occur after DTSTART',
165 'node' => $due,
166 );
167
168 }
169
170 }
171
172 return $result;
173
174 }
175
176 }