11 |
delphine |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Carto extends WidgetCommun {
|
|
|
4 |
|
|
|
5 |
const SERVICE_CARTO_NOM = 'carto';
|
|
|
6 |
const SERVICE_CARTO_ACTION_DEFAUT = 'carto';
|
|
|
7 |
|
|
|
8 |
private $carte;
|
|
|
9 |
private $source;
|
|
|
10 |
|
|
|
11 |
private $numeroTaxon;
|
|
|
12 |
private $utilisateur;
|
|
|
13 |
private $referentiel;
|
|
|
14 |
private $departement;
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Methode appelee par defaut pour executer ce widget
|
|
|
19 |
*/
|
|
|
20 |
public function executer() {
|
|
|
21 |
$retour = null;
|
|
|
22 |
// recuperer les parametres de l'URL
|
|
|
23 |
$this->extraireParametres();
|
|
|
24 |
// verifier la disponibilite des services et ressources demandees
|
|
|
25 |
$methode = $this->traiterNomMethodeExecuter($this->carte);
|
|
|
26 |
if (method_exists($this, $methode)) {
|
|
|
27 |
$retour = $this->$methode();
|
|
|
28 |
} else {
|
|
|
29 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
|
|
30 |
}
|
|
|
31 |
if (is_null($retour)) {
|
|
|
32 |
$info = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
33 |
$this->envoyer($info);
|
|
|
34 |
} else {
|
|
|
35 |
$squelette = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'squelettes' . DIRECTORY_SEPARATOR
|
|
|
36 |
. $retour['squelette'] . '.tpl.html';
|
|
|
37 |
$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
38 |
$this->envoyer($html);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function extraireParametres() {
|
|
|
43 |
extract($this->parametres);
|
|
|
44 |
$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT);
|
|
|
45 |
$this->source = (isset($source) ? $source : $this->config['carto']['sourceParDefaut']);
|
|
|
46 |
$this->numeroTaxon = (isset($num_taxon) ? $num_taxon : '*');
|
|
|
47 |
$this->departement = (isset($dept) ? $dept : '*');
|
|
|
48 |
$this->referentiel = (isset($referentiel) ? $referentiel : '*');
|
|
|
49 |
$this->utilisateur = (isset($utilisateur) ? $utilisateur : '*');
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Carte par défaut
|
|
|
54 |
*/
|
|
|
55 |
public function executerCarto() {
|
|
|
56 |
$widget = null;
|
|
|
57 |
$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
|
|
|
58 |
|
|
|
59 |
// Création des infos du widget
|
|
|
60 |
$widget['donnees']['url_serivce_carto'] = $this->contruireUrlServiceCarto();
|
|
|
61 |
$widget['donnees']['url_base'] = $url_base;
|
|
|
62 |
$widget['donnees']['source'] = $this->source;
|
|
|
63 |
$widget['donnees']['num_taxon'] = $this->numeroTaxon;
|
|
|
64 |
$widget['donnees']['utilisateur'] = $this->utilisateur;
|
|
|
65 |
$widget['donnees']['departement'] = $this->departement;
|
|
|
66 |
$widget['donnees']['referentiel'] = $this->referentiel;
|
|
|
67 |
|
|
|
68 |
$widget['donnees']['communeImageUrl'] = $this->config['carto']['communeImageUrl'];
|
|
|
69 |
$widget['donnees']['pointImageUrl'] = $this->config['carto']['pointImageUrl'];
|
|
|
70 |
$widget['donnees']['liensVersSources'] = $this->config['carto']['liensVersSources'];
|
|
|
71 |
$widget['donnees']['sourcesDispo'] = $this->config['carto']['sourcesDispo'];
|
|
|
72 |
$widget['donnees']['nomSourcesDispo'] = $this->config['carto']['nomSourcesDispo'];
|
|
|
73 |
$widget['donnees']['titreLegende'] = $this->config['carto']['titreLegende'];
|
|
|
74 |
$widget['donnees']['url_limites_communales'] = $this->obtenirUrlsLimitesCommunales();
|
|
|
75 |
|
|
|
76 |
$widget['squelette'] = 'carto';
|
|
|
77 |
return $widget;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
private function contruireUrlServiceCarto($action = null) {
|
|
|
81 |
// Création url données json
|
|
|
82 |
$url = sprintf($this->config['chemins']['baseURLServicesTpl'], '');
|
|
|
83 |
if ($action) {
|
|
|
84 |
$url .= "/$action";
|
|
|
85 |
|
|
|
86 |
$parametres_retenus = array();
|
|
|
87 |
$parametres_a_tester = array('source', 'utilisateur', 'referentiel', 'dept', 'num_taxon');
|
|
|
88 |
foreach ($parametres_a_tester as $param) {
|
|
|
89 |
if (isset($this->$param) && $this->$param != '*') {
|
|
|
90 |
$parametres_retenus[$param] = $this->$param;
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
if (count($parametres_retenus) > 0) {
|
|
|
94 |
$parametres_url = array();
|
|
|
95 |
foreach ($parametres_retenus as $cle => $valeur) {
|
|
|
96 |
$parametres_url[] = $cle.'='.$valeur;
|
|
|
97 |
}
|
|
|
98 |
$url .= '?'.implode('&', $parametres_url);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return $url;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
private function obtenirUrlsLimitesCommunales() {
|
|
|
105 |
$urls = null;
|
|
|
106 |
if (isset($this->departement)) {
|
|
|
107 |
// si on veut afficher les limites départementales on va compter et chercher les noms de fichiers
|
|
|
108 |
$fichiersKml = $this->chercherFichierKml();
|
|
|
109 |
if (count($fichiersKml) > 0) {
|
|
|
110 |
foreach ($fichiersKml as $kml => $dossier){
|
|
|
111 |
$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);
|
|
|
112 |
$urls[] = $url_limites_communales;
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
$urls = json_encode($urls);
|
|
|
117 |
return $urls;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
private function chercherFichierKml(){
|
|
|
121 |
$fichiers = array();
|
|
|
122 |
$chemins = explode(',', $this->config['carto']['communesKmzChemin']);
|
|
|
123 |
$departements = explode(',', $this->departement);// plrs code de départements peuvent être demandés séparés par des virgules
|
|
|
124 |
$departements_trouves = array();
|
|
|
125 |
foreach ($chemins as $dossier_chemin) {
|
|
|
126 |
if ($dossier_ressource = opendir($dossier_chemin)) {
|
|
|
127 |
while ($element = readdir($dossier_ressource)) {
|
|
|
128 |
if ($element != '.' && $element != '..') {
|
|
|
129 |
foreach ($departements as $departement) {
|
|
|
130 |
$nom_dossier = basename($dossier_chemin);
|
|
|
131 |
if (!isset($departements_trouves[$departement]) || $departements_trouves[$departement] == $nom_dossier) {
|
|
|
132 |
$dept_protege = preg_quote($departement);
|
|
|
133 |
if (!is_dir($dossier_chemin.'/'.$element) && preg_match("/^$dept_protege(?:_[0-9]+|)\.km[lz]$/", $element)) {
|
|
|
134 |
$fichiers[$element] = $nom_dossier;
|
|
|
135 |
$departements_trouves[$departement] = $nom_dossier;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
closedir($dossier_ressource);
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
return $fichiers;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
?>
|