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