Subversion Repositories eFlore/Applications.coel

Rev

Rev 1788 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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