Пример #1
0
 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
     }
 }