fromiCalendar() public method

Creates a task from a Horde_Icalendar_Vtodo object.
public fromiCalendar ( Horde_Icalendar_Vtodo $vTodo )
$vTodo Horde_Icalendar_Vtodo The iCalendar data to update from.
Exemplo n.º 1
0
Arquivo: Api.php Projeto: Gomez/horde
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  */
 public function davPutObject($collection, $object, $data)
 {
     $dav = $GLOBALS['injector']->getInstance('Horde_Dav_Storage');
     $internal = $dav->getInternalCollectionId($collection, 'tasks') ?: $collection;
     if (!Nag::hasPermission($internal, Horde_Perms::EDIT)) {
         throw new Nag_Exception("Task List does not exist or no permission to edit");
     }
     $ical = new Horde_Icalendar();
     if (!$ical->parsevCalendar($data)) {
         throw new Nag_Exception(_("There was an error importing the iCalendar data."));
     }
     $storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($internal);
     foreach ($ical->getComponents() as $content) {
         if (!$content instanceof Horde_Icalendar_Vtodo) {
             continue;
         }
         $task = new Nag_Task();
         $task->fromiCalendar($content);
         try {
             try {
                 $existing_id = $dav->getInternalObjectId($object, $internal) ?: preg_replace('/\\.ics$/', '', $object);
             } catch (Horde_Dav_Exception $e) {
                 $existing_id = $object;
             }
             $existing_task = Nag::getTask($internal, $existing_id);
             /* Check if our task is newer then the existing - get the
              * task's history. */
             $modified = $this->_modified($internal, $existing_task->uid);
             try {
                 if (!empty($modified) && $content->getAttribute('LAST-MODIFIED') < $modified) {
                     /* LAST-MODIFIED timestamp of existing entry is newer:
                      * don't replace it. */
                     continue;
                 }
             } catch (Horde_Icalendar_Exception $e) {
             }
             $task->owner = $existing_task->owner;
             $storage->modify($existing_task->id, $task->toHash());
         } catch (Horde_Exception_NotFound $e) {
             $hash = $task->toHash();
             $newTask = $storage->add($hash);
             $dav->addObjectMap($newTask[0], $object, $internal);
         }
     }
 }
Exemplo n.º 3
0
Arquivo: data.php Projeto: horde/horde
 /* Create a Nag storage instance. */
 $nag_storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($storage->get('target'));
 $max_tasks = $perms->hasAppPermission('max_tasks');
 $num_tasks = Nag::countTasks();
 $result = null;
 foreach ($next_step as $row) {
     if ($max_tasks !== true && $num_tasks >= $max_tasks) {
         Horde::permissionDeniedError('nag', 'max_tasks', sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')));
         break;
     }
     if (!is_array($row)) {
         if (!is_a($row, 'Horde_Icalendar_Vtodo')) {
             continue;
         }
         $task = new Nag_Task($nag_storage);
         $task->fromiCalendar($row);
         $row = $task->toHash();
         foreach (array_keys($app_fields) as $field) {
             if (!isset($row[$field])) {
                 $row[$field] = '';
             }
         }
     }
     $row['owner'] = $GLOBALS['registry']->getAuth();
     foreach (array('start', 'due', 'completed_date') as $field) {
         if (!empty($row[$field])) {
             try {
                 $date = new Horde_Date($row[$field]);
                 $row[$field] = $date->timestamp();
             } catch (Horde_Date_Exception $e) {
                 unset($row[$field]);