Create a nag Task object from an activesync message
public fromASTask ( Horde_ActiveSync_Message_Task $message ) | ||
$message | Horde_ActiveSync_Message_Task | The task object |
/** * Replaces the task identified by UID with the content represented in the * specified content type. * * If you want to replace multiple tasks with the UID specified in the * VCALENDAR data, you may use $this->import instead. This automatically does a * replace if existings UIDs are found. * * * @param string $uid Identify the task to replace. * @param string $content The content of the task. * @param string $contentType What format is the data in? Currently supports: * - text/x-vcalendar * - text/calendar * * @return boolean Success or failure. */ public function replace($uid, $content, $contentType) { $factory = $GLOBALS['injector']->getInstance('Nag_Factory_Driver'); $existing = $factory->create('')->getByUID($uid); $taskId = $existing->id; $owner = $existing->owner; if (!Nag::hasPermission($existing->tasklist, Horde_Perms::EDIT)) { throw new Horde_Exception_PermissionDenied(); } switch ($contentType) { case 'text/calendar': case 'text/x-vcalendar': if (!$content instanceof Horde_Icalendar_Vtodo) { $iCal = new Horde_Icalendar(); if (!$iCal->parsevCalendar($content)) { throw new Nag_Exception(_("There was an error importing the iCalendar data.")); } $components = $iCal->getComponents(); $component = null; foreach ($components as $content) { if ($content instanceof Horde_Icalendar_Vtodo) { if ($component !== null) { throw new Nag_Exception(_("Multiple iCalendar components found; only one vTodo is supported.")); } $component = $content; } } if ($component === null) { throw new Nag_Exception(_("No iCalendar data was found.")); } } $task = new Nag_Task(); $task->fromiCalendar($content); $task->owner = $owner; $factory->create($existing->tasklist)->modify($taskId, $task->toHash()); break; case 'activesync': $task = new Nag_Task(); $task->fromASTask($content); $task->owner = $owner; $factory->create($existing->tasklist)->modify($taskId, $task->toHash()); break; default: throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType)); } return $result; }