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