Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 152 Rev 160
Line 131... Line 131...
131
	public function traiterRessources() {
131
	public function traiterRessources() {
132
		if (isset($this->ressources) && !empty($this->ressources)) {
132
		if (isset($this->ressources) && !empty($this->ressources)) {
133
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
133
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
134
				$this->traiterRessourceId(); // ajoute condition id=#valeur
134
				$this->traiterRessourceId(); // ajoute condition id=#valeur
135
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
135
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
136
					$this->traiterRessourceChampOuRelations(); //modifie requete_champ ou requete_condition
136
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
137
				}
137
				}
138
			}
138
			}
139
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
139
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
140
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
140
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
141
		}
141
		}
Line 144... Line 144...
144
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
144
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
145
	public function traiterRessourceId() {
145
	public function traiterRessourceId() {
146
		if (is_numeric($this->ressources[0])) {
146
		if (is_numeric($this->ressources[0])) {
147
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
147
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
148
			$this->format_reponse .= '/id';
148
			$this->format_reponse .= '/id';
-
 
149
		} elseif ($this->ressources[0] == 'attributions') {
-
 
150
			$this->format_reponse .= '/attributions';
149
		} else {
151
		} else {
150
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
152
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
151
				' " n\'existe pas.';
153
				' " n\'existe pas.';
152
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
154
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
153
		}
155
		}
154
	}
156
	}
Line 155... Line 157...
155
 
157
 
156
 
-
 
157
	public function traiterRessourceChampOuRelations() {
-
 
158
		//requete = /noms-vernaculaires/#id/relations :
-
 
159
		if ($this->ressources[1] == 'relations') {
-
 
160
			$this->format_reponse .= '/relations';
-
 
161
			$this->requete_condition[] = 'num_taxon = (SELECT region FROM '.$this->table.' WHERE '
-
 
162
										.implode(' AND ', $this->requete_condition).')';
-
 
163
		//requete = /noms-vernaculaires/#id/#champ :
158
 
164
		} else {
159
	public function traiterRessourceChamp() {
165
			$this->format_reponse .= '/champ';
-
 
166
			$this->analyserChamp();
160
		$this->format_reponse .= '/champ';
Line 167... Line 161...
167
		}
161
		$this->analyserChamp();
168
	}
162
	}
169
 
163
 
Line 227... Line 221...
227
		return $this->requete_limite;
221
		return $this->requete_limite;
228
	}
222
	}
Line 229... Line 223...
229
 
223
 
230
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
224
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
-
 
