1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Icalendar_Vevent extends Horde_Icalendar
16: {
17: 18: 19: 20: 21:
22: public $type = 'vEvent';
23:
24: 25: 26: 27: 28:
29: public function exportvCalendar()
30: {
31:
32: $requiredAttributes = array(
33: 'DTSTAMP' => time(),
34: 'UID' => strval(new Horde_Support_Uuid())
35: );
36:
37: $method = !empty($this->_container)
38: ? $this->_container->getAttribute('METHOD')
39: : 'PUBLISH';
40:
41: switch ($method) {
42: case 'PUBLISH':
43: $requiredAttributes['DTSTART'] = time();
44: $requiredAttributes['SUMMARY'] = '';
45: break;
46:
47: case 'REQUEST':
48: $requiredAttributes['ATTENDEE'] = '';
49: $requiredAttributes['DTSTART'] = time();
50: $requiredAttributes['SUMMARY'] = '';
51: break;
52:
53: case 'REPLY':
54: $requiredAttributes['ATTENDEE'] = '';
55: break;
56:
57: case 'ADD':
58: $requiredAttributes['DTSTART'] = time();
59: $requiredAttributes['SEQUENCE'] = 1;
60: $requiredAttributes['SUMMARY'] = '';
61: break;
62:
63: case 'CANCEL':
64: $requiredAttributes['ATTENDEE'] = '';
65: $requiredAttributes['SEQUENCE'] = 1;
66: break;
67:
68: case 'REFRESH':
69: $requiredAttributes['ATTENDEE'] = '';
70: break;
71: }
72:
73: foreach ($requiredAttributes as $name => $default_value) {
74: try {
75: $this->getAttribute($name);
76: } catch (Horde_Icalendar_Exception $e) {
77: $this->setAttribute($name, $default_value);
78: }
79: }
80:
81: return $this->_exportvData('VEVENT');
82: }
83:
84: 85: 86: 87: 88: 89: 90:
91: public function updateAttendee($email, $status, $fullname = '')
92: {
93: foreach ($this->_attributes as $key => $attribute) {
94: if ($attribute['name'] == 'ATTENDEE' &&
95: $attribute['value'] == 'mailto:' . $email) {
96: $this->_attributes[$key]['params']['PARTSTAT'] = $status;
97: if (!empty($fullname)) {
98: $this->_attributes[$key]['params']['CN'] = $fullname;
99: }
100: unset($this->_attributes[$key]['params']['RSVP']);
101: return;
102: }
103: }
104: $params = array('PARTSTAT' => $status);
105: if (!empty($fullname)) {
106: $params['CN'] = $fullname;
107: }
108: $this->setAttribute('ATTENDEE', 'mailto:' . $email, $params);
109: }
110:
111: 112: 113: 114: 115:
116: public function organizerName()
117: {
118: try {
119: $organizer = $this->getAttribute('ORGANIZER', true);
120: } catch (Horde_Icalendar_Exception $e) {
121: return Horde_Icalendar_Translation::t("An unknown person");
122: }
123:
124: if (isset($organizer[0]['CN'])) {
125: return $organizer[0]['CN'];
126: }
127:
128: $organizer = parse_url($this->getAttribute('ORGANIZER'));
129:
130: return $organizer['path'];
131: }
132:
133: 134: 135: 136: 137:
138: public function updateFromvEvent($vevent)
139: {
140: $newAttributes = $vevent->getAllAttributes();
141: foreach ($newAttributes as $newAttribute) {
142: try {
143: $currentValue = $this->getAttribute($newAttribute['name']);
144: } catch (Horde_Icalendar_Exception $e) {
145:
146: $this->setAttribute($newAttribute['name'],
147: $newAttribute['value'],
148: $newAttribute['params']);
149: continue;
150: }
151:
152:
153: $found = false;
154:
155:
156:
157:
158: foreach ($this->_attributes as $id => $attr) {
159: if ($attr['name'] == $newAttribute['name'] &&
160: $attr['value'] == $newAttribute['value']) {
161:
162: foreach ($newAttribute['params'] as $param_id => $param_name) {
163: $this->_attributes[$id]['params'][$param_id] = $param_name;
164: }
165: $found = true;
166: break;
167: }
168: }
169: if (!$found) {
170:
171:
172: foreach ($this->_attributes as $id => $attr) {
173: if ($attr['name'] == $newAttribute['name']) {
174: $this->_attributes[$id]['value'] = $newAttribute['value'];
175:
176: foreach ($newAttribute['params'] as $param_id => $param_name) {
177: $this->_attributes[$id]['params'][$param_id] = $param_name;
178: }
179: break;
180: }
181: }
182: }
183: }
184: }
185:
186: 187: 188: 189: 190: 191:
192: public function updateAttendeesFromvEvent($vevent)
193: {
194: $newAttributes = $vevent->getAllAttributes();
195: foreach ($newAttributes as $newAttribute) {
196: if ($newAttribute['name'] != 'ATTENDEE') {
197: continue;
198: }
199:
200: try {
201: $currentValue = $this->getAttribute($newAttribute['name']);
202: } catch (Horde_Icalendar_Exception $e) {
203:
204: $this->setAttribute($newAttribute['name'],
205: $newAttribute['value'],
206: $newAttribute['params']);
207: continue;
208: }
209:
210:
211: $found = false;
212:
213:
214:
215: foreach ($this->_attributes as $id => $attr) {
216: if ($attr['name'] == $newAttribute['name'] &&
217: $attr['value'] == $newAttribute['value']) {
218:
219: foreach ($newAttribute['params'] as $param_id => $param_name) {
220: $this->_attributes[$id]['params'][$param_id] = $param_name;
221: }
222: $found = true;
223: break;
224: }
225: }
226:
227: if (!$found) {
228:
229:
230: foreach ($this->_attributes as $id => $attr) {
231: if ($attr['name'] == $newAttribute['name']) {
232: $this->_attributes[$id]['value'] = $newAttribute['value'];
233:
234: foreach ($newAttribute['params'] as $param_id => $param_name) {
235: $this->_attributes[$id]['params'][$param_id] = $param_name;
236: }
237: break;
238: }
239: }
240: }
241: }
242: }
243:
244: }
245: