Example #1
0
 /**
  * Enlève d'un groupe les couches, sauf celles spécifiées
  * @param string $id_couches Liste des couches à conserver
  * @param int $groupe_id 
  * @param int $profil_id Id du profil propriétaire
  */
 public function enleverCouchesDuGroupe($id_couches, $groupe_id, $profil_id)
 {
     if (!$id_couches) {
         $id_couches = 0;
     }
     $estAdmin = $this->getDi()->getSession()->get("info_utilisateur")->estAdmin;
     if (!$estAdmin) {
         //Récupérer la liste des profils du pilote
         $profils = $this->getDi()->getSession()->get("info_utilisateur")->profils;
         $liste_profil_id_utilisateur = array();
         foreach ($profils as $profil) {
             array_push($liste_profil_id_utilisateur, $profil["id"]);
         }
         $liste_profil_id_utilisateur = implode(",", $liste_profil_id_utilisateur);
     }
     //Récupérer les couches qui sont à enlever du groupe
     $igoGroupeCouches = IgoGroupeCouche::find("groupe_id = {$groupe_id} AND couche_id NOT IN ({$id_couches})");
     foreach ($igoGroupeCouches as $igoGroupeCouche) {
         //L'utilisateur n'est pas un pilote
         if (!$estAdmin) {
             //Vérifier si l'utilisateur à le droit d'enlever la couche du groupe
             $igoVuePermissionsPourCouches = IgoVuePermissionsPourCouches::findFirst("couche_id = {$igoGroupeCouche->couche_id} AND groupe_id = {$groupe_id} AND profil_id IN({$liste_profil_id_utilisateur})");
         }
         //L'utilisateur a le droit d'enlever la couche du groupe
         if ($estAdmin || $igoVuePermissionsPourCouches && $igoVuePermissionsPourCouches->est_association) {
             //Supprimer les associations de cette couche dans les contextes
             $igoCoucheContextes = IgoCoucheContexte::find("groupe_id = {$igoGroupeCouche->id}");
             foreach ($igoCoucheContextes as $igoCoucheContexte) {
                 if (!$igoCoucheContextes->delete()) {
                     foreach ($igoCoucheContextes->getMessages() as $message) {
                         $this->flash->error($message);
                     }
                 }
             }
             if (!$igoGroupeCouche->delete()) {
                 foreach ($igoGroupeCouche->getMessages() as $message) {
                     $this->flash->error($message);
                 }
             }
         }
     }
 }
 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());
 }
Example #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;
     }
 }
Example #4
0
 public function associerContexteEditAction($param)
 {
     $numberPage = 1;
     if (strpos($param, "&") > 0) {
         //Ok, Ok, c'est pas joli... il faudra parser.
         $numberPage = substr($param, strpos($param, "&page=") + 6);
         $param = substr($param, 0, strpos($param, "&"));
     }
     if ($this->startsWith($param, "contexte_id")) {
         $contexte_id = intval(substr($param, strrpos($param, "=") + 1));
         // Sauvegarde du formulaire
         $act_id = $id = 0;
         $nouvelleValeur = FALSE;
         //
         $a_creer = TRUE;
         // L'instance de couche contexte doit être créée
         foreach ($_POST as $attribut_id => $valeur) {
             if ($this->endsWith($attribut_id, "_")) {
                 $couche_contexte_id = 0;
             } else {
                 $couche_contexte_id = intval(substr($attribut_id, strrpos($attribut_id, "_") + 1));
             }
             $attribut_id = substr($attribut_id, 0, strrpos($attribut_id, "_"));
             $id = intval(substr($attribut_id, strrpos($attribut_id, "_") + 1));
             $attribut = substr($attribut_id, 0, strrpos($attribut_id, "_"));
             /*
              var_dump($contexte_id);
              var_dump($id);
              var_dump($attribut_id);
              var_dump($attribut);
              var_dump($valeur);
             */
             if ($id > 0) {
                 //C'est un attribut
                 if ($act_id != $id) {
                     //une autre ligne
                     if ($act_id != 0 && $nouvelleValeur) {
                         $igoCouchecontexte->save();
                         if (!($igoCouchecontexte->est_visible || $igoCouchecontexte->est_active)) {
                             $igoCouchecontexte->delete();
                         }
                     }
                     $nouvelleValeur = FALSE;
                     $a_creer = TRUE;
                 }
                 if ($a_creer) {
                     if ($couche_contexte_id == 0) {
                         $igoCouchecontexte = new IgoCoucheContexte();
                         //$igoCouche=IgoCouche::findFirst("id=" . $id);
                         $igoCouchecontexte->contexte_id = $contexte_id;
                         $igoCouchecontexte->groupe_id = $id;
                     } else {
                         $igoCouchecontexte = IgoCoucheContexte::findFirst("id=" . $couche_contexte_id);
                     }
                     $nouvelleValeur = $igoCouchecontexte->est_visible || $igoCouchecontexte->est_active;
                     $igoCouchecontexte->est_visible = FALSE;
                     $igoCouchecontexte->est_active = FALSE;
                     $a_creer = FALSE;
                 }
                 if (isset($valeur) && $valeur != 0 && trim($valeur) != "" && !is_null($valeur) && $valeur != FALSE) {
                     $nouvelleValeur = TRUE;
                 }
                 $act_id = $id;
                 $igoCouchecontexte->{$attribut} = $valeur;
             }
         }
         if ($act_id != 0 && $nouvelleValeur) {
             $igoCouchecontexte->save();
             if (!($igoCouchecontexte->est_visible || $igoCouchecontexte->est_active)) {
                 $igoCouchecontexte->delete();
             }
         }
         $this->flash->notice("Changements sauvegardés");
         //Requête
         $phql = $this->modelsManager->createBuilder()->columns("IgoCoucheContexte.id as id," . "IgoGroupe.id as groupe_id," . "nom," . "IgoGroupe.description," . "ind_fond_de_carte," . "est_visible," . "est_active")->from('IgoGroupe')->leftjoin('IgoCoucheContexte')->where("IgoCoucheContexte." . $param . " OR  IgoCoucheContexte.contexte_id IS NULL")->orderBy('contexte_id');
     }
     $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $phql, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
 }
