public function arbreCouchesEditAction($param = null)
 {
     //var_dump($this->udate());
     $deleted = false;
     $params = array();
     parse_str($param, $params);
     $contexte_id = isset($params['contexte_id']) ? $params['contexte_id'] : $this->request->get('contexte_id');
     if (!$contexte_id) {
         $this->flash->error("igo_contexte non-trouvé");
         return $this->dispatcher->forward(array("controller" => "igo_contexte", "action" => "index"));
     }
     //On récupére les données du formulaire Associer des groupes et des couches
     if (isset($_POST['valeursArbo'])) {
         $valeurs = json_decode($_POST['valeursArbo']);
         //On récupéres les données de la rétro d'un mapfile
     } else {
         $valeurs = $_POST;
     }
     //Sauvegarde des items du formulaire
     $igoCoucheContexte = false;
     foreach ($valeurs as $name => $valeur) {
         if (!$deleted) {
             $phql = "DELETE FROM IgoCoucheContexte WHERE contexte_id={$contexte_id}";
             $this->modelsManager->executeQuery($phql);
             $deleted = true;
             //var_dump($deleted);
         }
         $arbre_id = null;
         $couche_id = null;
         $changed = false;
         $type = null;
         $titre = null;
         $ordre = 0;
         if ('T' == substr($name, 1, 1)) {
             $titre = $valeur;
         }
         if ('O' == substr($name, 1, 1)) {
             $ordre = $valeur;
         }
         //Déterminer à quoi on a affaire
         if ('G' == substr($name, 0, 1)) {
             $type = 'groupe';
             $a = explode("_", substr($name, 2));
             array_shift($a);
             $arbre_id = implode('_', $a);
             $groupe_id = array_pop($a);
         } elseif ('CX' == substr($name, 0, 2)) {
             $type = 'colonne';
             $a = explode("_", substr($name, 2));
             $attribut_id = array_pop($a);
             array_shift($a);
             $arbre_id = implode('_', $a);
             $couche_id = substr($name, 2, strpos($name, "_") - 2);
         } elseif ('C' == substr($name, 0, 1)) {
             $type = 'couche';
             $a = explode("_", substr($name, 2));
             array_shift($a);
             $arbre_id = implode('_', $a);
             $couche_id = explode("_", substr($name, 2))[0];
         }
         if (isset($valeur) && $valeur != 0) {
             // printf("name: %s, arbre_id: %s, groupe_id: %s, couche_id: %s, type: %s, valeur: %s<br>", $name, $arbre_id, $groupe_id, $couche_id, $type, $valeur);
         }
         //Tenter de récupérer le igo_couche_contexte associé
         switch ($type) {
             case 'groupe':
                 // echo "1";
                 if (!$igoCoucheContexte || $igoCoucheContexte->arbre_id != $arbre_id || $igoCoucheContexte->couche_id != null || $igoCoucheContexte->attribut_id != null) {
                     // echo "-1R";
                     $igoCoucheContexte = null;
                     //$igoCoucheContexte = IgoCoucheContexte::findFirst("contexte_id={$contexte_id} AND groupe_id={$groupe_id} AND couche_id IS NULL AND attribut_id is null");
                     //  var_dump($igoCoucheContexte);
                 }
                 break;
             case 'colonne':
                 //   echo "3";
                 if (!$igoCoucheContexte || $igoCoucheContexte->arbre_id != $arbre_id || $igoCoucheContexte->couche_id != $couche_id || $igoCoucheContexte->attribut_id != $attribut_id) {
                     //   echo "-3R";
                     $igoCoucheContexte = null;
                     //$igoCoucheContexte = IgoCoucheContexte::findFirst("contexte_id={$contexte_id} AND groupe_id={$groupe_id} AND attribut_id={$attribut_id} AND couche_id={$couche_id}");
                 }
                 break;
             case 'couche':
                 // echo "2";
                 if (!$igoCoucheContexte || $igoCoucheContexte->arbre_id != $arbre_id || $igoCoucheContexte->couche_id != $couche_id || $igoCoucheContexte->attribut_id != null) {
                     //  echo "-2R";
                     $igoCoucheContexte = null;
                     //$igoCoucheContexte = IgoCoucheContexte::findFirst("contexte_id={$contexte_id} AND groupe_id={$groupe_id} AND couche_id={$couche_id} AND attribut_id is null");
                     //var_dump("contexte_id={$contexte_id} AND groupe_id={$groupe_id} AND couche_id={$couche_id} AND attribut_id is null");
                 }
                 break;
         }
         //On n'a pas trouvé le igo_couche_contexte associé
         if (!$igoCoucheContexte && $valeur) {
             //echo "***Création***";
             $changed = true;
             $igoCoucheContexte = new IgoCoucheContexte();
             $igoCoucheContexte->contexte_id = $contexte_id;
             //Initialiser les champs du contexte
             switch ($type) {
                 case 'groupe':
                     $igoGroupe = IgoGroupe::findFirst("id=" . $groupe_id);
                     if (!$igoGroupe) {
                         $this->flash->error("Le groupe &laquo; {$groupe_id} &raquo; n'existe pas.");
                     }
                     $igoCoucheContexte->groupe_id = $groupe_id;
                     $igoCoucheContexte->arbre_id = $arbre_id;
                     $igoCoucheContexte->ind_fond_de_carte = 'D';
                     $igoCoucheContexte->mf_layer_meta_name = $igoGroupe->nom;
                     $igoCoucheContexte->mf_layer_meta_title = $igoGroupe->nom;
                     if (!is_null($titre) && "" != $titre) {
                         $igoCoucheContexte->mf_layer_meta_group_title = $titre;
                     }
                     if (!is_null($ordre)) {
                         $igoCoucheContexte->layer_a_order = $ordre;
                     }
                     $igoCoucheContexte->mf_layer_meta_z_order = $igoGroupe->mf_layer_meta_z_order;
                     break;
                 case 'colonne':
                     $igoCoucheContexte->couche_id = $couche_id;
                     $igoCoucheContexte->groupe_id = $groupe_id;
                     $igoCoucheContexte->arbre_id = $arbre_id;
                     $igoCoucheContexte->attribut_id = $attribut_id;
                     $igoCoucheContexte->ind_fond_de_carte = 'D';
                     //$igoCoucheContexte->couche_id = $couche_id;
                     break;
                 case 'couche':
                     $igoCouche = IgoCouche::findFirst('id=' . $couche_id);
                     if (!$igoCouche) {
                         $this->flash->error("La couche ayant le igo_couche.id &laquo; {$couche_id} &raquo; n'existe pas.");
                     }
                     $igoCoucheContexte->groupe_id = $groupe_id;
                     $igoCoucheContexte->couche_id = $couche_id;
                     $igoCoucheContexte->arbre_id = $arbre_id;
                     $igoCoucheContexte->ind_fond_de_carte = 'D';
                     $igoCoucheContexte->mf_layer_meta_name = $igoCouche->mf_layer_meta_name;
                     $igoCoucheContexte->mf_layer_meta_title = $igoCouche->mf_layer_meta_title;
                     $igoCoucheContexte->mf_layer_meta_z_order = $igoCouche->mf_layer_meta_z_order;
                     if (!is_null($titre)) {
                         $igoCoucheContexte->mf_layer_meta_group_title = $titre;
                         $igoCoucheContexte->mf_layer_meta_title = $titre;
                     }
                     if (!is_null($ordre)) {
                         $igoCoucheContexte->layer_a_order = $ordre;
                     }
                     break;
             }
         }
         if ($igoCoucheContexte) {
             //Modifier la valeur de l'attribut
             $valeur = $valeur == '1';
             $attribut = substr($name, 1, 1);
             switch ($attribut) {
                 case "V":
                     $changed = $changed || $igoCoucheContexte->est_visible != $valeur;
                     $igoCoucheContexte->est_visible = $valeur;
                     break;
                 case "A":
                     $changed = $changed || $igoCoucheContexte->est_active != $valeur;
                     $igoCoucheContexte->est_active = $valeur;
                     break;
                 case "X":
                     $changed = $changed || $igoCoucheContexte->est_exclu != $valeur;
                     $igoCoucheContexte->est_exclu = $valeur;
                     break;
                 case "T":
                     if (!is_null($titre) && "" != $titre) {
                         $changed = $changed || $igoCoucheContexte->mf_layer_meta_group_title != $titre;
                         $igoCoucheContexte->mf_layer_meta_group_title = $titre;
                     }
                     break;
                 case "O":
                     if (!is_null($ordre)) {
                         $changed = $changed || $igoCoucheContexte->layer_a_order != $ordre;
                         $igoCoucheContexte->layer_a_order = $ordre;
                     }
                     break;
             }
         }
         if ($changed) {
             if (!$igoCoucheContexte->save()) {
                 foreach ($igoCoucheContexte->getMessages() as $message) {
                     $this->flash->error($message);
                 }
             }
         }
     }
     $contexteController = new IgoContexteController();
     $contexteController->saveMapFile($contexte_id);
     $igo_contexte = IgoContexte::findFirstByid($contexte_id);
     if (!$igo_contexte) {
         $this->flash->error("igo_contexte non-trouvé");
         return $this->dispatcher->forward(array("controller" => "igo_contexte", "action" => "index"));
     }
     $profils = $this->session->get("profils");
     $liste_profil_id_utilisateur = array();
     if ($profils) {
         foreach ($profils as $profil) {
             array_push($liste_profil_id_utilisateur, $profil["id"]);
         }
     }
     $liste_profil_id_utilisateur = implode(",", $liste_profil_id_utilisateur);
     if (!$liste_profil_id_utilisateur) {
         $liste_profil_id_utilisateur = 0;
     }
     $sql = " select 'G'::character varying(1) AS type,\r\n    gr.groupe_id as id,\r\n    gr.nom,\r\n    cc.mf_layer_meta_group_title AS mf_layer_meta_group_title,\r\n    gr.groupe_id AS groupe_id,\r\n    NULL::integer AS attribut_id,\r\n    COALESCE(cc.est_visible, false) AS visible,\r\n    COALESCE(cc.est_active, false) AS active,\r\n    COALESCE(cc.est_exclu, false) AS exclu,\r\n    NULL::text AS colonne,\r\n    NULL::boolean AS est_commune,\r\n    NULL::integer AS couche_id,\r\n    cc.id AS couche_contexte_id,\r\n    cc.layer_a_order AS layer_a_order,\r\n    true AS association_est_association,\r\n    COALESCE(cc.arbre_id, gr.grp) as grp,\r\n    (length(grp) - length(replace(grp, '_'::text, ''::text))) as len\r\n  from igo_vue_groupes_recursif gr\r\n  LEFT JOIN igo_couche_contexte cc ON cc.arbre_id=grp AND cc.contexte_id={$contexte_id} and cc.couche_id IS NULL\r\n  --LEFT JOIN igo_vue_permissions_pour_groupes pg ON pg.profil_id IN ({$liste_profil_id_utilisateur})\r\n UNION\r\n  select 'C'::character varying(1) AS type,\r\n    c.id,\r\n    c.mf_layer_meta_title AS nom,\r\n    cc.mf_layer_meta_group_title AS mf_layer_meta_group_title,\r\n    gc.groupe_id AS groupe_id,\r\n    igo_attribut.id AS attribut_id,\r\n     COALESCE(cc.est_visible,false) AND cc.arbre_id = gr.grp AS visible,\r\n     COALESCE(cc.est_active,false) AND cc.arbre_id = gr.grp AS active,\r\n     COALESCE(cc2.est_exclu,false) AND igo_attribut.id = cc2.attribut_id  AS exclu,\r\n    igo_attribut.colonne AS colonne,\r\n    c.est_commune AS est_commune,\r\n    c.id AS couche_id,\r\n    cc.id AS couche_contexte_id,\r\n    COALESCE(NULLIF(cc.layer_a_order, 0), c.layer_a_order) AS layer_a_order,\r\n    igo_vue_permissions_pour_couches.est_association AS association_est_association,\r\n    COALESCE(cc.arbre_id, gr.grp) as grp,\r\n        (length(grp) - length(replace(grp, '_'::text, ''::text))) as len\r\n     from igo_vue_groupes_recursif gr\r\n     JOIN igo_groupe_couche gc ON gc.groupe_id=gr.groupe_id\r\n     JOIN igo_couche c  ON gc.couche_id=c.id\r\n     JOIN igo_geometrie ON c.geometrie_id = igo_geometrie.id\r\n     LEFT JOIN igo_attribut ON igo_attribut.geometrie_id = igo_geometrie.id\r\n     LEFT JOIN igo_couche_contexte cc ON c.id=cc.couche_id AND cc.contexte_id={$contexte_id} and  cc.arbre_id=grp and cc.attribut_id IS NULL\r\n     LEFT JOIN igo_couche_contexte cc2 ON c.id=cc.couche_id AND cc.contexte_id={$contexte_id} and  cc.arbre_id=grp and cc2.attribut_id IS NOT NULL and cc2.attribut_id=igo_attribut.id\r\n     LEFT JOIN igo_vue_permissions_pour_couches ON igo_vue_permissions_pour_couches.couche_id = cc.id \r\nORDER BY grp, len,  type DESC, layer_a_order";
     //echo $sql;
     $igo_groupe = new IgoGroupe();
     $igo_groupe = new Resultset(null, $igo_groupe, $igo_groupe->getReadConnection()->query($sql));
     //$igo_groupe=$this->modelsManager->executeQuery($sql);
     $this->view->setVar("arbre", $igo_groupe);
     //  var_dump($this->udate());
 }
