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