Subversion Repositories eFlore/Applications.coel

Rev

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