private function getConnection($connectionString, $connectionType)
 {
     $connectionQuery = '';
     if ($connectionString) {
         $connectionQuery .= 'connexion LIKE "' . $connectionString . '%"';
     } else {
         $connectionQuery .= 'connexion IS NULL ';
     }
     $igoConnexionType = IgoConnexionType::findFirst("connexion_type = '{$connectionType}'");
     if (!$igoConnexionType) {
         die("Type de connection inconnu: " . $connectionType);
     }
     $connexionTypeId = $igoConnexionType->id;
     $connexionTypeNom = $igoConnexionType->nom;
     if ($igoConnexionType) {
         $connectionQuery .= ' AND connexion_type_id=' . $connexionTypeId;
     }
     //If connection doesn't exist, create it
     $igoConnection = IgoConnexion::findFirst($connectionQuery);
     if (!$igoConnection) {
         $igoConnection = new IgoConnexion();
         // $igoConnection->setTransaction($transaction);
         $igoConnection->connexion = $connectionString;
         $igoConnection->connexion_type_id = $connexionTypeId;
         if ($igoConnection->save(false) == false) {
             foreach ($igoConnection->getMessages() as $message) {
                 throw new Exception($message);
             }
             //$transaction->rollback();
             $this->db->rollback();
         } else {
             $igoConnection->nom = $connexionTypeNom . ' ' . $igoConnection->id;
             $igoConnection->save(false);
         }
     } else {
         if ($igoConnection->nom == "" || $igoConnection->nom == null) {
             //  $igoConnection->setTransaction($transaction);
             $igoConnection->nom = $connexionTypeNom . ' ' . $igoConnection->id;
             $igoConnection->connexion_type_id = $connexionTypeId;
             $igoConnection->save(false);
         }
     }
     return $igoConnection;
 }
