Subversion Repositories eFlore/Applications.coel

Rev

Rev 1697 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1646 alex 1
<?php
2
 
3
class CartoDepartement extends WidgetCommun {
4
 
5
	const SERVICE_CARTO_NOM           = 'cartoDepartement';
6
	const SERVICE_CARTO_ACTION_DEFAUT = 'cartoDepartement';
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 : '*');
41
	}
42
 
43
	/**
44
	 * Carte par défaut
45
	 */
46
	public function executerCartoDepartement() {
47
		$widget = null;
48
 
49
		// Création des infos du widget
50
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
51
		$widget['donnees']['url_web_service'] = sprintf($this->config['chemins']['baseURLServicesTpl'], '');
52
		$widget['donnees']['url_page_fiche']  = $this->config['carto']["urlPageFiche"];
53
		$widget['donnees']['departement'] = $this->departement;
54
		$widget['squelette'] = 'carto_departement';
55
		return $widget;
56
	}
57
 
58
	private function contruireUrlService() {
59
		// Création url données json
60
		$url = sprintf($this->config['chemins']['baseURLServicesTpl'], '');
61
		if ($action) {
62
			$url .= "/$action";
63
 
64
			$parametres_retenus = array();
65
			$parametres_a_tester = array('dept');
66
			foreach ($parametres_a_tester as $param) {
67
				if (isset($this->$param) && $this->$param != '*') {
68
					$parametres_retenus[$param] = $this->$param;
69
				}
70
			}
71
			if (count($parametres_retenus) > 0) {
72
				$parametres_url = array();
73
				foreach ($parametres_retenus as $cle => $valeur) {
74
					$parametres_url[] = $cle.'='.$valeur;
75
				}
76
				$url .= '?'.implode('&', $parametres_url);
77
			}
78
		}
79
		return $url;
80
	}
81
 
82
	private function obtenirUrlsLimitesCommunales() {
83
		$urls = null;
84
		if (isset($this->departement)) {
85
			// si on veut afficher les limites départementales on va compter et chercher les noms de fichiers
86
			$fichiersKml = $this->chercherFichierKml();
87
			if (count($fichiersKml) > 0) {
88
				foreach ($fichiersKml as $kml => $dossier){
89
					$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);
90
					$urls[] = $url_limites_communales;
91
				}
92
			}
93
		}
94
		$urls = json_encode($urls);
95
		return $urls;
96
	}
97
 
98
	private function chercherFichierKml(){
99
		$fichiers = array();
100
		$chemins = explode(',', $this->config['carto']['communesKmzChemin']);
101
		$departements = explode(',', $this->departement);// plrs code de départements peuvent être demandés séparés par des virgules
102
		$departements_trouves = array();
103
		foreach ($chemins as $dossier_chemin) {
104
			if ($dossier_ressource = opendir($dossier_chemin)) {
105
				while ($element = readdir($dossier_ressource)) {
106
					if ($element != '.' && $element != '..') {
107
						foreach ($departements as $departement) {
108
							$nom_dossier = basename($dossier_chemin);
109
							if (!isset($departements_trouves[$departement]) || $departements_trouves[$departement] == $nom_dossier) {
110
								$dept_protege = preg_quote($departement);
111
								if (!is_dir($dossier_chemin.'/'.$element) && preg_match("/^$dept_protege(?:_[0-9]+|)\.kml$/", $element)) {
112
									$fichiers[$element] = $nom_dossier;
113
									$departements_trouves[$departement] = $nom_dossier;
114
								}
115
							}
116
						}
117
					}
118
				}
119
				closedir($dossier_ressource);
120
			}
121
		}
122
 
123
		return $fichiers;
124
	}
125
 
126
}
127
 
128
?>