annotate vendor/sabre/vobject/lib/FreeBusyGenerator.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use DateTimeZone;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 use Sabre\VObject\Component\VCalendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 use Sabre\VObject\Recur\EventIterator;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * This class helps with generating FREEBUSY reports based on existing sets of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * objects.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * It only looks at VEVENT and VFREEBUSY objects from the sourcedata, and
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * generates a single VFREEBUSY object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * VFREEBUSY components are described in RFC5545, The rules for what should
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * go in a single freebusy report is taken from RFC4791, section 7.10.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 class FreeBusyGenerator {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 * Input objects
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 protected $objects;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 * Start of range
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 * @var DateTime|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 protected $start;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 * End of range
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 * @var DateTime|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 protected $end;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 * VCALENDAR object
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 * @var Component
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 protected $baseObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 * Reference timezone.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 * When we are calculating busy times, and we come across so-called
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 * floating times (times without a timezone), we use the reference timezone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 * instead.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 * This is also used for all-day events.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * This defaults to UTC.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 * @var DateTimeZone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 protected $timeZone;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 * Creates the generator.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 * Check the setTimeRange and setObjects methods for details about the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 * arguments.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 * @param DateTime $start
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 * @param DateTime $end
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 * @param mixed $objects
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 * @param DateTimeZone $timeZone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 public function __construct(\DateTime $start = null, \DateTime $end = null, $objects = null, DateTimeZone $timeZone = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 if ($start && $end) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 $this->setTimeRange($start, $end);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 if ($objects) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 $this->setObjects($objects);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 if (is_null($timeZone)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 $timeZone = new DateTimeZone('UTC');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 $this->setTimeZone($timeZone);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 * Sets the VCALENDAR object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 * If this is set, it will not be generated for you. You are responsible
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 * for setting things like the METHOD, CALSCALE, VERSION, etc..
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 * The VFREEBUSY object will be automatically added though.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 * @param Component $vcalendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 public function setBaseObject(Component $vcalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 $this->baseObject = $vcalendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 * Sets the input objects
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 * You must either specify a valendar object as a strong, or as the parse
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 * Component.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 * It's also possible to specify multiple objects as an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 * @param mixed $objects
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 public function setObjects($objects) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 if (!is_array($objects)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 $objects = array($objects);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 $this->objects = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 foreach($objects as $object) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 if (is_string($object)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 $this->objects[] = Reader::read($object);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134 } elseif ($object instanceof Component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 $this->objects[] = $object;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 * Sets the time range
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 * Any freebusy object falling outside of this time range will be ignored.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 * @param DateTime $start
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 * @param DateTime $end
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 public function setTimeRange(\DateTime $start = null, \DateTime $end = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 $this->start = $start;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 $this->end = $end;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 * Sets the reference timezone for floating times.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 * @param DateTimeZone $timeZone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 public function setTimeZone(DateTimeZone $timeZone) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 $this->timeZone = $timeZone;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 * Parses the input data and returns a correct VFREEBUSY object, wrapped in
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 * a VCALENDAR.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 * @return Component
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 public function getResult() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 $busyTimes = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 foreach($this->objects as $object) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 foreach($object->getBaseComponents() as $component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 switch($component->name) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 case 'VEVENT' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 $FBTYPE = 'BUSY';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 if (isset($component->TRANSP) && (strtoupper($component->TRANSP) === 'TRANSPARENT')) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 if (isset($component->STATUS)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 $status = strtoupper($component->STATUS);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 if ($status==='CANCELLED') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 if ($status==='TENTATIVE') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 $FBTYPE = 'BUSY-TENTATIVE';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 $times = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 if ($component->RRULE) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 $iterator = new EventIterator($object, (string)$component->uid, $this->timeZone);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 if ($this->start) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 $iterator->fastForward($this->start);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 $maxRecurrences = 200;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 while($iterator->valid() && --$maxRecurrences) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 $startTime = $iterator->getDTStart();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 if ($this->end && $startTime > $this->end) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 $times[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 $iterator->getDTStart(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 $iterator->getDTEnd(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 $iterator->next();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 $startTime = $component->DTSTART->getDateTime($this->timeZone);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 if ($this->end && $startTime > $this->end) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 $endTime = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 if (isset($component->DTEND)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 $endTime = $component->DTEND->getDateTime($this->timeZone);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 } elseif (isset($component->DURATION)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 $duration = DateTimeParser::parseDuration((string)$component->DURATION);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 $endTime = clone $startTime;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 $endTime->add($duration);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 } elseif (!$component->DTSTART->hasTime()) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 $endTime = clone $startTime;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 $endTime->modify('+1 day');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 // The event had no duration (0 seconds)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 $times[] = array($startTime, $endTime);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 foreach($times as $time) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 if ($this->end && $time[0] > $this->end) break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 if ($this->start && $time[1] < $this->start) break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 $busyTimes[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 $time[0],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 $time[1],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 $FBTYPE,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 case 'VFREEBUSY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 foreach($component->FREEBUSY as $freebusy) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 $fbType = isset($freebusy['FBTYPE'])?strtoupper($freebusy['FBTYPE']):'BUSY';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 // Skipping intervals marked as 'free'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 if ($fbType==='FREE')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 $values = explode(',', $freebusy);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 foreach($values as $value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 list($startTime, $endTime) = explode('/', $value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 $startTime = DateTimeParser::parseDateTime($startTime);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 if (substr($endTime,0,1)==='P' || substr($endTime,0,2)==='-P') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 $duration = DateTimeParser::parseDuration($endTime);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 $endTime = clone $startTime;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 $endTime->add($duration);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 $endTime = DateTimeParser::parseDateTime($endTime);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 if($this->start && $this->start > $endTime) continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 if($this->end && $this->end < $startTime) continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 $busyTimes[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 $startTime,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 $endTime,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 $fbType
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 if ($this->baseObject) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 $calendar = $this->baseObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 $vfreebusy = $calendar->createComponent('VFREEBUSY');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 $calendar->add($vfreebusy);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 if ($this->start) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 $dtstart = $calendar->createProperty('DTSTART');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 $dtstart->setDateTime($this->start);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 $vfreebusy->add($dtstart);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 if ($this->end) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 $dtend = $calendar->createProperty('DTEND');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 $dtend->setDateTime($this->end);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 $vfreebusy->add($dtend);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 $dtstamp = $calendar->createProperty('DTSTAMP');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 $dtstamp->setDateTime(new \DateTime('now', new \DateTimeZone('UTC')));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 $vfreebusy->add($dtstamp);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336 foreach($busyTimes as $busyTime) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 $busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 $busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 $prop = $calendar->createProperty(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 'FREEBUSY',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345 $prop['FBTYPE'] = $busyTime[2];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 $vfreebusy->add($prop);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 return $calendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355