Subversion Repositories eFlore/Applications.cel

Rev

Rev 1123 | Rev 1215 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1123 Rev 1209
Line 19... Line 19...
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
20
 */
20
 */
21
class Saisie extends WidgetCommun {
21
class Saisie extends WidgetCommun {
Line 22... Line 22...
22
 
22
 
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'biodiversite34';
24
	const PROJET_DEFAUT = 'defaut';
-
 
25
	const WS_SAISIE = "CelWidgetSaisie";
-
 
26
	const WS_NOM = "noms";
-
 
27
	const NS_PROJET = "bdtfx";
Line 25... Line 28...
25
	const WS_SAISIE = "CelWidgetSaisie";
28
	const EFLORE_API_VERSION = "0.1";
26
 
29
 
Line 27... Line 30...
27
	private $projet = null;
30
	private $projet = null;
Line 32... Line 35...
32
	 */
35
	 */
33
	public function executer() {
36
	public function executer() {
34
		$retour = null;
37
		$retour = null;
35
		extract($this->parametres);
38
		extract($this->parametres);
Line 36... Line -...
36
 
-
 
37
		if (!isset($projet)) {
39
 
38
			$this->projet = self::PROJET_DEFAUT;
-
 
39
		} else {
-
 
40
			$this->projet = $projet;
-
 
41
		}
40
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
Line 42... Line 41...
42
		$this->chargerConfigProjet();
41
		$this->chargerConfigProjet();
43
 
42
 
44
		$service = (isset($service)) ? $service : $this->projet;
43
		$service = isset($service) ? $service : 'widget';
45
		$methode = $this->traiterNomMethodeExecuter($service);
44
		$methode = $this->traiterNomMethodeExecuter($service);
46
		if (method_exists($this, $methode)) {
45
		if (method_exists($this, $methode)) {
47
			$retour = $this->$methode();
46
			$retour = $this->$methode();
Line 75... Line 74...
75
		} else {
74
		} else {
76
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
75
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
77
		}
76
		}
78
	}
77
	}
Line -... Line 78...
-
 
78
 
-
 
79
	public function executerWidget() {
-
 
80
		$widget['squelette'] = $this->projet;
-
 
81
		$widget['donnees'] = array();
-
 
82
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
83
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
84
 
-
 
85
		if ($this->projet == 'defaut') {
-
 
86
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
-
 
87
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, self::NS_PROJET, self::WS_NOM);
-
 
88
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
-
 
89
		} else {
-
 
90
			$widget['donnees']['taxons'] = $this->recupererListeTaxon();
-
 
91
			$widget['donnees']['milieux'] = $this->parserMilieux();
-
 
92
		}
-
 
93
		return  $widget;
-
 
94
	}
79
 
95
 
80
	public function executerTaxons() {
96
	public function executerTaxons() {
81
		$widget['squelette'] = $this->projet.'_taxons';
97
		$widget['squelette'] = $this->projet.'_taxons';
82
		$widget['squelette_ext'] = '.tpl.js';
98
		$widget['squelette_ext'] = '.tpl.js';
83
		$widget['donnees'] = array();
-
 
84
		$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet))));
99
		$widget['donnees'] = array();
85
		$taxons = $this->$methode();
100
		$taxons = $this->recupererListeTaxon();
86
		$taxons_tries = array();
101
		$taxons_tries = array();
87
		foreach ($taxons as $taxon) {
102
		foreach ($taxons as $taxon) {
88
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
103
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
89
		}
104
		}
90
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
105
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
91
		return  $widget;
106
		return  $widget;
Line -... Line 107...
-
 
107
	}
-
 
108
 
-
 
109
	private function recupererListeTaxon() {
-
 
110
		$taxons = null;
-
 
111
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
-
 
112
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
113
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
114
		} else {
-
 
115
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
116
		}
-
 
117
		$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
-
 
118
		return $taxons_tries;
-
 
119
	}
-
 
120
 
-
 
121
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
-
 
122
		$header = NULL;
-
 
123
		$data = array();
-
 
124
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
-
 
125
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
-
 
126
				if (!$header) {
-
 
127
					$header = $row;
-
 
128
				} else {
-
 
129
					$data[] = array_combine($header, $row);
-
 
130
				}
-
 
131
			}
-
 
132
			fclose($handle);
-
 
133
		}
-
 
134
		return $data;
-
 
135
	}
-
 
136
 
-
 
