Subversion Repositories eFlore/Applications.cel

Rev

Rev 698 | Rev 837 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 698 Rev 836
Line 29... Line 29...
29
 * @version	$Id$
29
 * @version	$Id$
30
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
30
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
31
 */
31
 */
32
class Carto extends WidgetCommun {
32
class Carto extends WidgetCommun {
33
	const DS = DIRECTORY_SEPARATOR;
33
	const DS = DIRECTORY_SEPARATOR;
-
 
34
	const SERVICE_CARTO_NOM = 'CelWidgetMap';
34
	const SERVICE_DEFAUT = 'carte-defaut';
35
	const SERVICE_CARTO_ACTION_DEFAUT = 'carte-defaut';
-
 
36
	
-
 
37
	private $carte = null;
-
 
38
	private $utilisateur = null;
-
 
39
	private $projet = null;
-
 
40
	private $dept = null;
-
 
41
	private $num_taxon = null;
-
 
42
	private $station = null;
-
 
43
	private $format = null;// Format des obs pour les stations (tableau/liste)
Line 35... Line 44...
35
	
44
	
36
	/**
45
	/**
37
	 * Méthode appelée par défaut pour charger ce widget.
46
	 * Méthode appelée par défaut pour charger ce widget.
38
	 */
47
	 */
39
	public function executer() {
48
	public function executer() {
40
		$retour = null;
49
		$retour = null;
Line 41... Line -...
41
		extract($this->parametres);
-
 
42
 
-
 
43
		if (!isset($carte)) {
-
 
44
			$carte = self::SERVICE_DEFAUT;
-
 
45
		}
50
		$this->extraireParametres();
46
		
51
 
47
		$methode = $this->traiterNomMethodeExecuter($carte);
52
		$methode = $this->traiterNomMethodeExecuter($this->carte);
48
		if (method_exists($this, $methode)) {
53
		if (method_exists($this, $methode)) {
49
			$retour = $this->$methode();
54
			$retour = $this->$methode();
50
		} else {
55
		} else {
Line 58... Line 63...
58
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
63
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
59
			$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
64
			$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
60
			$this->envoyer($html);
65
			$this->envoyer($html);
61
		}
66
		}
62
	}
67
	}
-
 
68
	
-
 
69
	public function extraireParametres() {
-
 
70
		extract($this->parametres);
-
 
71
		$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT);
-
 
72
		$this->utilisateur = (isset($utilisateur) ? $utilisateur : '*');
-
 
73
		$this->projet = (isset($projet) ? $projet : '*');
-
 
74
		$this->dept = (isset($dept) ? $dept : '*');
-
 
75
		$this->num_taxon = (isset($num_taxon) ? $num_taxon : '*');
-
 
76
		$this->station = (isset($station) ? $station : null);
-
 
77
		$this->format = (isset($format) ? $format : null);
-
 
78
	}
Line 63... Line 79...
63
 
79
 
64
	/**
80
	/**
65
	 * Carte par défaut
81
	 * Carte par défaut
66
	 */
82
	 */
67
	public function executerCarteDefaut() {
83
	public function executerCarteDefaut() {
68
		$widget = null;
-
 
69
		extract($this->parametres);
-
 
70
		$utilisateur = (isset($utilisateur) ? $utilisateur : '*');
-
 
71
		$projet = (isset($projet) ? $projet : '*');
-
 
72
		$dept = (isset($dept) ? $dept : '*');
-
 
73
		$num_taxon = (isset($num_taxon) ? $num_taxon : '*');
-
 
74
		
-
 
75
		// Création url données json
84
		$widget = null;
76
		$url_cel_carto = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelWidgetMap');
-
 
77
		$url_json = "$url_cel_carto/carte-defaut-json/$utilisateur/$projet/$dept/$num_taxon";
-
 
78
		
85
		$url_json = $this->contruireUrlServiceCarto('carte-defaut-json');
Line 79... Line 86...
79
		$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
86
		$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
80
 
87
 
81
		// Création des infos du widget
88
		// Création des infos du widget
82
		$widget['donnees']['url_cel_carto'] = $url_cel_carto;
89
		$widget['donnees']['url_cel_carto'] = $this->contruireUrlServiceCarto();
83
		$widget['donnees']['url_json'] = $url_json;
-
 
84
		$widget['donnees']['url_base'] = $url_base;
90
		$widget['donnees']['url_json'] = $url_json;
85
		$widget['donnees']['jquery_version'] = '1.4.4';
91
		$widget['donnees']['url_base'] = $url_base;
86
		$widget['donnees']['utilisateur'] = $utilisateur;
92
		$widget['donnees']['utilisateur'] = $this->utilisateur;
87
		$widget['donnees']['projet'] = $projet;
93
		$widget['donnees']['projet'] = $this->projet;
88
		$widget['donnees']['dept'] = $dept;
94
		$widget['donnees']['dept'] = $this->dept;
89
		$widget['donnees']['num_taxon'] = $num_taxon;
95
		$widget['donnees']['num_taxon'] = $this->num_taxon;
90
		$widget['donnees']['taxons'] = $this->chargerTaxons();
96
		$widget['donnees']['taxons'] = $this->chargerTaxons();
91
		if ($num_taxon != '*') {
97
		if ($this->num_taxon != '*') {
92
			$taxon_courrant = current($widget['donnees']['taxons']);
98
			$taxon_courrant = current($widget['donnees']['taxons']);
93
			$widget['donnees']['taxon_nom'] = $taxon_courrant['nom'];
99
			$widget['donnees']['taxon_nom'] = $taxon_courrant['nom'];
Line 94... Line 100...
94
		}
100
		}
95
		$widget['squelette'] = 'carte_defaut';
101
		$widget['squelette'] = 'carte_defaut';
96
		
102
		
-
 
103
		if (isset($this->dept)) {
97
		if (isset($dept)) {
104
			// si on veut afficher les limites départemmentales on va compter et chercher les noms de fichiers
98
			// si on veut afficher les limites départemmentales on va compter et chercher les noms de fichiers
105
			$fichiersKml = $this->chercherFichierKml();
99
			$fichiersKml = $this->chercherFichierKml($dept);
106
			$urls = null;
100
			foreach ($fichiersKml as $kml => $dossier){
107
			foreach ($fichiersKml as $kml => $dossier){
-
 
108
				$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);
101
				$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);
109
				$urls[] = $url_limites_communales;
Line 102... Line 110...
102
				$widget['donnees']['url_limites_communales'][] = $url_limites_communales;
110
			}
103
			}
111
			$widget['donnees']['url_limites_communales'] = json_encode($urls);
Line -... Line 112...
-
 
112
		}
-
 
113
		
-
 
114
		return $widget;
-
 
115
	}
-
 
116
	
-
 
117
	private function contruireUrlServiceCarto($action = null) {
-
 
118
		// Création url données json
-
 
119
		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::SERVICE_CARTO_NOM);
-
 
120
		if ($action) {
-
 
121
			$url .= "/$action";
-
 
122
			
-
 
123
			$parametres_retenus = array();
-
 
124
			$parametres_a_tester = array('station', 'utilisateur', 'projet', 'dept', 'num_taxon');
-
 
125
			foreach ($parametres_a_tester as $param) {
-
 
126
				if ($this->$param != null && $this->$param != '*') {
-
 
127
					$parametres_retenus[$param] = $this->$param;
-
 
128
				}
-
 
129
			}
-
 
130
			if (count($parametres_retenus) > 0) {
-
 
131
				$parametres_url = array();
-
 
132
				foreach ($parametres_retenus as $cle => $valeur) {
-
 
133
					$parametres_url[] = $cle.'='.$valeur;
-
 
134
				}
-
 
135
				$url .= '?'.implode('&', $parametres_url);
-
 
136
			}
-
 
137
		}
104
		}
