public static function createDistantView(EiProjet $ei_project, EiTree $ei_parent_tree, $data, Doctrine_Connection $conn = null) { $result_file = new DOMDocument(); if ($conn == null) { $conn = Doctrine_Manager::connection(); } try { $conn->beginTransaction(); //Début de la transaction //$result_file = new DOMDocument(); //Appel du webservice $result_update = MyFunction::loadResultOfWebServiceByPostJson(MyFunction::getPrefixPath(null) . "/serviceweb/project/view/create.json", array('project_id' => $ei_project->getProjectId(), 'project_ref' => $ei_project->getRefId(), 'parent_id' => $ei_parent_tree->getId(), 'data' => $data)); $array_result = json_decode(html_entity_decode($result_update), true); //Récupération de la vue pour traitement if (count($array_result) == 0) { return false; } if (array_key_exists("error", $array_result)) { return false; } if (!$array_result[0]) { return false; } //Rechargement d'une vuew EiView::reload($array_result, $conn); $conn->commit(); return true; } catch (Exception $e) { $conn->rollback(); //return false; throw $e; } }
public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null) { if ($conn == null) { $conn = Doctrine_Manager::connection(); } //Création de la collection d'objet View à ajouter $collection = new Doctrine_Collection("EiView"); $items = $projets->getElementsByTagName("ei_views"); if ($items->length > 0) { //ya t-il des éléments à traiter? $ei_views = $items->item(0)->getElementsByTagName("ei_view"); if ($ei_views->length > 0) { foreach ($ei_views as $ei_view) { $view_id = $ei_view->getAttribute("view_id"); $view_ref = $ei_view->getAttribute("view_ref"); //recherche du profil en base if ($view_id != null && $view_ref != null) { $q = Doctrine_Core::getTable('EiView')->findOneByViewIdAndViewRef($view_id, $view_ref); if ($q && $q != null) { //si l'element existe , on fait une mise à jour $q->setDescription($ei_view->getElementsByTagName("description")->item(0)->nodeValue); $q->setIsActive($ei_view->getElementsByTagName("is_active")->item(0)->nodeValue); $q->save($conn); } else { //l'élément n'existe pas encore, et dans ce cas on le crée $new_ei_view = new EiView(); $new_ei_view->setViewId($view_id); $new_ei_view->setViewRef($view_ref); $new_ei_view->setDescription($ei_view->getElementsByTagName("description")->item(0)->nodeValue); $new_ei_view->setIsActive($ei_view->getElementsByTagName("is_active")->item(0)->nodeValue); $new_ei_view->setProjectId($project_id); $new_ei_view->setProjectRef($project_ref); // $new_ei_view->save($conn); $collection->add($new_ei_view); } } } if ($collection->getFirst()) { $collection->save($conn); } //Sauvegarde de la collection return 1; } return null; //On a retrouvé aucun élément de ce type } }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $this->html = $request->getParameter($form->getName()); //Si les données sont valides, on envoi en format json la fonction et ses éventuels paramètres pour insertion. $this->result = EiView::createDistantView($this->ei_project, $this->ei_parent_tree, json_encode($this->html)); $this->success = true; } else { $this->html = $this->getPartial('view/form', array('form' => $form, 'ei_parent_tree' => $this->ei_parent_tree, 'ei_project' => $this->ei_project)); } }