Subversion Repositories eFlore/Applications.coel

Rev

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