Example #1
0
 public function saveAction($r_controller = null, $r_action = null, $r_id = null)
 {
     set_time_limit(180);
     ini_set('memory_limit', '512M');
     $request = new \Phalcon\Http\Request();
     $response = new \Phalcon\Http\Response();
     $previousURL = 'mapfile/process';
     if (!$request->isPost()) {
         return $response->redirect($this->cancelURL);
     }
     $layers = $this->session->get('processData');
     if (!$layers) {
         return $response->redirect($this->cancelURL);
     }
     //Check if a context shoud be created
     $creer_contexte = $request->getPost('creer_contexte', null);
     $igoContexte = null;
     if ($creer_contexte) {
         $contexteName = trim($request->getPost('name', null));
         $contexteCode = trim($request->getPost('code', null));
         $contexteDescription = trim($request->getPost('description', null));
         $onlineResource = trim($request->getPost('onlineResource', null));
         if (!$contexteName) {
             $this->flashSession->error('Veuillez indiquer un nom de contexte.');
         }
         if (!$contexteCode) {
             $this->flashSession->error('Veuillez indiquer un code de contexte.');
         }
         if (!$contexteDescription) {
             $this->flashSession->error('Veuillez indiquer une description du contexte.');
         }
         if (!$onlineResource) {
             $this->flashSession->error('Veuillez indiquer la resource en ligne.');
         }
         $mapServerConfig = $this->getDI()->getConfig()->mapserver;
         $fileName = $mapServerConfig->mapfileCacheDir . $mapServerConfig->contextesCacheDir . trim($contexteCode) . ".map";
         if (file_exists($fileName)) {
             $this->flash->error("Le fichier {$fileName} existe déjà. Choisissez un autre code.");
         }
         $this->session->set('contexteName', $contexteName);
         $this->session->set('contexteCode', $contexteCode);
         $this->session->set('contexteDescription', $contexteDescription);
         $this->session->set('onlineResource', $onlineResource);
         if ($this->flashSession->has('error')) {
             return $response->redirect($previousURL);
         }
         $igoContexte = new IgoContexte();
         $mapfileData = $this->session->get('mapfileData');
         // Substitude contexteCode if provided
         $onlineResource = str_replace("{Code}", $contexteCode, $onlineResource);
         $igoContexte->mf_map_meta_onlineresource = $onlineResource;
         $igoContexte->mf_map_projection = $mapfileData['map']['projection'];
         $igoContexte->nom = $contexteName;
         $igoContexte->code = $contexteCode;
         $igoContexte->description = $contexteDescription;
         $igoContexte->mode = "l";
         //mode Liste
         $igoContexte->generer_onlineresource = true;
     }
     //Save the layers (and optionally a context)
     $mapfileParser = new MapfileParser();
     $data = $mapfileParser->formatSaveData($layers, $this->view->host, $this->view->host_alias);
     try {
         $this->save($data, $igoContexte);
         $this->flashSession->success('Sauvegarde effectuée avec succès!');
     } catch (Exception $e) {
         $this->flashSession->error($e->getMessage());
         return $response->redirect($previousURL);
     }
     $this->clearSession();
 }
