Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 465 Rev 471
Line 17... Line 17...
17
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
17
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @version $Id$
18
 * @version $Id$
19
 * @copyright © 2010, Jean-Pascal MILCENT
19
 * @copyright © 2010, Jean-Pascal MILCENT
20
 */
20
 */
21
class Carto extends WidgetCommun {
21
class Carto extends WidgetCommun {
22
	const limitesCommunalesDossier = "http://www.tela-botanica.org/sites/eflore/generique/images/projets/cel/cartographie";
22
	const LIMITES_COMMUNALES_URL = "http://www.tela-botanica.org/sites/eflore/generique/images/projets/cel/cartographie/%s";
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
-
 
24
	const SERVICE_DEFAUT = 'carte-defaut';
Line 24... Line 25...
24
	
25
	
25
	/**
26
	/**
26
	 * Méthode appelée avec une requête de type GET.
27
	 * Méthode appelée avec une requête de type GET.
27
	 */
28
	 */
28
	public function executer() {
29
	public function executer() {
29
		$retour = null;
30
		$retour = null;
Line 30... Line 31...
30
		extract($this->parametres);
31
		extract($this->parametres);
31
 
-
 
32
		if (isset($carte)) {
-
 
33
			$methode = $this->traiterNomMethodeExecuter($carte);
32
 
34
			if (method_exists($this, $methode)) {
-
 
35
				$retour = $this->$methode();
-
 
36
			} else {
-
 
37
				$this->messages[] = "Ce type de carte '$methode' n'est pas disponible.";
-
 
38
			}
-
 
39
		} else {
33
		if (!isset($methode)) {
Line -... Line 34...
-
 
34
			$methode = self::SERVICE_DEFAUT;
-
 
35
		}
-
 
36
		
-
 
37
		$methode = $this->traiterNomMethodeExecuter($carte);
-
 
38
		if (method_exists($this, $methode)) {
-
 
39
			$retour = $this->$methode();
Line 40... Line 40...
40
			$this->messages[] = "Vous devez indiquer le type de carte.";
40
		} else {
41
		}
41
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
42
		
42
		}
43
 
43
 
Line 64... Line 64...
64
		$url_json .= (isset($utilisateur) ? $utilisateur : '*');
64
		$url_json .= (isset($utilisateur) ? $utilisateur : '*');
Line 65... Line 65...
65
 
65
 
Line 66... Line 66...
66
		$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
66
		$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
67
 
-
 
68
		// Création des infos du widget
67
 
69
		$widget['type'] = 'widget';
68
		// Création des infos du widget
-
 
69
		$widget['donnees']['url_json'] = $url_json;
70
		$widget['donnees']['url_json'] = $url_json;
70
		$widget['donnees']['url_base'] = $url_base;
Line 71... Line 71...
71
		$widget['donnees']['url_base'] = $url_base;
71
		$widget['donnees']['jquery_version'] = '1.4.3';
72
		$widget['squelette'] = 'carte_defaut';
72
		$widget['squelette'] = 'carte_defaut';
73
		
73
		
74
		if (isset($dept)) {
74
		if (isset($dept)) {
75
			// si on veut afficher les limites départemmentales on va compter et chercher les noms de fichiers
75
			// si on veut afficher les limites départemmentales on va compter et chercher les noms de fichiers
76
			$fichiersKml = $this->chercherFichierKml($dept);
-
 
77
			foreach ($fichiersKml as $kml){
76
			$fichiersKml = $this->chercherFichierKml($dept);
78
				$url_limites_communales = sprintf(self::limitesCommunalesDossier, '');
77
			foreach ($fichiersKml as $kml){
79
				$url_limites_communales .= '/'.$kml;
78
				$url_limites_communales = sprintf(self::LIMITES_COMMUNALES_URL, $kml);
Line 80... Line 79...
80
				$widget['donnees']['url_limites_communales'][] = $url_limites_communales;
79
				$widget['donnees']['url_limites_communales'][] = $url_limites_communales;
Line 96... Line 95...
96
			}
95
			}
97
		}
96
		}
Line 98... Line 97...
98
		
97
		
99
		closedir($dir);
98
		closedir($dir);
-
 
99
		return $fichier;
-
 
100
	}
-
 
101
	
-
 
102
	
-
 
103
	/**
-
 
104
	 * Tableau des observations d'une station
-
 
105
	 */
-
 
106
	public function executerObservations() {
-
 
107
		$widget = null;
-
 
108
		extract($this->parametres);
-
 
109
		
-
 
110
		$observations = $this->chargerObservation($station);
-
 
111
		$commune = $observations['commune'];
-
 
112
		unset($observations['commune'])
-
 
113
		;
-
 
114
		// Création des infos du widget
-
 
115
		$widget['donnees']['observations'] = $observations;
-
 
116
		$widget['donnees']['station_id'] = $station;
-
 
117
		$widget['donnees']['commune'] = $commune;
-
 
118
		
-
 
119
		$widget['squelette'] = $this->choisirFormatSortie(count($observations));
-
 
120
		
-
 
121
		return $widget;
-
 
122
	}
-
 
123
	
-
 
124
	private function chargerObservation($station) {
-
 
125
		// Récupération des données au format Json
-
 
126
		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], "CelWidgetMap/observations/$station");
-
 
127
		$json = $this->getDao()->envoyerRequeteConsultation($url);
Line -... Line 128...
-
 
128
		$donnees = json_decode($json);
-
 
129
		
-
 
130
		// Post-traitement des données
-
 
131
		$observations = $this->traiterObservations($donnees);
-
 
132
		
-
 
133
		return $observations;
-
 
134
	}
-
 
135
	
-
 
136
	private function traiterObservations($donnees) {
-
 
137
		$observations = array();
-
 
138
		if (is_array($donnees) && count($donnees) > 0) {
-
 
139
			foreach ($donnees as $donnee) {
-
 
140
				$observation = array();
-
 
141
				$observation['nn'] = $donnee->num_nom_sel;
-
 
142
				$observation['nom'] = $this->nettoyerTexte($donnee->nom_sel);
-
 
143
				$observation['date'] = $this->traiterDate($donnee->date_observation);
-
 
144
				$observation['lieu'] = $this->traiterLieu($donnee);
-
 
145
				$observation['observateur'] = $this->tronquerCourriel($donnee->identifiant);
-
 
146
				
-
 
147
				$observations[] = $observation;
-
 
148
				$observations['commune'] = $this->nettoyerTexte($donnee->location);
-
 
149
			}
-
 
150
		}
-
 
151
		return $observations;
-
 
152
	}
-
 
153
	
-
 
154
	private function traiterDate($date) {
-
 
155
		$date_timestamp = strtotime($date);
-
 
156
		$date_traitee = strftime('%d/%m/%Y', $date_timestamp);
-
 
157
		return $date_traitee;
-
 
158
	}
-
 
159
	
-
 
160
	private function traiterLieu($donnee) {
-
 
161
		$lieu = array();
-
 
162
		if (isset($donnee->location) && ! empty($donnee->location)) {
-
 
163
			$lieu[] = $donnee->location;
-
 
164
		}
-
 
165
		if (isset($donnee->lieudit) && ! empty($donnee->lieudit)) {
-
 
166
			$lieu[] = $donnee->lieudit;
-
 
167
		}
-
 
168
		if (isset($donnee->milieu) && ! empty($donnee->milieu)) {
-
 
169
			$lieu[] = $donnee->milieu;
100
		return $fichier;
170
		}
-
 
171
		return implode(', ', $lieu);
-
 
172
	}
-
 
173
	
-
 
174
	private function choisirFormatSortie($observations_nbre) {
-
 
175
		extract($this->parametres);
-
 
176
		$sortie = 'obs_tableau';
-
 
177
		if (isset($format)) {
-
 
178
			$sortie = ($format == 'tableau' ) ? 'obs_tableau' : 'obs_liste';
-
 
179
		} else {
-
 
180
			$sortie = ($observations_nbre > 4) ? 'obs_tableau' : 'obs_liste';
-
 
181
		}
-
 
182
		return $sortie;
101
		
183
	}
102
	}
184