Пример #2
0
 /**
  * Stocke dans la vue, pour un groupe, les groupes et les couches, qui sont son enfant et qui ne sont pas son enfant
  * @param int $id Groupe courant
  */
 private function definirCouchesPourSelecteur($id = 0)
 {
     $id = intval($id);
     $couchesEnfantDeGroupe = array();
     $couchesPasEnfantDeGroupe = array();
     $groupe = IgoGroupe::findFirst($id);
     $estAdmin = $this->session->get("info_utilisateur")->estAdmin;
     if ($estAdmin) {
         //Couches qui ne sont pas dans le groupe
         $sql = "SELECT DISTINCT c.id , c.mf_layer_name AS valeur " . "FROM igo_couche AS c " . "LEFT JOIN igo_groupe_couche AS gc ON c.id = gc.couche_id WHERE gc.groupe_id <> {$id} " . "AND NOT EXISTS (SELECT id FROM igo_groupe_couche AS sr_gc WHERE sr_gc.couche_id = c.id AND sr_gc.groupe_id = {$id}) ";
         $igo_groupe = new IgoGroupe();
         $couchesPasEnfantDeGroupe = new Resultset(null, $igo_groupe, $igo_groupe->getReadConnection()->query($sql));
     } else {
         $profils = $this->getDi()->getSession()->get("profils");
         $ids_profil = array();
         foreach ($profils as $profil) {
             $ids_profil[] = $profil["id"];
         }
         $ids_profil = implode(',', $ids_profil);
         //Couches qui ne sont pas dans le groupe
         $sql = "SELECT DISTINCT c.id , c.mf_layer_name AS valeur\n                    FROM igo_couche AS c \n                    LEFT JOIN igo_groupe_couche AS gc  ON c.id = gc.couche_id \n                    INNER JOIN IgoVuePermissionsPourCouches AS vpc\n                    ON vpc.couche_id = gc.id\n                    WHERE gc.groupe_id <> :groupe_id:\n                    AND est_association AND profil_id IN ({$ids_profil})";
         $couchesPasEnfantDeGroupe = $this->modelsManager->executeQuery($sql, array('groupe_id' => $id));
     }
     $estGroupeDeCouche = $groupe->couches->count();
     $this->view->setVar("estGroupeDeCouche", $estGroupeDeCouche);
     //Couches qui sont dans le groupe
     foreach ($groupe->couches as $value) {
         $couchesEnfantDeGroupe[] = array("id" => $value->id, "valeur" => $value->mf_layer_name);
     }
     $this->view->setVar("couchesPasEnfantDeGroupe", $couchesPasEnfantDeGroupe);
     $this->view->setVar("couchesEnfantDeGroupe", $couchesEnfantDeGroupe);
 }
