annotate vendor/sabre/vobject/lib/ITip/Broker.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 430dbd5346f7
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\ITip;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject\Component\VCalendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 use Sabre\VObject\DateTimeParser;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 use Sabre\VObject\Reader;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 use Sabre\VObject\Recur\EventIterator;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * The ITip\Broker class is a utility class that helps with processing
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * so-called iTip messages.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * iTip is defined in rfc5546, stands for iCalendar Transport-Independent
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 * Interoperability Protocol, and describes the underlying mechanism for
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * using iCalendar for scheduling for for example through email (also known as
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * IMip) and CalDAV Scheduling.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 * This class helps by:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 * 1. Creating individual invites based on an iCalendar event for each
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 * attendee.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * 2. Generating invite updates based on an iCalendar update. This may result
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 * in new invites, updates and cancellations for attendees, if that list
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 * changed.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 * 3. On the receiving end, it can create a local iCalendar event based on
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 * a received invite.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 * 4. It can also process an invite update on a local event, ensuring that any
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 * overridden properties from attendees are retained.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 * 5. It can create a accepted or declined iTip reply based on an invite.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 * 6. It can process a reply from an invite and update an events attendee
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 * status based on a reply.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 class Broker {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 * This setting determines whether the rules for the SCHEDULE-AGENT
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 * parameter should be followed.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 * This is a parameter defined on ATTENDEE properties, introduced by RFC
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 * 6638. This parameter allows a caldav client to tell the server 'Don't do
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 * any scheduling operations'.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 * If this setting is turned on, any attendees with SCHEDULE-AGENT set to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 * CLIENT will be ignored. This is the desired behavior for a CalDAV
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 * server, but if you're writing an iTip application that doesn't deal with
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 * CalDAV, you may want to ignore this parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 * @var bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 public $scheduleAgentServerRules = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 * The broker will try during 'parseEvent' figure out whether the change
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 * was significant.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 * It uses a few different ways to do this. One of these ways is seeing if
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * certain properties changed values. This list of specified here.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 * This list is taken from:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 * * http://tools.ietf.org/html/rfc5546#section-2.1.4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 * @var string[]
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 public $significantChangeProperties = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 'DTSTART',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 'DTEND',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 'DURATION',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 'DUE',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 'RRULE',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 'RDATE',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 'EXDATE',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 'STATUS',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 * This method is used to process an incoming itip message.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 * Examples:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 * 1. A user is an attendee to an event. The organizer sends an updated
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 * meeting using a new iTip message with METHOD:REQUEST. This function
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 * will process the message and update the attendee's event accordingly.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 * 2. The organizer cancelled the event using METHOD:CANCEL. We will update
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 * the users event to state STATUS:CANCELLED.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 * 3. An attendee sent a reply to an invite using METHOD:REPLY. We can
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 * update the organizers event to update the ATTENDEE with its correct
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 * PARTSTAT.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 * The $existingObject is updated in-place. If there is no existing object
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 * (because it's a new invite for example) a new object will be created.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 * If an existing object does not exist, and the method was CANCEL or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 * REPLY, the message effectively gets ignored, and no 'existingObject'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 * will be created.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 * The updated $existingObject is also returned from this function.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 * If the iTip message was not supported, we will always return false.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 * @param Message $itipMessage
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 * @param VCalendar $existingObject
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 * @return VCalendar|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 public function processMessage(Message $itipMessage, VCalendar $existingObject = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 // We only support events at the moment.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 if ($itipMessage->component !== 'VEVENT') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 return false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 switch($itipMessage->method) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 case 'REQUEST' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 return $this->processMessageRequest($itipMessage, $existingObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 case 'CANCEL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 return $this->processMessageCancel($itipMessage, $existingObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 case 'REPLY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 return $this->processMessageReply($itipMessage, $existingObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 default :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 // Unsupported iTip message
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 return $existingObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 }
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 * This function parses a VCALENDAR object and figure out if any messages
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 * need to be sent.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 * A VCALENDAR object will be created from the perspective of either an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 * attendee, or an organizer. You must pass a string identifying the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 * current user, so we can figure out who in the list of attendees or the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 * organizer we are sending this message on behalf of.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 * It's possible to specify the current user as an array, in case the user
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 * has more than one identifying href (such as multiple emails).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 * It $oldCalendar is specified, it is assumed that the operation is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 * updating an existing event, which means that we need to look at the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 * differences between events, and potentially send old attendees
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 * cancellations, and current attendees updates.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 * If $calendar is null, but $oldCalendar is specified, we treat the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 * operation as if the user has deleted an event. If the user was an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 * organizer, this means that we need to send cancellation notices to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 * people. If the user was an attendee, we need to make sure that the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 * organizer gets the 'declined' message.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 * @param VCalendar|string $calendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 * @param string|array $userHref
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 * @param VCalendar|string $oldCalendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 public function parseEvent($calendar = null, $userHref, $oldCalendar = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 if ($oldCalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 if (is_string($oldCalendar)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 $oldCalendar = Reader::read($oldCalendar);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 if (!isset($oldCalendar->VEVENT)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 // We only support events at the moment
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 $oldEventInfo = $this->parseEventInfo($oldCalendar);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 $oldEventInfo = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 'organizer' => null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 'significantChangeHash' => '',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 'attendees' => array(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 $userHref = (array)$userHref;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 if (!is_null($calendar)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 if (is_string($calendar)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 $calendar = Reader::read($calendar);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 if (!isset($calendar->VEVENT)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 // We only support events at the moment
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 $eventInfo = $this->parseEventInfo($calendar);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 if (!$eventInfo['attendees'] && !$oldEventInfo['attendees']) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 // If there were no attendees on either side of the equation,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 // we don't need to do anything.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 if (!$eventInfo['organizer'] && !$oldEventInfo['organizer']) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 // There was no organizer before or after the change.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 $baseCalendar = $calendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 // If the new object didn't have an organizer, the organizer
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 // changed the object from a scheduling object to a non-scheduling
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 // object. We just copy the info from the old object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 if (!$eventInfo['organizer'] && $oldEventInfo['organizer']) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 $eventInfo['organizer'] = $oldEventInfo['organizer'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 $eventInfo['organizerName'] = $oldEventInfo['organizerName'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 // The calendar object got deleted, we need to process this as a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 // cancellation / decline.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 if (!$oldCalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 // No old and no new calendar, there's no thing to do.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 $eventInfo = $oldEventInfo;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 if (in_array($eventInfo['organizer'], $userHref)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 // This is an organizer deleting the event.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 $eventInfo['attendees'] = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 // Increasing the sequence, but only if the organizer deleted
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 // the event.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 $eventInfo['sequence']++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 // This is an attendee deleting the event.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 foreach($eventInfo['attendees'] as $key=>$attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 if (in_array($attendee['href'], $userHref)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 $eventInfo['attendees'][$key]['instances'] = array('master' =>
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 array('id'=>'master', 'partstat' => 'DECLINED')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 $baseCalendar = $oldCalendar;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 if (in_array($eventInfo['organizer'], $userHref)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 return $this->parseEventForOrganizer($baseCalendar, $eventInfo, $oldEventInfo);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 } elseif ($oldCalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 // We need to figure out if the user is an attendee, but we're only
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 // doing so if there's an oldCalendar, because we only want to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 // process updates, not creation of new events.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 foreach($eventInfo['attendees'] as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 if (in_array($attendee['href'], $userHref)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 }
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 * Processes incoming REQUEST messages.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 * This is message from an organizer, and is either a new event
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 * invite, or an update to an existing one.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272 * @param Message $itipMessage
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 * @param VCalendar $existingObject
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 * @return VCalendar|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 if (!$existingObject) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 // This is a new invite, and we're just going to copy over
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 // all the components from the invite.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 $existingObject = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 foreach($itipMessage->message->getComponents() as $component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 $existingObject->add(clone $component);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 // We need to update an existing object with all the new
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 // information. We can just remove all existing components
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 // and create new ones.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 foreach($existingObject->getComponents() as $component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 $existingObject->remove($component);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 foreach($itipMessage->message->getComponents() as $component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 $existingObject->add(clone $component);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 return $existingObject;
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 * Processes incoming CANCEL messages.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 * This is a message from an organizer, and means that either an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 * attendee got removed from an event, or an event got cancelled
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 * altogether.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 * @param Message $itipMessage
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 * @param VCalendar $existingObject
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 * @return VCalendar|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 if (!$existingObject) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 // The event didn't exist in the first place, so we're just
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 // ignoring this message.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 foreach($existingObject->VEVENT as $vevent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 $vevent->STATUS = 'CANCELLED';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 $vevent->SEQUENCE = $itipMessage->sequence;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 return $existingObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 * Processes incoming REPLY messages.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 * The message is a reply. This is for example an attendee telling
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 * an organizer he accepted the invite, or declined it.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 * @param Message $itipMessage
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 * @param VCalendar $existingObject
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 * @return VCalendar|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336 protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 // A reply can only be processed based on an existing object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 // If the object is not available, the reply is ignored.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 if (!$existingObject) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 $instances = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 $requestStatus = '2.0';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 // Finding all the instances the attendee replied to.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 foreach($itipMessage->message->VEVENT as $vevent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349 $attendee = $vevent->ATTENDEE;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 $instances[$recurId] = $attendee['PARTSTAT']->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351 if (isset($vevent->{'REQUEST-STATUS'})) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 $requestStatus = $vevent->{'REQUEST-STATUS'}->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353 list($requestStatus) = explode(';', $requestStatus);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357 // Now we need to loop through the original organizer event, to find
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358 // all the instances where we have a reply for.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359 $masterObject = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360 foreach($existingObject->VEVENT as $vevent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362 if ($recurId==='master') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 $masterObject = $vevent;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365 if (isset($instances[$recurId])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 $attendeeFound = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367 if (isset($vevent->ATTENDEE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368 foreach($vevent->ATTENDEE as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369 if ($attendee->getValue() === $itipMessage->sender) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370 $attendeeFound = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371 $attendee['PARTSTAT'] = $instances[$recurId];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372 $attendee['SCHEDULE-STATUS'] = $requestStatus;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373 // Un-setting the RSVP status, because we now know
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
374 // that the attende already replied.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
375 unset($attendee['RSVP']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
376 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
377 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
378 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
379 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
380 if (!$attendeeFound) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
381 // Adding a new attendee. The iTip documentation calls this
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
382 // a party crasher.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
383 $attendee = $vevent->add('ATTENDEE', $itipMessage->sender, array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
384 'PARTSTAT' => $instances[$recurId]
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
385 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
386 if ($itipMessage->senderName) $attendee['CN'] = $itipMessage->senderName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
387 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
388 unset($instances[$recurId]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
389 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
390 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
391
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
392 if(!$masterObject) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
393 // No master object, we can't add new instances.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
394 return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
395 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
396 // If we got replies to instances that did not exist in the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
397 // original list, it means that new exceptions must be created.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
398 foreach($instances as $recurId=>$partstat) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
399
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
400 $recurrenceIterator = new EventIterator($existingObject, $itipMessage->uid);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
401 $found = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
402 $iterations = 1000;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
403 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
404
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
405 $newObject = $recurrenceIterator->getEventObject();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
406 $recurrenceIterator->next();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
407
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
408 if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getValue()===$recurId) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
409 $found = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
410 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
411 $iterations--;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
412
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
413 } while($recurrenceIterator->valid() && !$found && $iterations);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
414
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
415 // Invalid recurrence id. Skipping this object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
416 if (!$found) continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
417
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
418 unset(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
419 $newObject->RRULE,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
420 $newObject->EXDATE,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
421 $newObject->RDATE
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
422 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
423 $attendeeFound = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
424 if (isset($newObject->ATTENDEE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
425 foreach($newObject->ATTENDEE as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
426 if ($attendee->getValue() === $itipMessage->sender) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
427 $attendeeFound = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
428 $attendee['PARTSTAT'] = $partstat;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
429 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
430 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
431 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
432 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
433 if (!$attendeeFound) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
434 // Adding a new attendee
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
435 $attendee = $newObject->add('ATTENDEE', $itipMessage->sender, array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
436 'PARTSTAT' => $partstat
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
437 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
438 if ($itipMessage->senderName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
439 $attendee['CN'] = $itipMessage->senderName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
440 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
441 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
442 $existingObject->add($newObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
443
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
444 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
445 return $existingObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
446
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
447 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
448
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
449 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
450 * This method is used in cases where an event got updated, and we
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
451 * potentially need to send emails to attendees to let them know of updates
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
452 * in the events.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
453 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
454 * We will detect which attendees got added, which got removed and create
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
455 * specific messages for these situations.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
456 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
457 * @param VCalendar $calendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
458 * @param array $eventInfo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
459 * @param array $oldEventInfo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
460 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
461 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
462 protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, array $oldEventInfo) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
463
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
464 // Merging attendee lists.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
465 $attendees = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
466 foreach($oldEventInfo['attendees'] as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
467 $attendees[$attendee['href']] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
468 'href' => $attendee['href'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
469 'oldInstances' => $attendee['instances'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
470 'newInstances' => array(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
471 'name' => $attendee['name'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
472 'forceSend' => null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
473 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
474 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
475 foreach($eventInfo['attendees'] as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
476 if (isset($attendees[$attendee['href']])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
477 $attendees[$attendee['href']]['name'] = $attendee['name'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
478 $attendees[$attendee['href']]['newInstances'] = $attendee['instances'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
479 $attendees[$attendee['href']]['forceSend'] = $attendee['forceSend'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
480 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
481 $attendees[$attendee['href']] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
482 'href' => $attendee['href'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
483 'oldInstances' => array(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
484 'newInstances' => $attendee['instances'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
485 'name' => $attendee['name'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
486 'forceSend' => $attendee['forceSend'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
487 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
488 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
489 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
490
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
491 $messages = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
492
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
493 foreach($attendees as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
494
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
495 // An organizer can also be an attendee. We should not generate any
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
496 // messages for those.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
497 if ($attendee['href']===$eventInfo['organizer']) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
498 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
499 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
500
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
501 $message = new Message();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
502 $message->uid = $eventInfo['uid'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
503 $message->component = 'VEVENT';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
504 $message->sequence = $eventInfo['sequence'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
505 $message->sender = $eventInfo['organizer'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
506 $message->senderName = $eventInfo['organizerName'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
507 $message->recipient = $attendee['href'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
508 $message->recipientName = $attendee['name'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
509
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
510 if (!$attendee['newInstances']) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
511
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
512 // If there are no instances the attendee is a part of, it
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
513 // means the attendee was removed and we need to send him a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
514 // CANCEL.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
515 $message->method = 'CANCEL';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
516
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
517 // Creating the new iCalendar body.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
518 $icalMsg = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
519 $icalMsg->METHOD = $message->method;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
520 $event = $icalMsg->add('VEVENT', array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
521 'UID' => $message->uid,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
522 'SEQUENCE' => $message->sequence,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
523 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
524 if (isset($calendar->VEVENT->SUMMARY)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
525 $event->add('SUMMARY', $calendar->VEVENT->SUMMARY->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
526 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
527 $event->add(clone $calendar->VEVENT->DTSTART);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
528 $org = $event->add('ORGANIZER', $eventInfo['organizer']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
529 if ($eventInfo['organizerName']) $org['CN'] = $eventInfo['organizerName'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
530 $event->add('ATTENDEE', $attendee['href'], array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
531 'CN' => $attendee['name'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
532 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
533 $message->significantChange = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
534
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
535 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
536
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
537 // The attendee gets the updated event body
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
538 $message->method = 'REQUEST';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
539
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
540 // Creating the new iCalendar body.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
541 $icalMsg = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
542 $icalMsg->METHOD = $message->method;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
543
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
544 foreach($calendar->select('VTIMEZONE') as $timezone) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
545 $icalMsg->add(clone $timezone);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
546 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
547
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
548 // We need to find out that this change is significant. If it's
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
549 // not, systems may opt to not send messages.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
550 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
551 // We do this based on the 'significantChangeHash' which is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
552 // some value that changes if there's a certain set of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
553 // properties changed in the event, or simply if there's a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
554 // difference in instances that the attendee is invited to.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
555
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
556 $message->significantChange =
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
557 $attendee['forceSend'] === 'REQUEST' ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
558 array_keys($attendee['oldInstances']) != array_keys($attendee['newInstances']) ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
559 $oldEventInfo['significantChangeHash']!==$eventInfo['significantChangeHash'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
560
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
561 foreach($attendee['newInstances'] as $instanceId => $instanceInfo) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
562
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
563 $currentEvent = clone $eventInfo['instances'][$instanceId];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
564 if ($instanceId === 'master') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
565
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
566 // We need to find a list of events that the attendee
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
567 // is not a part of to add to the list of exceptions.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
568 $exceptions = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
569 foreach($eventInfo['instances'] as $instanceId=>$vevent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
570 if (!isset($attendee['newInstances'][$instanceId])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
571 $exceptions[] = $instanceId;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
572 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
573 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
574
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
575 // If there were exceptions, we need to add it to an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
576 // existing EXDATE property, if it exists.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
577 if ($exceptions) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
578 if (isset($currentEvent->EXDATE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
579 $currentEvent->EXDATE->setParts(array_merge(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
580 $currentEvent->EXDATE->getParts(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
581 $exceptions
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
582 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
583 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
584 $currentEvent->EXDATE = $exceptions;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
585 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
586 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
587
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
588 // Cleaning up any scheduling information that
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
589 // shouldn't be sent along.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
590 unset($currentEvent->ORGANIZER['SCHEDULE-FORCE-SEND']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
591 unset($currentEvent->ORGANIZER['SCHEDULE-STATUS']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
592
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
593 foreach($currentEvent->ATTENDEE as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
594 unset($attendee['SCHEDULE-FORCE-SEND']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
595 unset($attendee['SCHEDULE-STATUS']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
596
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
597 // We're adding PARTSTAT=NEEDS-ACTION to ensure that
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
598 // iOS shows an "Inbox Item"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
599 if (!isset($attendee['PARTSTAT'])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
600 $attendee['PARTSTAT'] = 'NEEDS-ACTION';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
601 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
602
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
603 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
604
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
605 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
606
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
607 $icalMsg->add($currentEvent);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
608
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
609 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
610
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
611 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
612
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
613 $message->message = $icalMsg;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
614 $messages[] = $message;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
615
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
616 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
617
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
618 return $messages;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
619
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
620 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
621
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
622 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
623 * Parse an event update for an attendee.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
624 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
625 * This function figures out if we need to send a reply to an organizer.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
626 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
627 * @param VCalendar $calendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
628 * @param array $eventInfo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
629 * @param array $oldEventInfo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
630 * @param string $attendee
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
631 * @return Message[]
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
632 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
633 protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
634
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
635 if ($this->scheduleAgentServerRules && $eventInfo['organizerScheduleAgent']==='CLIENT') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
636 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
637 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
638
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
639 // Don't bother generating messages for events that have already been
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
640 // cancelled.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
641 if ($eventInfo['status']==='CANCELLED') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
642 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
643 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
644
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
645 $instances = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
646 foreach($oldEventInfo['attendees'][$attendee]['instances'] as $instance) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
647
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
648 $instances[$instance['id']] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
649 'id' => $instance['id'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
650 'oldstatus' => $instance['partstat'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
651 'newstatus' => null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
652 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
653
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
654 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
655 foreach($eventInfo['attendees'][$attendee]['instances'] as $instance) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
656
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
657 if (isset($instances[$instance['id']])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
658 $instances[$instance['id']]['newstatus'] = $instance['partstat'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
659 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
660 $instances[$instance['id']] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
661 'id' => $instance['id'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
662 'oldstatus' => null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
663 'newstatus' => $instance['partstat'],
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
664 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
665 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
666
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
667 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
668
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
669 // We need to also look for differences in EXDATE. If there are new
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
670 // items in EXDATE, it means that an attendee deleted instances of an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
671 // event, which means we need to send DECLINED specifically for those
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
672 // instances.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
673 // We only need to do that though, if the master event is not declined.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
674 if ($instances['master']['newstatus'] !== 'DECLINED') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
675 foreach($eventInfo['exdate'] as $exDate) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
676
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
677 if (!in_array($exDate, $oldEventInfo['exdate'])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
678 if (isset($instances[$exDate])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
679 $instances[$exDate]['newstatus'] = 'DECLINED';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
680 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
681 $instances[$exDate] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
682 'id' => $exDate,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
683 'oldstatus' => null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
684 'newstatus' => 'DECLINED',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
685 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
686 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
687 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
688
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
689 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
690 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
691
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
692 // Gathering a few extra properties for each instance.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
693 foreach($instances as $recurId=>$instanceInfo) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
694
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
695 if (isset($eventInfo['instances'][$recurId])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
696 $instances[$recurId]['dtstart'] = clone $eventInfo['instances'][$recurId]->DTSTART;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
697 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
698 $instances[$recurId]['dtstart'] = $recurId;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
699 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
700
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
701 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
702
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
703 $message = new Message();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
704 $message->uid = $eventInfo['uid'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
705 $message->method = 'REPLY';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
706 $message->component = 'VEVENT';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
707 $message->sequence = $eventInfo['sequence'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
708 $message->sender = $attendee;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
709 $message->senderName = $eventInfo['attendees'][$attendee]['name'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
710 $message->recipient = $eventInfo['organizer'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
711 $message->recipientName = $eventInfo['organizerName'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
712
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
713 $icalMsg = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
714 $icalMsg->METHOD = 'REPLY';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
715
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
716 $hasReply = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
717
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
718 foreach($instances as $instance) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
719
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
720 if ($instance['oldstatus']==$instance['newstatus'] && $eventInfo['organizerForceSend'] !== 'REPLY') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
721 // Skip
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
722 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
723 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
724
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
725 $event = $icalMsg->add('VEVENT', array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
726 'UID' => $message->uid,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
727 'SEQUENCE' => $message->sequence,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
728 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
729 $summary = isset($calendar->VEVENT->SUMMARY)?$calendar->VEVENT->SUMMARY->getValue():'';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
730 // Adding properties from the correct source instance
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
731 if (isset($eventInfo['instances'][$instance['id']])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
732 $instanceObj = $eventInfo['instances'][$instance['id']];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
733 $event->add(clone $instanceObj->DTSTART);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
734 if (isset($instanceObj->SUMMARY)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
735 $event->add('SUMMARY', $instanceObj->SUMMARY->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
736 } elseif ($summary) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
737 $event->add('SUMMARY', $summary);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
738 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
739 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
740 // This branch of the code is reached, when a reply is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
741 // generated for an instance of a recurring event, through the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
742 // fact that the instance has disappeared by showing up in
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
743 // EXDATE
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
744 $dt = DateTimeParser::parse($instance['id'], $eventInfo['timezone']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
745 // Treat is as a DATE field
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
746 if (strlen($instance['id']) <= 8) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
747 $recur = $event->add('DTSTART', $dt, array('VALUE' => 'DATE'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
748 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
749 $recur = $event->add('DTSTART', $dt);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
750 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
751 if ($summary) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
752 $event->add('SUMMARY', $summary);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
753 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
754 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
755 if ($instance['id'] !== 'master') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
756 $dt = DateTimeParser::parse($instance['id'], $eventInfo['timezone']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
757 // Treat is as a DATE field
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
758 if (strlen($instance['id']) <= 8) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
759 $recur = $event->add('RECURRENCE-ID', $dt, array('VALUE' => 'DATE'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
760 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
761 $recur = $event->add('RECURRENCE-ID', $dt);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
762 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
763 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
764 $organizer = $event->add('ORGANIZER', $message->recipient);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
765 if ($message->recipientName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
766 $organizer['CN'] = $message->recipientName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
767 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
768 $attendee = $event->add('ATTENDEE', $message->sender, array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
769 'PARTSTAT' => $instance['newstatus']
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
770 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
771 if ($message->senderName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
772 $attendee['CN'] = $message->senderName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
773 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
774 $hasReply = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
775
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
776 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
777
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
778 if ($hasReply) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
779 $message->message = $icalMsg;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
780 return array($message);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
781 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
782 return array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
783 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
784
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
785 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
786
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
787 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
788 * Returns attendee information and information about instances of an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
789 * event.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
790 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
791 * Returns an array with the following keys:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
792 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
793 * 1. uid
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
794 * 2. organizer
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
795 * 3. organizerName
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
796 * 4. attendees
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
797 * 5. instances
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
798 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
799 * @param VCalendar $calendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
800 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
801 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
802 protected function parseEventInfo(VCalendar $calendar = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
803
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
804 $uid = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
805 $organizer = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
806 $organizerName = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
807 $organizerForceSend = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
808 $sequence = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
809 $timezone = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
810 $status = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
811 $organizerScheduleAgent = 'SERVER';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
812
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
813 $significantChangeHash = '';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
814
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
815 // Now we need to collect a list of attendees, and which instances they
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
816 // are a part of.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
817 $attendees = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
818
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
819 $instances = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
820 $exdate = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
821
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
822 foreach($calendar->VEVENT as $vevent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
823
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
824 if (is_null($uid)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
825 $uid = $vevent->UID->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
826 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
827 if ($uid !== $vevent->UID->getValue()) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
828 throw new ITipException('If a calendar contained more than one event, they must have the same UID.');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
829 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
830 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
831
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
832 if (!isset($vevent->DTSTART)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
833 throw new ITipException('An event MUST have a DTSTART property.');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
834 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
835
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
836 if (isset($vevent->ORGANIZER)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
837 if (is_null($organizer)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
838 $organizer = $vevent->ORGANIZER->getNormalizedValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
839 $organizerName = isset($vevent->ORGANIZER['CN'])?$vevent->ORGANIZER['CN']:null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
840 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
841 if ($organizer !== $vevent->ORGANIZER->getNormalizedValue()) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
842 throw new SameOrganizerForAllComponentsException('Every instance of the event must have the same organizer.');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
843 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
844 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
845 $organizerForceSend =
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
846 isset($vevent->ORGANIZER['SCHEDULE-FORCE-SEND']) ?
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
847 strtoupper($vevent->ORGANIZER['SCHEDULE-FORCE-SEND']) :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
848 null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
849 $organizerScheduleAgent =
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
850 isset($vevent->ORGANIZER['SCHEDULE-AGENT']) ?
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
851 strtoupper((string)$vevent->ORGANIZER['SCHEDULE-AGENT']) :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
852 'SERVER';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
853 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
854 if (is_null($sequence) && isset($vevent->SEQUENCE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
855 $sequence = $vevent->SEQUENCE->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
856 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
857 if (isset($vevent->EXDATE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
858 $exdate = $vevent->EXDATE->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
859 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
860 if (isset($vevent->STATUS)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
861 $status = strtoupper($vevent->STATUS->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
862 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
863
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
864 $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
865 if ($recurId==='master') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
866 $timezone = $vevent->DTSTART->getDateTime()->getTimeZone();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
867 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
868 if(isset($vevent->ATTENDEE)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
869 foreach($vevent->ATTENDEE as $attendee) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
870
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
871 if ($this->scheduleAgentServerRules &&
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
872 isset($attendee['SCHEDULE-AGENT']) &&
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
873 strtoupper($attendee['SCHEDULE-AGENT']->getValue()) === 'CLIENT'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
874 ) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
875 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
876 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
877 $partStat =
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
878 isset($attendee['PARTSTAT']) ?
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
879 strtoupper($attendee['PARTSTAT']) :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
880 'NEEDS-ACTION';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
881
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
882 $forceSend =
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
883 isset($attendee['SCHEDULE-FORCE-SEND']) ?
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
884 strtoupper($attendee['SCHEDULE-FORCE-SEND']) :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
885 null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
886
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
887
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
888 if (isset($attendees[$attendee->getNormalizedValue()])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
889 $attendees[$attendee->getNormalizedValue()]['instances'][$recurId] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
890 'id' => $recurId,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
891 'partstat' => $partStat,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
892 'force-send' => $forceSend,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
893 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
894 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
895 $attendees[$attendee->getNormalizedValue()] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
896 'href' => $attendee->getNormalizedValue(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
897 'instances' => array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
898 $recurId => array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
899 'id' => $recurId,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
900 'partstat' => $partStat,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
901 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
902 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
903 'name' => isset($attendee['CN'])?(string)$attendee['CN']:null,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
904 'forceSend' => $forceSend,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
905 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
906 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
907
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
908 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
909 $instances[$recurId] = $vevent;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
910
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
911 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
912
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
913 foreach($this->significantChangeProperties as $prop) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
914 if (isset($vevent->$prop)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
915 $significantChangeHash.=$prop.':';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
916 foreach($vevent->select($prop) as $val) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
917 $significantChangeHash.= $val->getValue().';';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
918 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
919 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
920 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
921
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
922 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
923 $significantChangeHash = md5($significantChangeHash);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
924
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
925 return compact(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
926 'uid',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
927 'organizer',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
928 'organizerName',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
929 'organizerScheduleAgent',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
930 'organizerForceSend',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
931 'instances',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
932 'attendees',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
933 'sequence',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
934 'exdate',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
935 'timezone',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
936 'significantChangeHash',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
937 'status'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
938 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
939
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
940 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
941
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
942 }