225
	public function recupererTotalResultat() {
231
	public function recupererTotalResultat() {
226
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
232
		$requete = 'SELECT count(distinct(id)) as nombre FROM '
227
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
233
			.$this->table
228
			.$this->table
234
			.$this->formerRequeteCondition();
229
			.$this->formerRequeteCondition();
Line 235... Line 230...
235
		$res = $this->getBdd()->recuperer($requete);
230
		$res = $this->getBdd()->recuperer($requete);
236
 
231
 
237
		if ($res) {
232
		if ($res) {
238
			$total = $res['nombre'];
233
			$total = $res['nombre'];
239
		} else {
234
		} else {
240
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base';
235
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
241
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
236
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
242
		}
237
		}
Line 249... Line 244...
249
	public function retournerResultatFormate($resultat) {
244
	public function retournerResultatFormate($resultat) {
250
		$this->recupererTableConfig('correspondance_champs');
245
		$this->recupererTableConfig('correspondance_champs');
251
		switch ($this->format_reponse) {
246
		switch ($this->format_reponse) {
252
			case 'noms-vernaculaires'				: 
247
			case 'noms-vernaculaires'				: 
253
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
248
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
-
 
249
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
254
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
250
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
255
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
251
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
256
			default									:																	break;
252
			default									:																	break;
257
		}
253
		}
258
		return $reponse;
254
		return $reponse;
259
	}
255
	}
Line 260... Line 256...
260
 
256
 
261
	public function formaterNomsVernaculaires($resultat) {
257
	public function formaterNomsVernaculaires($resultat) {
262
		//on remplit la table $table_retour_json['entete']
258
		//on remplit la table $table_retour_json['entete']
263
		$table_retour_json['entete']['masque'] = implode('&', $this->parametres);
259
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
264
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
260
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
265
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
261
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
266
		$table_retour_json['entete']['total']  = $this->total_resultat;
262
		$table_retour_json['entete']['total']  = $this->total_resultat;
267
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
263
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
268
		if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
264
		if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
269
		if (isset($url['suivant']) && $url['suivant']   != '') { $table_retour_json['entete']['href.suivant']   = $url['suivant']; }
265
		if (isset($url['suivant']) && $url['suivant']   != '') { $table_retour_json['entete']['href.suivant']   = $url['suivant']; }
270
 
266
		
271
		//on remplit la table $table_retour_json['resultat']
267
		//on remplit la table $table_retour_json['resultat']
272
		if (isset($this->parametres['masque.nv'])) {
268
		if (isset($this->parametres['masque.nv'])) {
273
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
269
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
274
		}
270
		}
Line 292... Line 288...
292
 
288
 
293
		$table_retour_json['resultat'] = $resultat_json;
289
		$table_retour_json['resultat'] = $resultat_json;
294
		return $table_retour_json;
290
		return $table_retour_json;
Line -... Line 291...
-
 
291
	}
-
 
292
	
-
 
293
	public function recupererMasque() {
-
 
294
		$tab_masque = array();
-
 
295
		foreach ($this->parametres as $param=>$valeur) {
-
 
296
			if (strstr($param, 'masque') != false) {
-
 
297
				$tab_masque[] = $param.'='.$valeur;
-
 
298
			}
-
 
299
		}
-
 
300
		$masque = implode('&', $tab_masque);
-
 
301
		return $masque;
295
	}
302
	}
296
	
303
	
297
	public function formaterEnOss($resultat) {
304
	public function formaterEnOss($resultat) {
298
		$table_nom = array();
305
		$table_nom = array();
299
		$oss = '';
306
		$oss = '';
Line 308... Line 315...
308
		if (isset($this->masque)) $masque = implode('&', $this->masque);
315
		if (isset($this->masque)) $masque = implode('&', $this->masque);
309
		else $masque = 'Pas de masque';
316
		else $masque = 'Pas de masque';
310
		$table_retour_oss = array($masque, $oss);
317
		$table_retour_oss = array($masque, $oss);
311
		return $table_retour_oss;
318
		return $table_retour_oss;
312
	}
319
	}
-
 
320
	
-
 
321
	public function formaterNomsVernaculairesAttributions($resultat) {
-
 
322
		//on remplie la table $table_retour_json['entete']
-
 
323
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
-
 
324
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
-
 
325
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
-
 
326
		$table_retour_json['entete']['total']  = $this->total_resultat;
-
 
327
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
-
 
328
		if (isset($url['precedent']) && $url['precedent'] != '') {
-
 
329
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
-
 
330
		}
-
 
331
		if (isset($url['suivant']) && $url['suivant']   != '') {
-
 
332
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
-
 
333
		}
-
 
334
	
-
 
335
		//on remplie la table $table_retour_json['resultat']
-
 
336
		if (isset($this->parametres['masque.nv'])) {
-
 
337
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
-
 
338
		}
-
 
339
		if (isset($this->parametres['masque'])) {
-
 
340
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
-
 
341
		}
-
 
342
		foreach ($resultat as $tab) {
-
 
343
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
-
 
344
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
-
 
345
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
-
 
346
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
-
 
347
			if ($this->retour_format == 'max') {
-
 
348
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
-
 
349
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
-
 
350
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
-
 
351
			}
-
 
352
		}
-
 
353
		
-
 
354
		if ($this->retour_format == 'max') {
-
 
355
			$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
-
 
356
		}
-
 
357
		
-
 
358
		$table_retour_json['resultat'] = $resultat_json;
-
 
359
		return $table_retour_json;
-
 
360
	}
-
 
361
	
-
 
362
	public function afficherTaxonsAttributions($resultat) {
-
 
363
		$nom_sci = $this->recupererNomTaxons();
-
 
364
		foreach ($resultat as $num=>$tab) {
-
 
365
			if (isset($nom_sci[$tab['taxon']])) {
-
 
366
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']];
-
 
367
			}
-
 
368
		}
-
 
369
		return $resultat;
-
 
370
	}
313
 
371
	
314
	// formatage de la reponse /id ss la forme
372
	// formatage de la reponse /id ss la forme
315
	// id, nom_vernaculaire, attributions
373
	// id, nom_vernaculaire, attributions
316
	// langue
374
	// langue
317
	// num_nom (correspond à un taxon bdtfx)
375
	// num_nom (correspond à un taxon bdtfx)
318
	public function formaterNomsVernaculairesId($resultat) {
376
	public function formaterNomsVernaculairesId($resultat) {
Line 393... Line 451...
393
		}
451
		}
394
		return $valeur;
452
		return $valeur;
395
	}
453
	}
Line 396... Line 454...
396
 
454
 
397
	public function afficherTaxons() {
-
 
398
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.$this->getBdd()->proteger(implode(',', $this->taxons));
455
	public function afficherTaxons() {
399
		$res = $this->consulterHref($url);
-
 
400
		foreach ($res->resultat as $id=>$taxon) {
-
 
401
			$resultat[$id] = $taxon->nom_sci;
-
 
402
		}
456
		$resultat = $this->recupererNomTaxons();
403
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
457
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
404
			foreach ($langue as $num_nom=>$taxon) {
458
			foreach ($langue as $num_nom=>$taxon) {
405
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
459
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
406
				if (isset($resultat[$num_tax])) {
460
				if (isset($resultat[$num_tax])) {
407
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax];
461
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax];
408
				}
462
				}
409
			}
463
			}
410
		}
464
		}
-
 
465
	}
-
 
466
	
-
 
467
	public function recupererNomTaxons() {
-
 
468
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.
-
 
469
			$this->getBdd()->proteger(implode(',', $this->taxons));
-
 
470
		$res = $this->consulterHref($url);
-
 
471
		foreach ($res->resultat as $id=>$taxon) {
-
 
472
			$resultat[$taxon->num_taxonomique] = $taxon->nom_sci;
-
 
473
		}
-
 
474
		return $resultat;
Line 411... Line 475...
411
	}
475
	}
412
 
476
 
413
	public function formaterNomsVernaculairesIdChamp($resultat) {
477
	public function formaterNomsVernaculairesIdChamp($resultat) {
414
		$this->table_retour['id'] = $this->ressources[0];
478
		$this->table_retour['id'] = $this->ressources[0];
415
		$champs = explode(' ', $this->ressources[1]);
479
		$champs = explode(' ', $this->ressources[1]);
416
		if (in_array('attributions', $champs) != false) {
480
		if (in_array('attributions', $champs) != false) {
417
			$this->formaterNomsVernaculairesId($resultat);
481
			$this->formaterNomsVernaculairesId($resultat);
418
			unset($this->table_retour['nom_vernaculaire']);
482
			unset($this->table_retour['nom_vernaculaire']);
419
		} else {//print_r($resultat);
483
		} else {
420
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
484
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
421
			foreach ($resultat as $taxon) {
485
			foreach ($resultat as $taxon) {
422
				foreach ($taxon as $key=>$valeur) {
486
				foreach ($taxon as $key=>$valeur) {