Exemple #2
0
 private function getConnection($connectionString, $connectionType)
 {
     $connectionQuery = '';
     if ($connectionString) {
         $connectionQuery .= 'connexion LIKE "' . $connectionString . '%"';
     } else {
         $connectionQuery .= 'connexion IS NULL ';
     }
     $igoConnexionType = IgoConnexionType::findFirst("connexion_type = '{$connectionType}'");
     if (!$igoConnexionType) {
         die("Type de connection inconnu: " . $connectionType);
     }
     $connexionTypeId = $igoConnexionType->id;
     $connexionTypeNom = $igoConnexionType->nom;
     if ($igoConnexionType) {
         $connectionQuery .= ' AND connexion_type_id=' . $connexionTypeId;
     }
     //If connection doesn't exist, create it
     $igoConnexion = IgoConnexion::findFirst($connectionQuery);
     if (!$igoConnexion) {
         $igoConnexion = new IgoConnexion();
         $igoConnexion->connexion = $connectionString;
         $igoConnexion->connexion_type_id = $connexionTypeId;
         $this->igoConnexionSave($igoConnexion);
         $igoConnexion->nom = $connexionTypeNom . ' ' . $igoConnexion->id;
         $igoConnexion->save(false);
     } else {
         if (!$igoConnexion->nom) {
             $igoConnexion->nom = $connexionTypeNom . ' ' . $igoConnexion->id;
             $igoConnexion->connexion_type_id = $connexionTypeId;
             $igoConnexion->save(false);
         }
     }
     return $igoConnexion;
 }
 public function traiteMapfileAction($r_controller = null, $r_action = null, $r_id = null)
 {
     parent::newAction($r_controller, $r_action, $r_id);
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "index"));
     }
     $this->view->pick("gestion_couche/creation");
     $code = $this->request->getPost("code");
     $code = $this->traiteClass($code);
     $lignes = explode("\n", $code);
     $mf_layer_meta_def = "";
     $mf_layer_def = "";
     $meta = false;
     $projection = false;
     foreach ($lignes as $ligne) {
         if ($projection) {
             $this->tag->setDefault('mf_layer_projection', trim($ligne, " '\"\t\n\r"));
             $projection = false;
             continue;
         }
         if (trim($ligne) == "" || trim($ligne) == "LAYER") {
             continue;
         }
         preg_match("/[\\s]?(?P<element>[^\\s]+)\\s+(?P<contenu>[^#\n]*)/i", $ligne, $matches);
         if (!isset($matches['contenu'])) {
             //echo "Pas de match pour $ligne <br>";
             continue;
         } else {
             //printf ("Élément: %s  Contenu: %s <br>",$matches['element'],$matches['contenu']);
         }
         switch ($matches['element']) {
             case 'NAME':
                 $this->tag->setDefault('mf_layer_name', trim($matches['contenu'], "'\"\n\r"));
                 $this->tag->setDefault('fiche_csw_id', trim($matches['contenu'], "'\"\n\r"));
                 $catalogue = IgoCatalogueCsw::findFirst();
                 $this->tag->setDefault('catalogue_csw_id', $catalogue->id);
                 $igoClasseEntite = IgoClasseEntite::findFirst("nom='" . trim($matches['contenu'], "'\"\n\r") . "'");
                 if ($igoClasseEntite) {
                     $this->tag->setDefault('classe_entite_id', $igoClasseEntite->id);
                 }
                 break;
             case 'TYPE':
                 $igoGeometrieType = IgoGeometrieType::findFirst("layer_type='" . trim($matches['contenu'], "\n\r") . "'");
                 if ($igoGeometrieType) {
                     $this->tag->setDefault('geometrie_type_id', $igoGeometrieType->id);
                 }
                 break;
             case 'GROUP':
                 $this->tag->setDefault('mf_layer_group', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'CONNECTIONTYPE':
                 //TODO aller chercher la connection
                 $igoConnexionType = IgoConnexionType::findFirst("nom='" . trim($matches['contenu'], "\n\r") . "'");
                 if ($igoConnexionType) {
                     $this->tag->setDefault('connexion_type_id', $igoConnexionType->id);
                 }
                 break;
             case 'CONNECTION':
                 $this->tag->setDefault('connexion', trim($matches['contenu'], "'\"\n\r"));
                 // TODO bypasser l'erreur de phql
                 $where = "connexion like '" . trim(str_replace("'", "_", trim($matches['contenu'], "'\"\n\r"))) . "'";
                 $igoConnexion = IgoConnexion::findFirst($where);
                 //var_dump($where);
                 if ($igoConnexion) {
                     $this->tag->setDefault('connexion_id', $igoConnexion->id);
                 }
                 break;
             case 'DATA':
                 $this->tag->setDefault('mf_layer_data', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'MINSCALE':
                 $this->tag->setDefault('mf_layer_minscale_denom', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'MAXSCALE':
                 $this->tag->setDefault('mf_layer_maxscale_denom', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'LABELMINSCALE':
                 $this->tag->setDefault('mf_layer_labelminscale_denom', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'LABELMAXSCALE':
                 $this->tag->setDefault('mf_layer_labelmaxscale_denom', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'OPACITY':
                 $this->tag->setDefault('mf_layer_opacity', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'FILTER':
                 $this->tag->setDefault('mf_layer_filter', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case '"wms_group_title"':
                 $this->tag->setDefault('wms_group_title', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case '"wms_name"':
                 $this->tag->setDefault('wms_name', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case '"wms_title"':
                 $this->tag->setDefault('wms_title', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case '"z_order"':
                 $this->tag->setDefault('z_order', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case '"msp_classe_meta"':
                 $this->tag->setDefault('fiche_csw_id', trim($matches['contenu'], "'\"\n\r"));
                 break;
             case 'PROJECTION':
                 $projection = true;
                 break;
             case 'METADATA':
                 $meta = true;
                 break;
             case 'END':
                 $meta = false;
                 break;
             case 'PROCESSING':
                 break;
             default:
                 if ($meta) {
                     $mf_layer_meta_def = $mf_layer_meta_def . "\n" . $ligne;
                 } else {
                     $mf_layer_def = $mf_layer_def . "\n" . $ligne;
                 }
         }
         $this->tag->setDefault('mf_layer_meta_def', trim($mf_layer_meta_def, "'\"\n\r"));
         $this->tag->setDefault('mf_layer_def', trim($mf_layer_def, "'\"\n\r"));
     }
 }