137
	private function parserMilieux() {
-
 
138
		$infosMilieux = array();
-
 
139
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
140
		foreach ($milieux as $milieu) {
-
 
141
			$details = explode(';', $milieu);
-
 
142
			if (isset($details[1])) {
-
 
143
				$infosMilieux[$details[0]] = $details[1];
-
 
144
			} else {
-
 
145
				$infosMilieux[$details[0]] = '';
-
 
146
			}
-
 
147
		}
-
 
148
		ksort($infosMilieux);
-
 
149
		return $infosMilieux;
92
	}
150
	}
93
 
151
 
94
	public function executerUploadImage() {
152
	public function executerUploadImage() {
95
		$retour = array(
153
		$retour = array(
96
			'squelette' => $this->projet.'_image',
154
				'squelette' => $this->projet.'_image',
Line 169... Line 227...
169
		// Retour des infos
227
		// Retour des infos
170
		$retour['donnees']['message'] = $message;
228
		$retour['donnees']['message'] = $message;
171
		$retour['donnees']['debogage'] = $debogage;
229
		$retour['donnees']['debogage'] = $debogage;
172
		return $retour;
230
		return $retour;
173
	}
231
	}
174
 
-
 
175
	public function executerBiodiversite34() {
-
 
176
		$widget['squelette'] = $this->projet;
-
 
177
		$widget['donnees'] = array();
-
 
178
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
179
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
180
 
-
 
181
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
-
 
182
		$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34();
-
 
183
		return  $widget;
-
 
184
	}
-
 
185
 
-
 
186
	private function parserMilieuxBiodiversite34() {
-
 
187
		$infosMilieux = array();
-
 
188
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
189
		foreach ($milieux as $milieu) {
-
 
190
			$details = explode(';', $milieu);
-
 
191
			if (isset($details[1])) {
-
 
192
				$infosMilieux[$details[0]] = $details[1];
-
 
193
			} else {
-
 
194
				$infosMilieux[$details[0]] = '';
-
 
195
			}
-
 
196
		}
-
 
197
		ksort($infosMilieux);
-
 
198
		return $infosMilieux;
-
 
199
	}
-
 
200
 
-
 
201
	private function recupererListeTaxonBiodiversite34() {
-
 
202
		$taxons = null;
-
 
203
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
-
 
204
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
205
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
206
		} else {
-
 
207
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
208
		}
-
 
209
 
-
 
210
		$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
-
 
211
 
-
 
212
		return $taxons_tries;
-
 
213
	}
-
 
214
 
-
 
215
	public function executerSauvages() {
-
 
216
		$widget['squelette'] = $this->projet;
-
 
217
		$widget['donnees'] = array();
-
 
218
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
219
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
220
 
-
 
221
		$widget['donnees']['taxons'] = $this->recupererListeTaxonSauvages();
-
 
222
		$widget['donnees']['milieux'] = $this->parserMilieuxSauvages();
-
 
223
		return  $widget;
-
 
224
	}
-
 
225
 
-
 
226
	private function parserMilieuxSauvages() {
-
 
227
		$infosMilieux = array();
-
 
228
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
229
		foreach ($milieux as $milieu) {
-
 
230
			$details = explode(';', $milieu);
-
 
231
			if (isset($details[1])) {
-
 
232
				$infosMilieux[$details[0]] = $details[1];
-
 
233
			} else {
-
 
234
				$infosMilieux[$details[0]] = '';
-
 
235
			}
-
 
236
		}
-
 
237
		return $infosMilieux;
-
 
238
	}
-
 
239
 
-
 
240
	private function recupererListeTaxonSauvages() {
-
 
241
		$taxons = null;
-
 
242
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'sauvages_taxons.tsv';
-
 
243
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
244
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
245
		} else {
-
 
246
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
247
		}
-
 
248
		return $taxons;
-
 
249
	}
-
 
250
 
-
 
251
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
-
 
252
		$header = NULL;
-
 
253
	    $data = array();
-
 
254
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
-
 
255
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
-
 
256
	            if (!$header) {
-
 
257
	                $header = $row;
-
 
258
	            } else {
-
 
259
	                $data[] = array_combine($header, $row);
-
 
260
	            }
-
 
261
	        }
-
 
262
	        fclose($handle);
-
 
263
	    }
-
 
264
	    return $data;
-
 
265
	}
-
 
266
}
232
}
267
233
?>
-
 
234
268
235