/**
  * Get parameters and set classes for the project and repository given.
  *
  * @param boolean $save If true, we have to save the form. So take liz_repository and others instead of repository from request parameters.
  * @return array List of needed variables : $params, $lizmapRepository, lizmapProject, etc.
  */
 private function getEditionParameters($save = Null)
 {
     // Get the project
     $project = $this->param('project');
     $repository = $this->param('repository');
     $layerId = $this->param('layerId');
     $featureIdParam = $this->param('featureId');
     if ($save) {
         $project = $this->param('liz_project');
         $repository = $this->param('liz_repository');
         $layerId = $this->param('liz_layerId');
         $featureIdParam = $this->param('liz_featureId');
     }
     if (!$project) {
         jMessage::add('The parameter project is mandatory !', 'ProjectNotDefind');
         return false;
     }
     // Get repository data
     $lrep = lizmap::getRepository($repository);
     $lproj = lizmap::getProject($repository . '~' . $project);
     // Redirect if no rights to access this repository
     if (!jAcl2::check('lizmap.repositories.view', $lrep->getKey())) {
         jMessage::add(jLocale::get('view~default.repository.access.denied'), 'AuthorizationRequired');
         return false;
     }
     // Redirect if no rights to use the edition tool
     if (!jAcl2::check('lizmap.tools.edition.use', $lrep->getKey())) {
         jMessage::add(jLocale::get('view~edition.access.denied'), 'AuthorizationRequired');
         return false;
     }
     $layerXml = $lproj->getXmlLayer($layerId);
     $layerXmlZero = $layerXml[0];
     $_layerName = $layerXmlZero->xpath('layername');
     $layerName = (string) $_layerName[0];
     // Verifying if the layer is edtable
     $eLayers = $lproj->getEditionLayers();
     if (!property_exists($eLayers, $layerName)) {
         jMessage::add('The layer is not editable!', 'LayerNotEditable');
         return false;
     }
     $eLayer = $eLayers->{$layerName};
     if ($eLayer->capabilities->modifyGeometry != "True" && $eLayer->capabilities->modifyAttribute != "True" && $eLayer->capabilities->deleteFeature != "True" && $eLayer->capabilities->createFeature != "True") {
         jMessage::add('The layer is not editable!', 'LayerNotEditable');
         return false;
     }
     // feature Id (optionnal, only for edition and save)
     if (preg_match('#,#', $featureIdParam)) {
         $featureId = preg_split('#,#', $featureIdParam);
     } else {
         $featureId = $featureIdParam;
     }
     // Define class private properties
     $this->project = $lproj;
     $this->repository = $lrep;
     $this->layerId = $layerId;
     $this->featureId = $featureId;
     $this->featureIdParam = $featureIdParam;
     $this->layerXml = $layerXml;
     $this->layerName = $layerName;
     // Optionnaly filter data by login
     if (!jAcl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey())) {
         $this->loginFilteredLayers = True;
     }
     $this->loginFilteredOveride = jacl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey());
     return true;
 }
 /**
  * Get parameters and set classes for the project and repository given.
  *
  * @param boolean $save If true, we have to save the form. So take liz_repository and others instead of repository from request parameters.
  * @return array List of needed variables : $params, $lizmapRepository, lizmapProject, etc.
  */
 private function getEditionParameters($save = Null)
 {
     // Get the project
     $project = $this->param('project');
     $repository = $this->param('repository');
     $layerId = $this->param('layerId');
     $featureIdParam = $this->param('featureId');
     if ($save) {
         $project = $this->param('liz_project');
         $repository = $this->param('liz_repository');
         $layerId = $this->param('liz_layerId');
         $featureIdParam = $this->param('liz_featureId');
     }
     if (!$project) {
         jMessage::add('The parameter project is mandatory !', 'ProjectNotDefined');
         return false;
     }
     // Get repository data
     $lrep = lizmap::getRepository($repository);
     if (!$lrep) {
         jMessage::add('The repository ' . strtoupper($repository) . ' does not exist !', 'RepositoryNotDefined');
         return false;
     }
     // Get the project data
     $lproj = null;
     try {
         $lproj = lizmap::getProject($repository . '~' . $project);
         if (!$lproj) {
             jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
             return false;
         }
     } catch (UnknownLizmapProjectException $e) {
         jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
         return false;
     }
     // Redirect if no rights to access this repository
     if (!$lproj->checkAcl()) {
         jMessage::add(jLocale::get('view~default.repository.access.denied'), 'AuthorizationRequired');
         return false;
     }
     // Redirect if no rights to use the edition tool
     if (!jAcl2::check('lizmap.tools.edition.use', $lrep->getKey())) {
         jMessage::add(jLocale::get('view~edition.access.denied'), 'AuthorizationRequired');
         return false;
     }
     $layerXml = $lproj->getXmlLayer($layerId);
     $layerXmlZero = $layerXml[0];
     $_layerName = $layerXmlZero->xpath('layername');
     $layerName = (string) $_layerName[0];
     // Verifying if the layer is editable
     $eLayers = $lproj->getEditionLayers();
     if (!property_exists($eLayers, $layerName)) {
         jMessage::add('The layer is not editable!', 'LayerNotEditable');
         return false;
     }
     $eLayer = $eLayers->{$layerName};
     if ($eLayer->capabilities->modifyGeometry != "True" && $eLayer->capabilities->modifyAttribute != "True" && $eLayer->capabilities->deleteFeature != "True" && $eLayer->capabilities->createFeature != "True") {
         jMessage::add('The layer is not editable!', 'LayerNotEditable');
         return false;
     }
     // feature Id (optional, only for edition and save)
     if (preg_match('#,#', $featureIdParam)) {
         $featureId = preg_split('#,#', $featureIdParam);
     } else {
         $featureId = $featureIdParam;
     }
     // Define class private properties
     $this->project = $lproj;
     $this->repository = $lrep;
     $this->layerId = $layerId;
     $this->featureId = $featureId;
     $this->featureIdParam = $featureIdParam;
     $this->layerXml = $layerXml;
     $this->layerName = $layerName;
     // Optionnaly filter data by login
     if (!jAcl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey())) {
         $this->loginFilteredLayers = True;
     }
     $this->loginFilteredOveride = jacl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey());
     // Get features primary key field values corresponding to featureId(s)
     if (!empty($featureId)) {
         $_datasource = $layerXmlZero->xpath('datasource');
         $datasource = (string) $_datasource[0];
         $s_provider = $layerXmlZero->xpath('provider');
         $this->provider = (string) $s_provider[0];
         $this->getDataFields($datasource);
         $typename = str_replace(' ', '_', $layerName);
         $wfsparams = array('SERVICE' => 'WFS', 'VERSION' => '1.0.0', 'REQUEST' => 'GetFeature', 'TYPENAME' => $typename, 'OUTPUTFORMAT' => 'GeoJSON', 'GEOMETRYNAME' => 'none', 'PROPERTYNAME' => implode(',', $this->primaryKeys), 'FEATUREID' => $typename . '.' . $featureId);
         $wfsrequest = new lizmapWFSRequest($lproj, $wfsparams);
         $wfsresponse = $wfsrequest->getfeature();
         if (property_exists($wfsresponse, 'data')) {
             $this->featureData = json_decode($wfsresponse->data);
             if (empty($this->featureData)) {
                 $this->featureData = Null;
             } else {
                 if (empty($this->featureData->features)) {
                     $this->featureData = Null;
                 }
             }
         }
     }
     return true;
 }