138
		$this->debug[] = $url;
105
		
-
 
106
		return $widget;
-
 
107
	}
-
 
108
	
-
 
109
	private function chargerTaxons() {
-
 
110
		extract($this->parametres);
-
 
111
		$utilisateur = (isset($utilisateur) ? $utilisateur : '*');
139
		// Prendre en compte param "station"
112
		$projet = (isset($projet) ? $projet : '*');
-
 
113
		$dept = (isset($dept) ? $dept : '*');
140
		return $url; 
114
		$num_taxon = (isset($num_taxon) ? $num_taxon : '*');
141
	}
115
		
142
	
Line 116... Line 143...
116
		// Récupération des données au format Json
143
	private function chargerTaxons() {
117
		$service = "CelWidgetMap/taxons/$utilisateur/$projet/$dept/$num_taxon";
144
		// Récupération des données au format Json
Line 140... Line 167...
140
			}
167
			}
141
		}
168
		}
142
		return $taxons;
169
		return $taxons;
143
	}
170
	}
Line 144... Line 171...
144
	
171
	
145
	private function chercherFichierKml($dept){
172
	private function chercherFichierKml(){
146
		$chemins = explode(',', $this->config['carto']['communesKmzChemin']);
173
		$chemins = explode(',', $this->config['carto']['communesKmzChemin']);
147
		$departements = explode(',', $dept);// plrs code de départements peuvent être demandés séparés par des virgules
174
		$departements = explode(',', $this->dept);// plrs code de départements peuvent être demandés séparés par des virgules
148
		$departements_trouves = array();
175
		$departements_trouves = array();
149
		$fichiers = array();
176
		$fichiers = array();
150
		foreach ($chemins as $dossier_chemin) {
177
		foreach ($chemins as $dossier_chemin) {
151
			if ($dossier_ressource = opendir($dossier_chemin)) {
178
			if ($dossier_ressource = opendir($dossier_chemin)) {
Line 173... Line 200...
173
	/**
200
	/**
174
	 * Tableau des observations d'une station
201
	 * Tableau des observations d'une station
175
	 */
202
	 */
176
	public function executerObservations() {
203
	public function executerObservations() {
177
		$widget = null;
204
		$widget = null;
178
		extract($this->parametres);
-
 
179
		
-
 
180
		$observations = $this->chargerObservation($station);
205
		$observations = $this->chargerObservation();
Line 181... Line 206...
181
				
206
				
182
		// Création des infos du widget
207
		// Création des infos du widget
183
		if (isset($observations['commune'])) {
208
		if (isset($observations['commune'])) {
184
			$commune = $observations['commune'];
209
			$commune = $observations['commune'];
Line 196... Line 221...
196
		if ($widget['squelette'] == 'obs_liste' && $obs_ids != null && count($obs_ids) > 0) {
221
		if ($widget['squelette'] == 'obs_liste' && $obs_ids != null && count($obs_ids) > 0) {
197
			$widget['donnees']['images'] = $this->chargerImages($obs_ids);
222
			$widget['donnees']['images'] = $this->chargerImages($obs_ids);
198
		}
223
		}
Line 199... Line 224...
199
		
224
		
200
		$widget['donnees']['observations'] = $observations;
225
		$widget['donnees']['observations'] = $observations;
Line 201... Line 226...
201
		$widget['donnees']['station_id'] = $station;
226
		$widget['donnees']['station_id'] = $this->station;
202
		
227
		
Line 203... Line 228...
203
		return $widget;
228
		return $widget;
204
	}
-
 
205
	
-
 
206
	private function chargerObservation($station) {
-
 
207
		extract($this->parametres);
-
 
208
		$utilisateur = (isset($utilisateur) ? $utilisateur : '*');
-
 
209
		$projet = (isset($projet) ? $projet : '*');
-
 
210
		$dept = (isset($dept) ? $dept : '*');
229
	}
211
		$num_taxon = (isset($num_taxon) ? $num_taxon : '*');
-
 
212
		
230
	
213
		// Récupération des données au format Json
231
	private function chargerObservation() {
214
		$service = "CelWidgetMap/observations/$station/$utilisateur/$projet/$dept/$num_taxon";
232
		// Récupération des données au format Json
Line 215... Line 233...
215
		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
233
		$url = $this->contruireUrlServiceCarto('observations');
216
		$json = $this->getDao()->consulter($url);
234
		$json = $this->getDao()->consulter($url);
Line 252... Line 270...
252
		}
270
		}
253
		return implode(', ', $lieu);
271
		return implode(', ', $lieu);
254
	}
272
	}
Line 255... Line 273...
255
	
273
	
256
	private function choisirFormatSortie($observations_nbre) {
-
 
257
		extract($this->parametres);
274
	private function choisirFormatSortie($observations_nbre) {
258
		$sortie = 'obs_tableau';
275
		$sortie = 'obs_tableau';
259
		if (isset($format) && $format != '*') {
276
		if (isset($this->format) && $this->format != '*') {
260
			$sortie = ($format == 'tableau' ) ? 'obs_tableau' : 'obs_liste';
277
			$sortie = ($this->format == 'tableau' ) ? 'obs_tableau' : 'obs_liste';
261
		} else {
278
		} else {
262
			$sortie = ($observations_nbre > 4) ? 'obs_tableau' : 'obs_liste';
279
			$sortie = ($observations_nbre > 4) ? 'obs_tableau' : 'obs_liste';
263
		}
280
		}
264
		return $sortie;
281
		return $sortie;
Line 265... Line 282...
265
	}
282
	}
266
	
283
	
267
	private function chargerImages($obs_ids) {
284
	private function chargerImages($obs_ids) {
268
		// Récupération des données au format Json
285
		// Récupération des données au format Json
-
 
286
		$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
269
		$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids);
287
		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
270
		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service);
288
		$this->debug[] = $url;
Line 271... Line 289...
271
		$json = $this->getDao()->consulter($url);
289
		$json = $this->getDao()->consulter($url);
272
		$donnees = json_decode($json);
290
		$donnees = json_decode($json);