1: <?php
2: /**
3: * A wrapper for vEvent iCalender data.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Itip
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL
11: * @link http://pear.horde.org/index.php?package=Itip
12: */
13:
14: /**
15: * A wrapper for vEvent iCalender data.
16: *
17: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
18: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
19: *
20: * See the enclosed file COPYING for license information (LGPL). If you did not
21: * receive this file, see
22: * {@link http://www.horde.org/licenses/lgpl21 LGPL}.
23: *
24: * @category Horde
25: * @package Itip
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL
28: * @link http://pear.horde.org/index.php?package=Itip
29: *
30: * @todo Clean this class up. Accessing private methods for copying the object
31: * is not nice. Reconsider if an interface is really needed. See also PMD
32: * report.
33: */
34: class Horde_Itip_Event_Vevent
35: implements Horde_Itip_Event
36: {
37: /**
38: * The wrapped vEvent.
39: *
40: * @var Horde_Icalendar_Vevent
41: */
42: private $_vevent;
43:
44: /**
45: * Constructor.
46: *
47: * @param Horde_Icalendar_Vevent $vevent The iCalendar object that will be
48: * wrapped by this instance.
49: */
50: public function __construct(Horde_Icalendar_Vevent $vevent)
51: {
52: $this->_vevent = $vevent;
53: }
54:
55: /**
56: * Returns the wrapped vEvent.
57: *
58: * @return Horde_Icalendar_Vevent The wrapped event.
59: */
60: public function getVevent()
61: {
62: return $this->_vevent;
63: }
64:
65: /**
66: * Return the method of the iTip request.
67: *
68: * @return string The method of the request.
69: */
70: public function getMethod()
71: {
72: return $this->_vevent->getAttributeDefault('METHOD', 'REQUEST');
73: }
74:
75: /**
76: * Return the uid of the iTip event.
77: *
78: * @return string The uid of the event.
79: */
80: public function getUid()
81: {
82: return $this->_vevent->getAttribute('UID');
83: }
84:
85: /**
86: * Return the summary for the event.
87: *
88: * @return string The summary.
89: */
90: public function getSummary()
91: {
92: return $this->_vevent->getAttributeDefault('SUMMARY', Horde_Itip_Translation::t("No summary available"));
93: }
94:
95: /**
96: * Return the start of the iTip event.
97: *
98: * @return string The start of the event.
99: */
100: public function getStart()
101: {
102: return $this->_vevent->getAttributeDefault('DTSTART', 0);
103: }
104:
105: /**
106: * Return the end of the iTip event.
107: *
108: * @return string The end of the event.
109: */
110: public function getEnd()
111: {
112: return $this->_vevent->getAttributeDefault('DTEND', 0);
113: }
114:
115: /**
116: * Return the organizer of the iTip event.
117: *
118: * @return string The organizer of the event.
119: *
120: * @todo Parse mailto using parse_url
121: */
122: public function getOrganizer()
123: {
124: return preg_replace('/^mailto:\s*/i', '', $this->_vevent->getAttributeDefault('ORGANIZER', ''));
125: }
126:
127: /**
128: * Copy the details from an event into this one.
129: *
130: * @param Horde_Itip_Event $event The event to copy from.
131: *
132: * @return NULL
133: */
134: public function copyEventInto(Horde_Itip_Event $event)
135: {
136: $this->copyUid($event);
137: $this->copySummary($event);
138: $this->copyDescription($event);
139: $this->copyStart($event);
140: $this->copyEndOrDuration($event);
141: $this->copySequence($event);
142: $this->copyLocation($event);
143: $this->copyOrganizer($event);
144: }
145:
146: /**
147: * Set the attendee parameters.
148: *
149: * @param string $attendee The mail address of the attendee.
150: * @param string $common_name Common name of the attendee.
151: * @param string $status Attendee status (ACCPETED, DECLINED, TENTATIVE)
152: *
153: * @return NULL
154: */
155: public function setAttendee($attendee, $common_name, $status)
156: {
157: $this->_vevent->setAttribute(
158: 'ATTENDEE',
159: 'mailto:' . $attendee,
160: array(
161: 'CN' => $common_name,
162: 'PARTSTAT' => $status
163: )
164: );
165: }
166:
167: /**
168: * Set the uid of the iTip event.
169: *
170: * @param string $uid The uid of the event.
171: *
172: * @return NULL
173: */
174: private function setUid($uid)
175: {
176: $this->_vevent->setAttribute('UID', $uid);
177: }
178:
179: /**
180: * Copy the uid from the request into the provided iTip instance.
181: *
182: * @return NULL
183: */
184: private function copyUid(Horde_Itip_Event $itip)
185: {
186: $itip->setUid($this->getUid());
187: }
188:
189: /**
190: * Set the summary for the event.
191: *
192: * @param string $summary The summary.
193: *
194: * @return NULL
195: */
196: private function setSummary($summary)
197: {
198: $this->_vevent->setAttribute('SUMMARY', $summary);
199: }
200:
201: /**
202: * Copy the summary from the request into the provided iTip instance.
203: *
204: * @return NULL
205: */
206: private function copySummary(Horde_Itip_Event $itip)
207: {
208: $itip->setSummary($this->getSummary());
209: }
210:
211: /**
212: * Return the description for the event.
213: *
214: * @return string The description.
215: */
216: private function getDescription()
217: {
218: return $this->_vevent->getAttribute('DESCRIPTION');
219: }
220:
221: /**
222: * Set the description for the event.
223: *
224: * @param string $description The description.
225: *
226: * @return NULL
227: */
228: private function setDescription($description)
229: {
230: $this->_vevent->setAttribute('DESCRIPTION', $description);
231: }
232:
233: /**
234: * Copy the description from the request into the provided iTip instance.
235: *
236: * @return NULL
237: */
238: private function copyDescription(Horde_Itip_Event $itip)
239: {
240: try {
241: $itip->setDescription($this->getDescription());
242: } catch (Horde_Icalendar_Exception $e) {
243: }
244: }
245:
246: /**
247: * Return the start parameters of the iTip event.
248: *
249: * @return array The start parameters of the event.
250: */
251: public function getStartParameters()
252: {
253: $parameters = $this->_vevent->getAttribute('DTSTART', true);
254: return array_pop($parameters);
255: }
256:
257: /**
258: * Set the start of the iTip event.
259: *
260: * @param string $start The start of the event.
261: * @param array $parameters Additional parameters.
262: *
263: * @return NULL
264: */
265: private function setStart($start, $parameters)
266: {
267: $this->_vevent->setAttribute('DTSTART', $start, $parameters);
268: }
269:
270: /**
271: * Copy the start time from the request into the provided iTip instance.
272: *
273: * @return NULL
274: */
275: private function copyStart(Horde_Itip_Event $itip)
276: {
277: $itip->setStart($this->getStart(), $this->getStartParameters());
278: }
279:
280: /**
281: * Return the end parameters of the iTip event.
282: *
283: * @return array The end parameters of the event.
284: */
285: private function getEndParameters()
286: {
287: $parameters = $this->_vevent->getAttribute('DTEND', true);
288: return array_pop($parameters);
289: }
290:
291: /**
292: * Set the end of the iTip event.
293: *
294: * @param string $end The end of the event.
295: * @param array $parameters Additional parameters.
296: *
297: * @return NULL
298: */
299: private function setEnd($end, $parameters)
300: {
301: $this->_vevent->setAttribute('DTEND', $end, $parameters);
302: }
303:
304: /**
305: * Return the duration for the event.
306: *
307: * @return string The duration of the event.
308: */
309: private function getDuration()
310: {
311: return $this->_vevent->getAttribute('DURATION');
312: }
313:
314: /**
315: * Return the duration parameters of the iTip event.
316: *
317: * @return array The duration parameters of the event.
318: */
319: private function getDurationParameters()
320: {
321: $parameters = $this->_vevent->getAttribute('DURATION', true);
322: return array_pop($parameters);
323: }
324:
325: /**
326: * Set the duration of the iTip event.
327: *
328: * @param string $duration The duration of the event.
329: * @param array $parameters Additional parameters.
330: *
331: * @return NULL
332: */
333: private function setDuration($duration, $parameters)
334: {
335: $this->_vevent->setAttribute('DURATION', $duration, $parameters);
336: }
337:
338: /**
339: * Copy the end time or event duration from the request into the provided
340: * iTip instance.
341: *
342: * @return NULL
343: */
344: private function copyEndOrDuration(Horde_Itip_Event $itip)
345: {
346: try {
347: $itip->setEnd($this->getEnd(), $this->getEndParameters());
348: } catch (Horde_Icalendar_Exception $e) {
349: $itip->setDuration($this->getDuration(), $this->getDurationParameters());
350: }
351: }
352:
353: /**
354: * Return the sequence for the event.
355: *
356: * @return string The sequence.
357: */
358: private function getSequence()
359: {
360: return $this->_vevent->getAttribute('SEQUENCE');
361: }
362:
363: /**
364: * Set the sequence for the event.
365: *
366: * @param string $sequence The sequence.
367: *
368: * @return NULL
369: */
370: private function setSequence($sequence)
371: {
372: $this->_vevent->setAttribute('SEQUENCE', $sequence);
373: }
374: /**
375: * Copy the sequence from the request into the provided iTip instance.
376: *
377: * @return NULL
378: */
379: private function copySequence(Horde_Itip_Event $itip)
380: {
381: try {
382: $itip->setSequence($this->getSequence());
383: } catch (Horde_Icalendar_Exception $e) {
384: }
385: }
386:
387: /**
388: * Return the location for the event.
389: *
390: * @return string The location.
391: */
392: private function getLocation()
393: {
394: return $this->_vevent->getAttribute('LOCATION');
395: }
396:
397: /**
398: * Set the location for the event.
399: *
400: * @param string $location The location.
401: *
402: * @return NULL
403: */
404: private function setLocation($location)
405: {
406: $this->_vevent->setAttribute('LOCATION', $location);
407: }
408:
409: /**
410: * Copy the location from the request into the provided iTip instance.
411: *
412: * @return NULL
413: */
414: private function copyLocation(Horde_Itip_Event $itip)
415: {
416: try {
417: $itip->setLocation($this->getLocation());
418: } catch (Horde_Icalendar_Exception $e) {
419: }
420: }
421:
422: /**
423: * Return the organizer for the event.
424: *
425: * @return string The organizer of the event.
426: */
427: private function getRawOrganizer()
428: {
429: return $this->_vevent->getAttribute('ORGANIZER');
430: }
431:
432: /**
433: * Return the organizer parameters of the iTip event.
434: *
435: * @return array The organizer parameters of the event.
436: */
437: private function getOrganizerParameters()
438: {
439: $parameters = $this->_vevent->getAttribute('ORGANIZER', true);
440: return array_pop($parameters);
441: }
442:
443: /**
444: * Set the organizer of the iTip event.
445: *
446: * @param string $organizer The organizer of the event.
447: * @param array $parameters Additional parameters.
448: *
449: * @return NULL
450: */
451: private function setOrganizer($organizer, $parameters)
452: {
453: $this->_vevent->setAttribute('ORGANIZER', $organizer, $parameters);
454: }
455:
456: /**
457: * Copy the organizer from the request into the provided iTip instance.
458: *
459: * @return NULL
460: */
461: private function copyOrganizer(Horde_Itip_Event $itip)
462: {
463: $itip->setOrganizer($this->getRawOrganizer(), $this->getOrganizerParameters());
464: }
465: }