/** * (non-PHPdoc) * @see ActiveSync_Frontend_Abstract::toTineModel() */ public function toTineModel(Syncroton_Model_IEntry $data, $entry = null) { if ($entry instanceof Tasks_Model_Task) { $task = $entry; } else { $task = new Tasks_Model_Task(array('organizer' => Tinebase_Core::getUser()->getId()), TRUE); } foreach ($this->_mapping as $syncrotonProperty => $tine20Property) { if (!isset($data->{$syncrotonProperty})) { $task->{$tine20Property} = null; continue; } switch ($tine20Property) { case 'completed': if ($data->{$syncrotonProperty} === 1) { $task->status = 'COMPLETED'; $task->{$tine20Property} = $data->dateCompleted; } else { $task->status = 'IN-PROCESS'; $task->{$tine20Property} = NULL; } break; case 'description': // @todo check $data->$fieldName->Type and convert to/from HTML if needed if ($data->{$syncrotonProperty} instanceof Syncroton_Model_EmailBody) { $task->{$tine20Property} = preg_replace("/(\r\n?|\n)/", "\r\n", $data->{$syncrotonProperty}->data); } else { $task->{$tine20Property} = null; } break; case 'priority': $prioMapping = Tasks_Model_Priority::getMapping(); $task->{$tine20Property} = isset($data->{$syncrotonProperty}) && isset($prioMapping[$data->{$syncrotonProperty}]) ? $prioMapping[$data->{$syncrotonProperty}] : Tasks_Model_Priority::NORMAL; break; default: if ($data->{$syncrotonProperty} instanceof DateTime) { $task->{$tine20Property} = new Tinebase_DateTime($data->{$syncrotonProperty}); } else { $task->{$tine20Property} = $data->{$syncrotonProperty}; } break; } } // task should be valid now $task->isValid(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " taskData " . print_r($task->toArray(), TRUE)); } return $task; }
/** * convert contact from xml to Addressbook_Model_Contact * * @todo handle images * @param SimpleXMLElement $_data * @return Addressbook_Model_Contact */ public function toTineModel(SimpleXMLElement $_data, $_entry = null) { if ($_entry instanceof Tasks_Model_Task) { $task = $_entry; } else { $task = new Tasks_Model_Task(null, true); } $xmlData = $_data->children('uri:Tasks'); foreach ($this->_mapping as $fieldName => $value) { switch ($value) { case 'completed': if ((int) $xmlData->{$fieldName} === 1) { $task->status = 'COMPLETED'; $task->completed = (string) $xmlData->DateCompleted; } else { $task->status = 'IN-PROCESS'; $task->completed = NULL; } break; case 'due': if (isset($xmlData->{$fieldName})) { $task->{$value} = new Tinebase_DateTime((string) $xmlData->{$fieldName}); } else { $task->{$value} = null; } break; default: if (isset($xmlData->{$fieldName})) { $task->{$value} = (string) $xmlData->{$fieldName}; } else { $task->{$value} = null; } break; } } if (version_compare($this->_device->acsversion, '12.0', '>=')) { $airSyncBase = $_data->children('uri:AirSyncBase'); if (isset($airSyncBase->Body) && isset($airSyncBase->Body->Data)) { $task->description = preg_replace("/(\r\n?|\n)/", "\r\n", (string) $airSyncBase->Body->Data); } } // task should be valid now $task->isValid(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " taskData " . print_r($task->toArray(), true)); } return $task; }