Пример #3
0
 /**
  * Save all layers and their depending classes in the database
  *  of distinct layers and not distinct layers.
  *  Distinct layers do not share the same name.   
  *
  *  $layers [array] : an array of layers
  *  
  * TODO: This function became huge overtime. It could be split
  *  into multiple functions but it's not an easy task and I lacked
  *  time to do it.
  *  
  */
 private function save($data, $igoContexte = null)
 {
     $this->db->begin();
     //Create a contexte if IgoContexte is defined
     if ($igoContexte) {
         $this->igoContexteSave($igoContexte);
     }
     //Create an associative array of all the possible non-multi geometry types
     //This way, we dont need to issue a sql request for each layer
     $geometryTypes = array();
     //TODO Déterminer pourquoi on ne veut pas les multi
     $allGeometryTypes = IgoGeometrieType::find("NOT nom ilike '%multi%'");
     foreach ($allGeometryTypes as $geometryType) {
         $geometryTypes[$geometryType->layer_type] = $geometryType->id;
     }
     //Create an empty array that will be used to store the group IDs
     $groups = array();
     $layerIndex = 1;
     try {
         $igoCouches = array();
         foreach ($data as $d) {
             $igoConnexion = null;
             if ($d['connection'] && isset($d['connection']['connectionString']) && isset($d['connection']['type'])) {
                 //Check if connexion exists already in the database
                 $igoConnexion = $this->getConnection($d['connection']['connectionString'], $d['connection']['type']);
             }
             foreach ($d['layers'] as $layer) {
                 if (isset($layer['connection']) && isset($layer['connectiontype']) && trim($layer['connection']) && trim($layer['connectiontype'])) {
                     //Check if connexion exists already in the database
                     $igoConnexion = $this->getConnection($layer['connection'], $layer['connectiontype']);
                 }
                 $groupeCoucheId = null;
                 $groupID = null;
                 $layer['currentGroup'] = null;
                 //If geometry type doesn't exist, create it
                 if (!array_key_exists($layer['type'], $geometryTypes)) {
                     $igoGeometrieType = new IgoGeometrieType();
                     $igoGeometrieType->layer_type = $layer['type'];
                     $igoGeometrieType->nom = $layer['type'];
                     $this->igoGeometrieTypeSave($igoGeometrieType);
                     //Store the new geometry type id in an array and refer to it
                     //for the following layers with the same geometry type
                     $geometryTypes[$layer['type']] = $igoGeometrieType->id;
                 }
                 $layerQuery = 'mf_layer_name="' . $layer['name'] . '"';
                 $igoLayer = IgoCouche::findFirst($layerQuery);
                 $layerSaveSuccessful = false;
                 if ($layer['action'] == 'insert') {
                     if ($igoLayer) {
                         //If a layer with the same name exists already
                         //Find its geometry
                         if ($igoLayer->geometrie_id) {
                             $geometryQuery = 'id="' . $igoLayer->geometrie_id . '"';
                             $igoGeometrie = IgoGeometrie::findFirst($geometryQuery);
                         } else {
                             $igoGeometrie = new IgoGeometrie();
                         }
                         //Find it's classe d'entité
                         if ($igoGeometrie && $igoGeometrie->classe_entite_id) {
                             $classeEntiteQuery = 'id="' . $igoGeometrie->classe_entite_id . '"';
                             $igoClasseEntite = IgoClasseEntite::findFirst($classeEntiteQuery);
                         } else {
                             $igoClasseEntite = null;
                         }
                         //Find its classes
                         if ($igoLayer->id) {
                             $classesQuery = 'couche_id="' . $igoLayer->id . '"';
                             $igoClasses = IgoClasse::find($classesQuery);
                         } else {
                             $igoClasses = null;
                         }
                     } else {
                         //If a layer with the same name doesn't exist
                         //Create a new layer
                         $igoLayer = new IgoCouche();
                         //Create a new geometry
                         $igoGeometrie = new IgoGeometrie();
                         //Set some variables to null
                         $igoClasseEntite = null;
                         $igoClasses = null;
                     }
                     $groupID = null;
                     if ($layer['wms_group_title']) {
                         //Create a new group only if no context are to be created or if the layer has no group already
                         if (!$igoContexte || !$layer['currentGroup']) {
                             //Find all the sub-groups
                             $groupNames = preg_split("/\\//", $layer['wms_group_title']);
                             $fullGroupName = '';
                             $parent_groupe_id = null;
                             foreach ($groupNames as $groupName) {
                                 //Build the full group name by appending the group name to the previous
                                 //full name. The full group name is used to store the ids of the
                                 //groups parsed already (but not yet commited) in order to create them only once
                                 //Exemple of two diffrent groups:
                                 //Vigilance/Inondation != MTQ/Inondation
                                 $fullGroupName .= '/' . $groupName;
                                 //Check if the group has been parsed already (from another layer) and retrieve its ID
                                 $found = false;
                                 foreach ($groups as $group) {
                                     if ($group['name'] == $fullGroupName) {
                                         $groupID = $group['id'];
                                         $found = true;
                                         break;
                                     }
                                 }
                                 //If the groups has not been created already, create it
                                 if (!$found) {
                                     //Check if this group exists in the database already
                                     $igoGroupe = IgoGroupe::findFirst('nom="' . $groupName . '"');
                                     if ($igoGroupe) {
                                         //If it exists already, retrieve it's id
                                         $groupID = $igoGroupe->id;
                                     } else {
                                         //If it doesn't exist, create it and retrieve it's id
                                         $igoGroupe = new IgoGroupe();
                                         $igoGroupe->nom = $groupName;
                                         $igoGroupe->est_exclu_arbre = 'FALSE';
                                         if (!$igoGroupe->save()) {
                                             foreach ($igoGroupe->getMessages() as $message) {
                                                 throw new Exception($message);
                                             }
                                             $this->db->rollback();
                                         }
                                         $groupID = $igoGroupe->id;
                                     }
                                     $igoGroupe->specifie_parent($parent_groupe_id);
                                     //Store the id of the newly created group in the groups array
                                     $groups[] = array('name' => $fullGroupName, 'id' => $groupID);
                                 }
                                 $parent_groupe_id = $groupID;
                             }
                         }
                     }
                     //This array is used to define a couche_contexte for each excluded attribute
                     $excludedAttributes = array();
                     if (!$igoClasseEntite) {
                         //If the classe d'entité doesn't exist, create a new one
                         $igoClasseEntite = new IgoClasseEntite();
                         //Else, set the classe d'entité name to the layer name
                         $igoClasseEntite->nom = $layer['name'];
                         // TODO : presentement on prend le premier catalogue du bord. Il faudra penser à une meilleure solution.
                         $igoCatalogueCsw = IgoCatalogueCsw::findFirst();
                         if ($igoCatalogueCsw) {
                             $igoClasseEntite->catalogue_csw_id = $igoCatalogueCsw->id;
                         }
                         if (!$igoClasseEntite->save()) {
                             foreach ($igoClasseEntite->getMessages() as $message) {
                                 throw new Exception($message);
                             }
                             $this->db->rollback();
                         }
                     }
                     //if (!$igoClasseEntite) {
                     //
                     //Update or set the geometry attributes
                     $igoGeometrie->mf_layer_projection = $layer['projection'];
                     $igoGeometrie->mf_layer_data = $layer['data'];
                     $igoGeometrie->connexion_id = $igoConnexion ? $igoConnexion->id : $igoGeometrie->connexion_id;
                     $igoGeometrie->geometrie_type_id = $geometryTypes[$layer['type']];
                     $igoGeometrie->classe_entite_id = $igoClasseEntite->id;
                     $igoGeometrie->vue_defaut = $layer['vue_defaut'];
                     $igoGeometrie->acces = "L";
                     // Définir l'indice d'inclusion...
                     $indice_inclusion = "T";
                     // T=Tous, E=Exclusion I=Inclusion
                     foreach ($layer['attributes'] as $attribute) {
                         if ($attribute['est_inclu']) {
                             $indice_inclusion = "I";
                             break;
                         } else {
                             $indice_inclusion = "E";
                             break;
                         }
                     }
                     $igoGeometrie->ind_inclusion = $indice_inclusion;
                     if ($igoGeometrie->save(false) == false) {
                         $this->db->rollback();
                         foreach ($igoGeometrie->getMessages() as $message) {
                             throw new Exception($message);
                         }
                     }
                     //Insert or update attributes
                     foreach ($layer['attributes'] as $attribute) {
                         $attributeQuery = 'geometrie_id="' . $igoGeometrie->id . '" AND colonne="' . $attribute['colonne'] . '"';
                         $igoAttribute = IgoAttribut::findFirst($attributeQuery);
                         $update = false;
                         if (!$igoAttribute) {
                             $igoAttribute = new IgoAttribut();
                             $update = true;
                         } else {
                             if ($igoAttribute && !$igoContexte) {
                                 $update = true;
                             }
                         }
                         if ($update) {
                             $igoAttribute->colonne = $attribute['colonne'];
                             $igoAttribute->est_cle = $attribute['est_cle'] ? 'TRUE' : 'FALSE';
                             $igoAttribute->est_inclu = $attribute['est_inclu'] ? 'TRUE' : 'FALSE';
                             $igoAttribute->geometrie_id = $igoGeometrie->id;
                             if (!$igoAttribute->save(false)) {
                                 foreach ($igoAttribute->getMessages() as $message) {
                                     throw new Exception($message);
                                 }
                                 $this->db->rollback();
                             }
                         } else {
                             if ($igoContexte && !$attribute['est_inclu']) {
                                 if ($igoAttribute->est_inclu == 'TRUE') {
                                     $excludedAttributes[] = $igoAttribute->id;
                                 }
                             }
                         }
                     }
                     // Création ou mise à jour de la couche
                     $igoLayer->type = $layer['location'];
                     $igoLayer->geometrie_id = $igoGeometrie->id;
                     $igoLayer->mf_layer_name = $layer['name'];
                     $igoLayer->mf_layer_group = $layer['group'];
                     $igoLayer->mf_layer_meta_name = $layer['wms_name'];
                     $igoLayer->mf_layer_meta_attribution_title = $layer['wms_attribution_title'];
                     $igoLayer->mf_layer_meta_title = $layer['wms_title'];
                     $igoLayer->mf_layer_meta_group_title = $layer['wms_group_title'];
                     $igoLayer->mf_layer_filtre = $layer['filter'];
                     $igoLayer->mf_layer_opacity = $layer['opacity'];
                     $igoLayer->mf_layer_minscale_denom = $layer['minscaledenom'] == -1 ? null : $layer['minscaledenom'];
                     $igoLayer->mf_layer_maxscale_denom = $layer['maxscaledenom'] == -1 ? null : $layer['maxscaledenom'];
                     $igoLayer->mf_layer_labelitem = $layer['labelitem'];
                     $igoLayer->mf_layer_labelminscale_denom = $layer['labelminscaledenom'] == -1 ? null : $layer['labelminscaledenom'];
                     $igoLayer->mf_layer_labelmaxscale_denom = $layer['labelmaxscaledenom'] == -1 ? null : $layer['labelmaxscaledenom'];
                     $igoLayer->mf_layer_def = $layer['layer_def'];
                     $igoLayer->mf_layer_meta_def = $layer['meta_def'];
                     if (isset($layer['wfs_maxfeatures']) && is_numeric($layer['wfs_maxfeatures'])) {
                         $igoLayer->mf_layer_meta_wfs_max_feature = $layer['wfs_maxfeatures'];
                     }
                     // Assignation du champ fiche_csw_id tel que décrit dans issue 39
                     $igoLayer->fiche_csw_id = $layer['name'];
                     if (isset($layer['msp_classe_meta'])) {
                         $igoLayer->fiche_csw_id = $layer['msp_classe_meta'];
                     }
                     //Check if some attributes should be overwritten in igoCoucheContexte
                     $coucheContexteName = null;
                     if ($igoContexte && $igoLayer->mf_layer_meta_name && $igoLayer->mf_layer_meta_name != $layer['wms_name']) {
                         $coucheContexteName = $layer['wms_name'];
                     } else {
                         $igoLayer->mf_layer_meta_name = isset($layer['wms_name']) ? $layer['wms_name'] : $layer['name'];
                     }
                     $coucheContexteTitle = null;
                     if ($igoContexte && $igoLayer->mf_layer_meta_title && $igoLayer->mf_layer_meta_title != $layer['wms_title']) {
                         $coucheContexteTitle = $layer['wms_title'];
                     } else {
                         $igoLayer->mf_layer_meta_title = $layer['wms_title'];
                     }
                     $coucheContexteFilter = null;
                     if ($igoContexte && $igoLayer->mf_layer_filtre && $igoLayer->mf_layer_filtre != $layer['filter']) {
                         $coucheContexteFilter = $layer['filter'];
                     } else {
                         $igoLayer->mf_layer_filtre = $layer['filter'];
                     }
                     //If the new group is different than the current group, assign the new group the the context instead
                     //of changing the group itself
                     if ($layer['currentGroup'] && $layer['currentGroup'] != $layer['wms_group_title']) {
                         $igoCoucheContexte->mf_layer_meta_group_title = $layer['wms_group_title'];
                     }
                     if (!$igoLayer->save(false)) {
                         foreach ($igoLayer->getMessages() as $message) {
                             throw new Exception($message);
                         }
                         $this->db->rollback();
                     } else {
                         $layerSaveSuccessful = true;
                         //If the layer has some classes defined already, delete them and re-insert them
                         //We need to delete them and re-insert since it is not possible to update them
                         //(they don't have a name on which we can query)
                         if ($igoClasses) {
                             foreach ($igoClasses as $igoClass) {
                                 if ($igoClass->delete() == false) {
                                     foreach ($igoClass->getMessages() as $message) {
                                         throw new Exception($message);
                                     }
                                 }
                             }
                         }
                         //Save each classes and assign them a z order
                         $mf_class_z_order = 0;
                         foreach ($layer['classes'] as $class) {
                             $igoClass = new IgoClasse();
                             $igoClass->mf_class_def = $class;
                             $igoClass->couche_id = $igoLayer->id;
                             $igoClass->mf_class_z_order = $mf_class_z_order;
                             $igoClass->save(false);
                             if ($igoLayer->save(false) == false) {
                                 foreach ($igoClass->getMessages() as $message) {
                                     throw new Exception($message);
                                 }
                                 $this->db->rollback();
                             }
                             $mf_class_z_order++;
                         }
                         if ($groupID) {
                             $igoGroupeeCouche = IgoGroupeCouche::findFirst('couche_id=' . $igoLayer->id . ' AND groupe_id=' . $groupID);
                             if (!$igoGroupeeCouche) {
                                 $igoGroupeeCouche = new IgoGroupeCouche();
                                 $igoGroupeeCouche->groupe_id = $groupID;
                                 $igoGroupeeCouche->couche_id = $igoLayer->id;
                                 $igoGroupeeCouche->save();
                             }
                         } else {
                             echo "La couche {$layer['name']} est dans aucun groupe.<br>";
                         }
                     }
                 }
                 //Conserver = softinsert, Insérer/remplacer = insert
                 if ($layer['action'] == 'softinsert' || $layer['action'] == 'insert' && $layerSaveSuccessful) {
                     if (!isset($excludedAttributees)) {
                         $excludedAttributes = array();
                     }
                     if ($igoContexte) {
                         //If no attributes are excluded, append a null value to the excluded attributes
                         //array. This way a couche_contexte with no excluded attribute will be created
                         if (count($excludedAttributes) == 0) {
                             $excludedAttributes[] = null;
                         }
                         foreach ($excludedAttributes as $excludedAttribute) {
                             $igoCoucheContexte = new IgoCoucheContexte();
                             $igoCoucheContexte->contexte_id = $igoContexte->id;
                             $igoCoucheContexte->couche_id = $igoLayer->id;
                             $igoCoucheContexte->layer_a_order = $layerIndex++;
                             $nomComplet = str_replace("'", "_", $layer['wms_group_title']);
                             while (!empty($nomComplet)) {
                                 // Fix pour que le groupe existe la première fois.
                                 $igoVueGroupesRecursif = IgoVueGroupesRecursif::findFirst("nom_complet like '%{$nomComplet}'");
                                 $groupe_id = $igoVueGroupesRecursif ? $igoVueGroupesRecursif->groupe_id : $groupID;
                                 if ($groupe_id && $igoVueGroupesRecursif) {
                                     $arbre_id = $igoVueGroupesRecursif->grp;
                                     $igoCoucheContexteGroupe = IgoCoucheContexte::findFirst("contexte_id={$igoContexte->id} and couche_id IS NULL and arbre_id='{$arbre_id}'");
                                     if (!$igoCoucheContexteGroupe) {
                                         $igoCoucheContexteGroupe = new IgoCoucheContexte();
                                         $igoCoucheContexteGroupe->contexte_id = $igoContexte->id;
                                         $igoCoucheContexteGroupe->couche_id = null;
                                         $igoCoucheContexteGroupe->groupe_id = $groupe_id;
                                         $igoCoucheContexteGroupe->arbre_id = $arbre_id;
                                         $igoCoucheContexteGroupe->mf_layer_meta_name = $igoVueGroupesRecursif->nom;
                                         $igoCoucheContexteGroupe->mf_layer_meta_title = $igoVueGroupesRecursif->nom_complet;
                                         $a = explode("/", $igoVueGroupesRecursif->nom_complet);
                                         $s = array_pop($a);
                                         $igoCoucheContexteGroupe->mf_layer_meta_title = $s;
                                         $igoCoucheContexteGroupe->mf_layer_meta_group_title = $s;
                                         $igoCoucheContexteGroupe->layer_a_order = $layerIndex++;
                                         $igoCoucheContexteGroupe->est_visible = 'TRUE';
                                         $igoCoucheContexteGroupe->ind_fond_de_carte = 'D';
                                         $igoCoucheContexteGroupe->save();
                                     }
                                 }
                                 $t = explode('/', $nomComplet);
                                 array_pop($t);
                                 $nomComplet = implode('/', $t);
                             }
                             $igoCoucheContexte->groupe_id = $groupe_id;
                             $igoVueGroupesRecursif = IgoVueGroupesRecursif::findFirst("nom_complet like '%" . str_replace("'", "_", $layer['wms_group_title']) . "'");
                             $igoCoucheContexte->arbre_id = $igoVueGroupesRecursif ? $igoVueGroupesRecursif->grp : $groupe_id;
                             $igoCoucheContexte->mf_layer_meta_name = $layer['wms_name'];
                             $igoCoucheContexte->mf_layer_meta_title = $layer['wms_title'];
                             $a = explode("/", $layer['wms_title']);
                             $s = array_pop($a);
                             $igoCoucheContexte->mf_layer_meta_title = $s;
                             $igoCoucheContexte->mf_layer_meta_group_title = $s;
                             $igoCoucheContexte->mf_layer_meta_z_order = $layer['zIndex'];
                             $igoCoucheContexte->est_visible = 'TRUE';
                             $igoCoucheContexte->ind_fond_de_carte = 'D';
                             //Check if some attributes should be overwritten in igoCoucheContexte
                             $coucheContexteName = null;
                             if ($igoContexte && $igoLayer->mf_layer_meta_name && $igoLayer->mf_layer_meta_name != $layer['wms_name']) {
                                 $coucheContexteName = $layer['wms_name'];
                             } else {
                                 $igoLayer->mf_layer_meta_name = $layer['wms_name'] ? $layer['wms_name'] : $layer['name'];
                             }
                             $coucheContexteTitle = null;
                             if ($igoContexte && $igoLayer->mf_layer_meta_title && $igoLayer->mf_layer_meta_title != $layer['wms_title']) {
                                 $coucheContexteTitle = $layer['wms_title'];
                             } else {
                                 $igoLayer->mf_layer_meta_title = $layer['wms_title'];
                             }
                             $coucheContexteFilter = null;
                             if ($igoContexte && $igoLayer->mf_layer_filtre && $igoLayer->mf_layer_filtre != $layer['filter']) {
                                 $coucheContexteFilter = $layer['filter'];
                             } else {
                                 $igoLayer->mf_layer_filtre = $layer['filter'];
                             }
                             if ($coucheContexteName) {
                                 $igoCoucheContexte->mf_layer_meta_name = $coucheContexteName;
                             }
                             if ($coucheContexteTitle) {
                                 $igoCoucheContexte->mf_layer_meta_title = $coucheContexteTitle;
                             }
                             if ($coucheContexteFilter) {
                                 $igoCoucheContexte->mf_layer_filtre = $coucheContexteFilter;
                             }
                             if ($excludedAttribute) {
                                 $igoCoucheContexte->attribut_id = $excludedAttribute;
                                 $igoCoucheContexte->est_exclu = 'TRUE';
                             }
                             //If the new group is different than the current group, assign the new group the the context instead
                             //of changing the group itself
                             if ($layer['currentGroup'] && $layer['currentGroup'] != $layer['wms_group_title']) {
                                 $igoCoucheContexte->mf_layer_meta_group_title = $layer['wms_group_title'];
                             }
                             $this->igoCoucheContexteSave($igoCoucheContexte);
                         }
                     }
                 }
                 $igoCouches[] = $igoLayer;
             }
         }
         $this->db->commit();
         if ($igoContexte !== null) {
             $igoContexte->saveMapFile();
         }
         foreach ($igoCouches as $igoCouche) {
             $igoCouche->saveMapFile(false);
         }
     } catch (Exception $e) {
         error_log(json_encode($e));
         throw $e;
     }
 }
Пример #4
0
 public static function findEstAssociable($params = null)
 {
     $profils = \Phalcon\DI::getDefault()->getSession()->get("info_utilisateur")->profils;
     $profil_ids = array();
     foreach ($profils as $profil) {
         array_push($profil_ids, $profil["id"]);
     }
     $profil_ids = implode(",", $profil_ids);
     $sql = "SELECT DISTINCT igo_vue_permissions_pour_groupes.groupe_id AS id, " . " igo_groupe.nom AS nom " . "FROM igo_vue_permissions_pour_groupes " . "INNER JOIN igo_groupe ON igo_groupe.id = igo_vue_permissions_pour_groupes.groupe_id " . "WHERE igo_vue_permissions_pour_groupes.profil_id IN ({$profil_ids}) AND igo_vue_permissions_pour_groupes.est_association ";
     $igo_groupe = new IgoGroupe();
     return new \Phalcon\Mvc\Model\Resultset\Simple(null, $igo_groupe, $igo_groupe->getReadConnection()->query($sql, $params));
 }