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