Example #5
0
 public function exclude_items($igo_contexte, $igo_profil)
 {
     $exclude_list = "";
     if ($this->IgoGeometrie->ind_inclusion == "E") {
         foreach ($this->IgoGeometrie->IgoAttribut as $value) {
             if (!$value->est_inclu) {
                 $exclude_list = $exclude_list . ', ' . $value->colonne;
             }
         }
     }
     $igo_couche_contexte = IgoCoucheContexte::find("couche_id=" . $this->id . "and contexte_id=" . $igo_contexte->id . "and est_exclu");
     foreach ($igo_couche_contexte as $value) {
         $exclude_list = $exclude_list . ', ' . $value->IgoAttribut->colonne;
     }
     if ($igo_profil && isset($igo_profil->id)) {
         $igo_permission = IgoPermission::find("couche_id=" . $this->id . "and profil_id=" . $igo_profil->id . "and est_exclu");
         foreach ($igo_permission as $value) {
             $exclude_list = $exclude_list . ', ' . $value->IgoAttribut->colonne;
         }
     }
     if ($exclude_list != "") {
         $exclude_list = substr($exclude_list, 2);
         return '"gml_exclude_items" "' . $exclude_list . '"';
     } else {
         return '';
     }
 }
Example #6
0
 /**
  * Créé une copie d'une association igo_couche_contexte
  * @param int $contexte_id Id de contexte à associer au igo_couche_contexte
  * return IgoCoucheContexte|bool Le IgoCoucheContexte, false en cas d'erreur
  */
 public function dupliquer($contexte_id = false)
 {
     //    error_log("Début IgoCoucheContexte->dupliquer()");
     $igoNouveauCoucheContexte = new IgoCoucheContexte();
     $igoNouveauCoucheContexte->contexte_id = $contexte_id ? $contexte_id : $this->contexte_id;
     $igoNouveauCoucheContexte->couche_id = $this->couche_id;
     $igoNouveauCoucheContexte->groupe_id = $this->groupe_id;
     $igoNouveauCoucheContexte->arbre_id = $this->arbre_id;
     $igoNouveauCoucheContexte->attribut_id = $this->attribut_id;
     $igoNouveauCoucheContexte->est_visible = $this->est_visible;
     $igoNouveauCoucheContexte->est_active = $this->est_active;
     $igoNouveauCoucheContexte->est_exclu = $this->est_exclu;
     $igoNouveauCoucheContexte->ind_fond_de_carte = $this->ind_fond_de_carte;
     $igoNouveauCoucheContexte->mf_layer_meta_name = $this->mf_layer_meta_name;
     $igoNouveauCoucheContexte->mf_layer_meta_title = $this->mf_layer_meta_title;
     $igoNouveauCoucheContexte->mf_layer_meta_group_title = $this->mf_layer_meta_group_title;
     $igoNouveauCoucheContexte->mf_layer_meta_z_order = $this->mf_layer_meta_z_order;
     $igoNouveauCoucheContexte->layer_a_order = $this->layer_a_order;
     $igoNouveauCoucheContexte->mf_layer_class_def = $this->mf_layer_class_def;
     $igoNouveauCoucheContexte->date_modif = $this->date_modif;
     if (!$igoNouveauCoucheContexte->save()) {
         $flash = $this->getDI()->getFlash();
         foreach ($igoNouveauCoucheContexte->getMessages() as $message) {
             $flash->error($message);
         }
         return false;
     }
     //    error_log("Fin IgoCoucheContexte->dupliquer()");
     return $igoNouveauCoucheContexte;
 }