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 KalFunction à ajouter $collection = new Doctrine_Collection("KalFunction"); $items = $projets->getElementsByTagName("ei_functions"); if ($items->length > 0) { //ya t-il des éléments à traiter? $ei_functions = $items->item(0)->getElementsByTagName("ei_function"); if ($ei_functions->length > 0) { foreach ($ei_functions as $ei_function) { $function_id = $ei_function->getAttribute("function_id"); $function_ref = $ei_function->getAttribute("function_ref"); //recherche de la fonction en base if ($function_id != null && $function_ref != null) { $q = Doctrine_Core::getTable('KalFunction')->findOneByFunctionIdAndFunctionRef($function_id, $function_ref); if ($q && $q != null) { //si l'element existe , on fait une mise à jour $q->setDescription($ei_function->getElementsByTagName("description")->item(0)->nodeValue); $q->setIsActive($ei_function->getElementsByTagName("is_active")->item(0)->nodeValue); $q->save($conn); //On supprime toutes les commandes associées à la fonction Doctrine_Core::getTable('EiFunctionHasCommande')->deleteAssociatedCmd($q, $conn); } else { //l'élément n'existe pas encore, et dans ce cas on le crée $new_ei_function = new KalFunction(); $new_ei_function->setFunctionId($function_id); $new_ei_function->setFunctionRef($function_ref); $new_ei_function->setProjectId($project_id); $new_ei_function->setProjectRef($project_ref); $new_ei_function->setDescription($ei_function->getElementsByTagName("description")->item(0)->nodeValue); $new_ei_function->setIsActive($ei_function->getElementsByTagName("is_active")->item(0)->nodeValue); $collection->add($new_ei_function); } } } if ($collection->getFirst()) { $collection->save($conn); } //Sauvegarde de la collection return 1; } return null; } }
public function executeCreate(sfWebRequest $request) { $this->forward404unless($request->isXmlHttpRequest()); $this->html = 'Error ...'; $this->success = false; $this->checkProject($request); $this->checkProfile($request, $this->ei_project); $this->checkParentTree($request, $this->ei_project); /* Vérification du package par défaut de l'utilisateur */ $this->defPack = Doctrine_Core::getTable('EiUserDefaultPackage')->findOneByProjectIdAndProjectRefAndUserIdAndUserRef($this->ei_project->getProjectId(), $this->ei_project->getRefId(), $this->ei_user->getUserId(), $this->ei_user->getRefId()); if ($this->defPack == null) { return $this->renderText(json_encode(array('html' => "You have to set default intervention before.Please do it and try again ...", 'is_default_intervention_null' => true, 'success' => $this->success))); } $kal_function = new KalFunction(); $kal_function->setProjectId($this->ei_project->getProjectId()); $kal_function->setProjectRef($this->ei_project->getRefId()); $this->form = new KalFunctionForm($kal_function); $this->processForm($request, $this->form); return $this->renderText(json_encode(array('html' => $this->html, 'success' => $this->success))); return sfView::NONE; }