diff --git a/cadastre/classes/cadastreConfig.class.php b/cadastre/classes/cadastreConfig.class.php index 38d65dc..5fb0d7e 100644 --- a/cadastre/classes/cadastreConfig.class.php +++ b/cadastre/classes/cadastreConfig.class.php @@ -82,6 +82,27 @@ public static function getFilterByLogin($repository, $project, $layerId) return $loginFilterConfig; } + public static function getLoginFilter($repository, $project, $layerId) + { + if (jAuth::isConnected() && jAcl2::check('lizmap.tools.loginFilteredLayers.override', $repository)) { + return null; + } + + $p = lizmap::getProject($repository . '~' . $project); + + $qgisLayer = $p->getLayer($layerId); + if (!$qgisLayer) { + return null; + } + + $loginFilterObj = $p->getLoginFilter($qgisLayer->getName()); + if (!empty($loginFilterObj) && array_key_exists('filter', $loginFilterObj)) { + return $loginFilterObj['filter']; + } + + return null; + } + public static function getPolygonFilter($repository, $project, $layerId) { if (jAuth::isConnected() && jAcl2::check('lizmap.tools.loginFilteredLayers.override', $repository)) { diff --git a/cadastre/classes/listParcelleLieuDatasource.class.php b/cadastre/classes/listParcelleLieuDatasource.class.php index 9b09a1f..5cd1d17 100644 --- a/cadastre/classes/listParcelleLieuDatasource.class.php +++ b/cadastre/classes/listParcelleLieuDatasource.class.php @@ -50,26 +50,23 @@ public function getData($form) $layerConditions = null; $layerSql = cadastreConfig::getLayerSql($repository, $project, $config->parcelle->id); $polygonFilter = cadastreConfig::getPolygonFilter($repository, $project, $config->parcelle->id); - if ($layerSql !== null && $polygonFilter !== null) { - $layerConditions .= '(' . $layerSql . ') AND (' . $polygonFilter . ')'; - } elseif ($layerSql !== null) { - $layerConditions = $layerSql; - } elseif ($polygonFilter !== null) { - $layerConditions = $polygonFilter; + $loginFilter = cadastreConfig::getLoginFilter($repository, $project, $config->parcelle->id); + $layerFilters = array(); + if ($layerSql !== null) { + $layerFilters[] = $layerSql; } - $fblConfig = cadastreConfig::getFilterByLogin($repository, $project, $config->parcelle->id); - - if ($fblConfig !== null) { - $filterValues = array('all'); - if (jAuth::isConnected()) { - if (property_exists($fblConfig, 'filterPrivate') && $fblConfig->filterPrivate == 'True') { - $user = jAuth::getUserSession(); - $filterValues[] = $user->login; - } else { - $filterValues = array_merge($filterValues, jAcl2DbUserGroup::getGroups()); - } + if ($polygonFilter !== null) { + $layerFilters[] = $polygonFilter; + } + if ($loginFilter !== null) { + $layerFilters[] = $loginFilter; + } + if (count($layerFilters) != 0) { + if (count($layerFilters) == 1) { + $layerConditions = $layerFilters[0]; + } else { + $layerConditions = '(' . implode(') AND (', $layerFilters) . ')'; } - $searchConditions->addCondition($fblConfig->filterAttribute, 'IN', $filterValues); } foreach ((array) $this->labelProperty as $property) {