Example #2
0
 public function saveAction($r_controller = null, $r_action = null, $r_id = null)
 {
     set_time_limit(180);
     ini_set('memory_limit', '512M');
     $request = new \Phalcon\Http\Request();
     $response = new \Phalcon\Http\Response();
     $previousURL = 'mapfile/process';
     if ($request->isPost() == true) {
         if ($layers = $this->session->get('processData')) {
             //Check if a context shoud be created
             $contexte = $request->getPost('contexte', null);
             $igoContexte = null;
             if ($contexte && $contexte == 1) {
                 $contexteName = $request->getPost('name', null);
                 $contexteCode = $request->getPost('code', null);
                 $contexteDescription = $request->getPost('description', null);
                 $onlineResource = $request->getPost('onlineResource', null);
                 $missingParameter = false;
                 if (!$contexteName || strlen(trim($contexteName)) == 0) {
                     $this->flashSession->error('Veuillez entrer un nom de contexte.');
                     $missingParameter = true;
                 }
                 if (!$contexteCode || strlen(trim($contexteCode)) == 0) {
                     $this->flashSession->error('Veuillez entrer un code de contexte.');
                     $missingParameter = true;
                 }
                 if (!$contexteDescription || strlen(trim($contexteDescription)) == 0) {
                     $this->flashSession->error('Veuillez entrer une description du contexte.');
                     $missingParameter = true;
                 }
                 if (!$onlineResource || strlen(trim($onlineResource)) == 0) {
                     $this->flashSession->error('Veuillez entré la resource en ligne.');
                     $missingParameter = true;
                 }
                 $this->session->set('contexteName', $contexteName);
                 $this->session->set('contexteCode', $contexteCode);
                 $this->session->set('contexteDescription', $contexteDescription);
                 $this->session->set('onlineResource', $onlineResource);
                 if ($missingParameter) {
                     return $response->redirect($previousURL);
                 }
                 $mapServerConfig = $this->getDI()->getConfig()->mapserver;
                 $fileName = $mapServerConfig->mapfileCacheDir . $mapServerConfig->contextesCacheDir . trim($contexteCode) . ".map";
                 if (file_exists($fileName)) {
                     $this->flash->error("le fichier {$fileName} existe déjà!");
                     return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
                 }
                 $igoContexte = new IgoContexte();
                 $mapfileData = $this->session->get('mapfileData');
                 // Online Resource for generated mapfile will be initialised by default to the mapserv.fcgi path and the generated mapfile path.
                 //                   $onlineResource = $mapfileData['map']['wms_onlineresource'];
                 //                   if (strpos(strtolower($onlineResource), strtolower($this->view->host)) !== false) {
                 //                       $igoContexte->mf_map_meta_onlineresource = $onlineResource;
                 //                   } else {
                 //                       if ($onlineResource && $onlineResource != '') {
                 //                           $contexteDescription .= ' (' . $onlineResource . ')';
                 //                       }
                 //                   }
                 //$mapserverConfiguration = $this->getDI()->getConfig()->mapserver;
                 //$onlineResource = $mapserverConfiguration->host . $mapserverConfiguration->mapserver_path . "?" . $mapserverConfiguration->mapfileCacheDir . $contexteCode . ".map";
                 $onlineResource = trim($onlineResource);
                 // contains {Code}.map
                 if (strpos($onlineResource, '{Code}') !== FALSE) {
                     if ($onlineResource) {
                         $onlineResource = str_replace("{Code}", $contexteCode, $onlineResource);
                     }
                 }
                 $igoContexte->mf_map_meta_onlineresource = $onlineResource;
                 //$igoContexte->mf_map_meta_onlineresource = trim($onlineResource);
                 $igoContexte->mf_map_projection = $mapfileData['map']['projection'];
                 $igoContexte->nom = trim($contexteName);
                 $igoContexte->code = trim($contexteCode);
                 $igoContexte->description = trim($contexteDescription);
                 $igoContexte->mode = "l";
                 $igoContexte->generer_onlineresource = true;
             }
             //Save the layers (and optionally a context)
             $mapfileParser = new MapfileParser();
             $data = $mapfileParser->formatSaveData($layers, $this->view->host, $this->view->host_alias);
             try {
                 $this->save($data, $igoContexte);
                 $this->flashSession->success('Sauvegarde effectuée avec succès!');
             } catch (Exception $e) {
                 $this->flashSession->error($e->getMessage());
                 return $response->redirect($previousURL);
             }
             //Clear session
             $this->session->set('mapfile', null);
             $this->session->set('mapfileData', null);
             $this->session->set('selectData', null);
             $this->session->set('processData', null);
             $this->session->set('contexteName', null);
             $this->session->set('contexteCode', null);
             $this->session->set('contexteDescription', null);
             $this->session->set('onlineResource', null);
         } else {
             return $response->redirect($this->cancelURL);
         }
     } else {
         return $response->redirect($this->cancelURL);
     }
 }