3
* Class representing vEvents.
5
* Copyright 2003-2013 Horde LLC (http://www.horde.org/)
7
* See the enclosed file COPYING for license information (LGPL). If you
8
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
10
* @author Mike Cochrane <mike@graftonhall.co.nz>
12
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15
class Horde_Icalendar_Vevent extends Horde_Icalendar
18
* The component type of this class.
22
public $type = 'vEvent';
29
public function exportvCalendar()
32
$requiredAttributes = array(
34
'UID' => strval(new Horde_Support_Uuid())
38
if (!empty($this->_container)) {
40
$method = $this->_container->getAttribute('METHOD');
41
} catch (Horde_Icalendar_Exception $e) {
47
$requiredAttributes['DTSTART'] = time();
48
$requiredAttributes['SUMMARY'] = '';
52
$requiredAttributes['ATTENDEE'] = '';
53
$requiredAttributes['DTSTART'] = time();
54
$requiredAttributes['SUMMARY'] = '';
58
$requiredAttributes['ATTENDEE'] = '';
62
$requiredAttributes['DTSTART'] = time();
63
$requiredAttributes['SEQUENCE'] = 1;
64
$requiredAttributes['SUMMARY'] = '';
68
$requiredAttributes['ATTENDEE'] = '';
69
$requiredAttributes['SEQUENCE'] = 1;
73
$requiredAttributes['ATTENDEE'] = '';
77
$requiredAttributes['DTSTART'] = time();
81
foreach ($requiredAttributes as $name => $default_value) {
83
$this->getAttribute($name);
84
} catch (Horde_Icalendar_Exception $e) {
85
$this->setAttribute($name, $default_value);
89
return $this->_exportvData('VEVENT');
93
* Update the status of an attendee of an event.
95
* @param $email The email address of the attendee.
96
* @param $status The participant status to set.
97
* @param $fullname The full name of the participant to set.
99
public function updateAttendee($email, $status, $fullname = '')
101
foreach ($this->_attributes as $key => $attribute) {
102
if ($attribute['name'] == 'ATTENDEE' &&
103
$attribute['value'] == 'mailto:' . $email) {
104
$this->_attributes[$key]['params']['PARTSTAT'] = $status;
105
if (!empty($fullname)) {
106
$this->_attributes[$key]['params']['CN'] = $fullname;
108
unset($this->_attributes[$key]['params']['RSVP']);
112
$params = array('PARTSTAT' => $status);
113
if (!empty($fullname)) {
114
$params['CN'] = $fullname;
116
$this->setAttribute('ATTENDEE', 'mailto:' . $email, $params);
120
* Return the organizer display name or email.
122
* @return string The organizer name to display for this event.
124
public function organizerName()
127
$organizer = $this->getAttribute('ORGANIZER', true);
128
} catch (Horde_Icalendar_Exception $e) {
129
return Horde_Icalendar_Translation::t("An unknown person");
132
if (isset($organizer[0]['CN'])) {
133
return $organizer[0]['CN'];
136
$organizer = parse_url($this->getAttribute('ORGANIZER'));
138
return $organizer['path'];
142
* Update this event with details from another event.
144
* @param Horde_Icalendar_Vevent $vevent The vEvent with latest details.
146
public function updateFromvEvent($vevent)
148
$newAttributes = $vevent->getAllAttributes();
149
foreach ($newAttributes as $newAttribute) {
151
$this->getAttribute($newAttribute['name']);
152
} catch (Horde_Icalendar_Exception $e) {
153
// Already exists so just add it.
154
$this->setAttribute($newAttribute['name'],
155
$newAttribute['value'],
156
$newAttribute['params']);
160
// Already exists so locate and modify.
163
// Try matching the attribte name and value incase
164
// only the params changed (eg attendee updating
166
foreach ($this->_attributes as $id => $attr) {
167
if ($attr['name'] == $newAttribute['name'] &&
168
$attr['value'] == $newAttribute['value']) {
170
foreach ($newAttribute['params'] as $param_id => $param_name) {
171
$this->_attributes[$id]['params'][$param_id] = $param_name;
178
// Else match the first attribute with the same
179
// name (eg changing start time).
180
foreach ($this->_attributes as $id => $attr) {
181
if ($attr['name'] == $newAttribute['name']) {
182
$this->_attributes[$id]['value'] = $newAttribute['value'];
184
foreach ($newAttribute['params'] as $param_id => $param_name) {
185
$this->_attributes[$id]['params'][$param_id] = $param_name;
195
* Update just the attendess of event with details from another
198
* @param Horde_Icalendar_Vevent $vevent The vEvent with latest details
200
public function updateAttendeesFromvEvent($vevent)
202
$newAttributes = $vevent->getAllAttributes();
203
foreach ($newAttributes as $newAttribute) {
204
if ($newAttribute['name'] != 'ATTENDEE') {
209
$this->getAttribute($newAttribute['name']);
210
} catch (Horde_Icalendar_Exception $e) {
211
// Already exists so just add it.
212
$this->setAttribute($newAttribute['name'],
213
$newAttribute['value'],
214
$newAttribute['params']);
218
// Already exists so locate and modify.
220
// Try matching the attribte name and value incase
221
// only the params changed (eg attendee updating
223
foreach ($this->_attributes as $id => $attr) {
224
if ($attr['name'] == $newAttribute['name'] &&
225
$attr['value'] == $newAttribute['value']) {
227
foreach ($newAttribute['params'] as $param_id => $param_name) {
228
$this->_attributes[$id]['params'][$param_id] = $param_name;
236
// Else match the first attribute with the same
237
// name (eg changing start time).
238
foreach ($this->_attributes as $id => $attr) {
239
if ($attr['name'] == $newAttribute['name']) {
240
$this->_attributes[$id]['value'] = $newAttribute['value'];
242
foreach ($newAttribute['params'] as $param_id => $param_name) {
243
$this->_attributes[$id]['params'][$param_id] = $param_name;