Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] AtlasPrint Listener not enough specific #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions cadastre/classes/atlasPrint.listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ class atlasPrintListener extends jEventListener
*/
public function onBeforePdfCreation($event)
{
$cadastreConfig = array();
$profile = 'cadastre';
$services = lizmap::getServices();
if (version_compare($services->qgisServerVersion, '3.0', '<')) {
if (!preg_match('#^cadastre#i', $event->project)) {
return null;
}
$cadastreConfig = array(
'layer' => 'Parcelles',
'pk' => 'geo_parcelle',
);
Comment on lines +24 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (version_compare($services->qgisServerVersion, '3.0', '<')) {
if (!preg_match('#^cadastre#i', $event->project)) {
return null;
}
$cadastreConfig = array(
'layer' => 'Parcelles',
'pk' => 'geo_parcelle',
);

If this code is for QGIS server < 3.0, this must be removed.

Related to #94

} else {
$config = cadastreConfig::get($event->repository, $event->project);
if ($config == null) {
return null;
}
$cadastreConfig = array(
'layer' => $config->parcelle->name,
'pk' => $config->parcelle->unique_field,
);
if ($config->parcelle->shortName && strlen($config->parcelle->shortName)) {
$cadastreConfig['layer'] = $config->parcelle->shortName;
}
$profile = cadastreProfile::getWithLayerId(
$event->repository,
$event->project,
$config->parcelle->id
);
}

try {
// try to get the specific search profile to do not rebuild it
jProfiles::get('jdb', $profile, true);
} catch (Exception $e) {
return null;
}

$status = 'error';
$file = null;

Expand All @@ -35,7 +72,7 @@ public function onBeforePdfCreation($event)

$layer = $params['layer'];
$exp_filter = $params['exp_filter'];
if (!$layer or $layer != 'Parcelles' or !$exp_filter) {
if (!$layer or $layer != $cadastreConfig['layer'] or !$exp_filter) {
$event->add(
array('status' => $status, 'file' => $file)
);
Expand All @@ -49,9 +86,18 @@ public function onBeforePdfCreation($event)
$get_fid = preg_match('(\d+)', $exp_filter, $match);
$fid = intval($match[0]);

if ($fid > 0) {
if ($fid < 1) {
$event->add(
array('status' => $status, 'file' => $file)
);

return null;
}

// Try to get data from geo_commune
try {
$sql = 'SELECT geo_parcelle FROM parcelle_info WHERE ogc_fid = ' . $fid;
$cnx = jDb::getConnection('cadastre');
$cnx = jDb::getConnection($profile);
$result = $cnx->query($sql);
$geo_parcelle = -1;
foreach ($result as $line) {
Expand Down Expand Up @@ -103,6 +149,8 @@ public function onBeforePdfCreation($event)
// \jLog::log($path);
$file = $path;
$status = 'success';
} catch (Exception $e) {
jLog::log("Cadastre :: " . $e->getMessage());
}

$event->add(
Expand Down
72 changes: 57 additions & 15 deletions cadastre/classes/cadastreConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,67 @@ class cadastreConfig
public static function get($repository, $project)
{
$p = lizmap::getProject($repository . '~' . $project);
if ($p) {
$request = new lizmapCadastreRequest(
$p,
array(
'service' => 'CADASTRE',
'version' => '1.0.0',
'request' => 'GetCapabilities',
)
);
$result = $request->process();
if ($result->code === 200 && $result->mime !== 'text/xml') {
$data = json_decode($result->data);
if ($data->status == 'success') {
return $data->data;
if (!$p) {
return null;
}
$customVariables = $p->getCustomProjectVariables();
if (!$customVariables) {
return null;
}
if (!array_key_exists('cadastre_parcelle_layer_id', $customVariables)
|| !array_key_exists('cadastre_parcelle_unique_field', $customVariables)) {
return null;
}

$parcelleLayerId = $customVariables['cadastre_parcelle_layer_id'];
$parcelleLayerUniqueField = $customVariables['cadastre_parcelle_unique_field'];

$parcelleLayer = $p->getLayer($parcelleLayerId);
if (!$parcelleLayer) {
return null;
}

$capabilities = array(
'parcelle' => array(
'id' => $parcelleLayerId,
'name' => $parcelleLayer->getName(),
'title' => $parcelleLayer->getTitle(),
'shortName' => $parcelleLayer->getShortName(),
'unique_field' => $customVariables['cadastre_parcelle_unique_field'],
),
);

if (array_key_exists('cadastre_section_layer_id', $customVariables)) {
$layer = $p->getLayer($customVariables['cadastre_section_layer_id']);
if ($layer) {
$capabilities['section'] = array(
'id' => $layer->getId(),
'name' => $layer->getName(),
'title' => $layer->getTitle(),
'shortName' => $layer->getShortName(),
);
if (array_key_exists('cadastre_section_unique_field', $customVariables)) {
$capabilities['section']['unique_field'] = $customVariables['cadastre_section_unique_field'];
}
}
}

return null;
if (array_key_exists('cadastre_commune_layer_id', $customVariables)) {
$layer = $p->getLayer($customVariables['cadastre_commune_layer_id']);
if ($layer) {
$capabilities['commune'] = array(
'id' => $layer->getId(),
'name' => $layer->getName(),
'title' => $layer->getTitle(),
'shortName' => $layer->getShortName(),
);
if (array_key_exists('cadastre_commune_unique_field', $customVariables)) {
$capabilities['commune']['unique_field'] = $customVariables['cadastre_commune_unique_field'];
}
}
}

return (object) $capabilities;
}

public static function getLayerSql($repository, $project, $layerId)
Expand Down
Loading