Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 932 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
721 aurelien 1
<?php
2
/**
3
* Description :
4
* Classe NomsVernaculaires.php fournit une liste de noms vernaculaires et leur liaison à la bdtxa
5
* Le but étant de fournir un ensemble minimal d'information comprenant :
6
* un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
7
* une relation avec un taxon de la bdtxa.
8
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
9
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
10
*
11
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
12
* distinct, retour.format, navigation.depart et navigation.limite.
13
*
14
* Encodage en entrée : utf8
15
* Encodage en sortie : utf8
16
* @package framework-v3
17
* @author Delphine Cauquil <delphine@tela-botanica.org>
18
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
19
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
* @version 1.0
22
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
23
*/
24
class NomsVernaculaires extends Commun {
25
	protected $champ_infos = array(
26
			'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtxa', 'nom' => 'nom_sci'));
27
 
28
	protected $service = 'noms-vernaculaires';
29
 
30
	/**
31
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
32
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
33
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
34
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
35
	protected $format_reponse = 'noms-vernaculaires';
36
 
37
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
38
	 * selon ressources et paramètres */
39
	protected $requete_champ = array(' * ');
40
	protected $requete_condition = '';
41
	protected $limite_requete = array(
42
		'depart' => 0,
43
		'limite' => 100
44
	);
45
 
46
	protected $champ_tri = 'code_langue';
47
	protected $direction_tri = 'asc';
48
 
49
	/**
50
	 * Indique les champs supplémentaires à retourner
51
	 *  - conseil_emploi = conseil d'emploi du nom vernaculaire
52
	 *  - genre = genre et nombre du nom
53
	 *  - taxon = nom retenu associé à ce nom
54
	 */
55
	protected $champs_supp = array();
56
 
57
	/**
58
	 * Precise la contenance plus ou moins précise du tableau à retourner :
59
	 *  - min = les données présentes dans la table
60
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
61
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
62
	protected $retour_format = 'max';
63
	/** Valeur du paramètre de requete recherche :
64
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
65
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
66
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
67
	protected $recherche;
68
 
69
	/** Permet de stocker le tableau de résultat (non encodé en json) */
70
	protected $table_retour = array();
71
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
72
	protected $total_resultat;
73
 
74
	private $config;
75
 
76
	public function __construct($config) {
77
		$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
78
	}
79
 
80
	//+------------------------------------------------------------------------------------------------------+
81
	// créer une condition en fonction du paramétre
82
	public function traiterParametres() {
83
		if (isset($this->parametres) && !empty($this->parametres)) {
84
 
85
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
86
				$this->recherche = $this->parametres['recherche'];
87
			}
88
			foreach ($this->parametres as $param => $valeur) {
89
				switch ($param) {
90
					case 'masque' :
91
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
92
						break;
93
					case 'masque.nt' :
94
						$this->ajouterFiltreMasque('num_taxon', $valeur);
95
						break;
96
					case 'masque.nv' :
97
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
98
						break;
99
					case 'masque.lg' :
100
						$this->ajouterFiltreMasque('code_langue', $valeur);
101
						break;
102
					case 'retour.format' :
103
						$this->retour_format = $valeur;
104
						break;
105
					case 'navigation.depart' :
106
						$this->limite_requete['depart'] = $valeur;
107
						break;
108
					case 'navigation.limite' :
109
						$this->limite_requete['limite'] = $valeur;
110
						break;
111
					case 'retour.champs' :
112
						$this->champs_supp = explode(',',$valeur);
113
					break;
114
					case 'recherche' :
115
						break;
116
					case 'version.projet' :
117
						break;
118
					default :
119
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
120
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
121
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
122
				}
123
			}
124
		}
125
	}
126
 
127
	public function ajouterFiltreMasque($nom_champ, $valeur) {
128
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
129
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
130
		} else {
131
			if ($this->recherche == 'floue') {
132
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
133
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
134
			} else {
135
				if ($this->recherche == 'etendue') {
136
					$valeur = '%'.str_replace(' ','% ', $valeur);
137
					$valeur .= '%';
138
				}
139
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
140
			}
141
		}
142
	}
143
 
144
	//+------------------------------------------------------------------------------------------------------+
145
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
146
	public function traiterRessources() {
147
		if (isset($this->ressources) && !empty($this->ressources)) {
148
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
149
				$this->traiterRessourceId(); // ajoute condition id=#valeur
150
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
151
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
152
				}
153
			}
154
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
155
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
156
		}
157
	}
158
 
159
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
160
	public function traiterRessourceId() {
161
		if (is_numeric($this->ressources[0])) {
162
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
163
			$this->format_reponse .= '/id';
164
		} elseif ($this->ressources[0] == 'attributions') {
165
			$this->format_reponse .= '/attributions';
166
		} else {
167
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
168
				' " n\'existe pas.';
169
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
170
		}
171
	}
172
 
173
 
174
	public function traiterRessourceChamp() {
175
		$this->format_reponse .= '/champ';
176
		$this->analyserChamp();
177
	}
178
 
179
	public function analyserChamp() {
180
		$this->requete_champ = array();
181
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
182
		$champs = explode(' ', $this->ressources[1]);
183
		foreach ($champs as $champ) {
184
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
185
			if (isset($this->champs_possibles[$match[1]])) {
186
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
187
			} elseif (isset($this->champs_possibles[$match[0]])) {
188
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
189
			} else {
190
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
191
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
192
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
193
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
194
			}
195
		}
196
	}
197
 
198
	//+------------------------------------------------------------------------------------------------------+
199
	public function assemblerLaRequete() {
200
		$requete = ' SELECT '.$this->formerRequeteChamp().
201
					', CASE code_langue WHEN "fra" THEN 1 ELSE 0 END AS tri '.
202
					' FROM '.$this->table
203
					.$this->formerRequeteCondition().
204
					' ORDER BY tri DESC, nom_vernaculaire ASC '
205
					.$this->formerRequeteLimite();
206
		return $requete;
207
	}
208
 
209
	public  function formerRequeteChamp() {
210
		if (in_array('*', $this->requete_champ)) {
211
			$champ = ' * ';
212
		} else {
213
			$champ = implode(', ', $this->requete_champ);
214
		}
215
		return $champ;
216
	}
217
 
218
	public  function formerRequeteCondition() {
219
		$condition = '';
220
		if ($this->requete_condition != null) {
221
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
222
		}
223
		return $condition;
224
	}
225
 
226
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
227
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
228
	public function formerRequeteLimite() {
229
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
230
			$this->requete_limite = '';
231
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
232
			$this->limite_requete['depart'] =
233
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
234
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
235
		} else {
236
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
237
		}
238
		return $this->requete_limite;
239
	}
240
 
241
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
242
	public function recupererTotalResultat() {
243
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct id ';
244
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
245
			.$this->table
246
			.$this->formerRequeteCondition();
247
		$res = $this->getBdd()->recuperer($requete);
248
 
249
		if ($res) {
250
			$total = $res['nombre'];
251
		} else {
252
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
253
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
254
		}
255
		return $total;
256
	}
257
 
258
	//+------------------------------------------------------------------------------------------------------+
259
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
260
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
261
	public function retournerResultatFormate($resultat) {
262
		$this->recupererTableConfig('correspondance_champs');
263
		switch ($this->format_reponse) {
264
			case 'noms-vernaculaires'				:
265
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
266
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
267
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
268
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
269
			default									:																	break;
270
		}
271
		return $reponse;
272
	}
273
 
274
	public function ajouterJsonEnTeteNV() {
275
		$table_retour_json['masque'] = $this->recupererMasque();
276
		$table_retour_json['depart'] = $this->limite_requete['depart'];
277
		$table_retour_json['limite'] = $this->limite_requete['limite'];
278
		$table_retour_json['total']  = $this->total_resultat;
279
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
280
		if (isset($url['precedent']) && $url['precedent'] != '') {
281
			$table_retour_json['href.precedent'] = $url['precedent'];
282
		}
283
		if (isset($url['suivant']) && $url['suivant']   != '') {
284
			$table_retour_json['href.suivant']   = $url['suivant'];
285
		}
286
		return $table_retour_json;
287
	}
288
 
289
	public function ajouterJsonResultatNV($resultat) {
290
		foreach ($resultat as $tab) {
291
			foreach ($tab as $key => $valeur) {
292
				if ($valeur != '') {
293
					switch ($key) {
294
						case 'id'				: $num = $valeur;								break;
295
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
296
						default					:												break;
297
					}
298
				}
299
			}
300
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
301
			$resultat_json[$num] = $this->table_retour;
302
			$this->table_retour = array();
303
		}
304
		return  $resultat_json;
305
	}
306
 
307
 
308
	public function formaterNomsVernaculaires($resultat) {
309
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
310
		$resultat = $this->hierarchiserResultat($resultat);
311
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
312
		return $table_retour_json;
313
	}
314
 
315
	public function hierarchiserResultat($resultat) {
316
		//tri recherche floue
317
		if (isset($this->parametres['masque.nv'])) {
318
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
319
		}
320
		if (isset($this->parametres['masque'])) {
321
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
322
		}
323
		return $resultat;
324
	}
325
 
326
	public function recupererMasque() {
327
		$tab_masque = array();
328
		foreach ($this->parametres as $param=>$valeur) {
329
			if (strstr($param, 'masque') != false) {
330
				$tab_masque[] = $param.'='.$valeur;
331
			}
332
		}
333
		$masque = implode('&', $tab_masque);
334
		return $masque;
335
	}
336
 
337
	public function formaterEnOss($resultat) {
338
		$table_nom = array();
339
		$oss = '';
340
		foreach ($resultat as $tab) {
341
			if (isset($tab['nom_vernaculaire']) ) {
342
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
343
					$table_nom[] = $tab['nom_vernaculaire'];
344
					$oss [] = $tab['nom_vernaculaire'];
345
				}
346
			}
347
		}
348
		if (isset($this->masque)) $masque = implode('&', $this->masque);
349
		else $masque = 'Pas de masque';
350
		$table_retour_oss = array($masque, $oss);
351
		return $table_retour_oss;
352
	}
353
 
354
	public function formaterNomsVernaculairesAttributions($resultat) {
355
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
356
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
357
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
358
		$table_retour_json['entete']['total']  = $this->total_resultat;
359
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
360
		if (isset($url['precedent']) && $url['precedent'] != '') {
361
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
362
		}
363
		if (isset($url['suivant']) && $url['suivant']   != '') {
364
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
365
		}
366
		foreach ($resultat as &$tab) {
367
			unset($tab['tri']);
368
			$resultat_json[$tab['id']]['id'] = $tab['id'];
369
			$resultat_json[$tab['id']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
370
			$resultat_json[$tab['id']]['code_langue'] = $tab['code_langue'];
371
			$resultat_json[$tab['id']]['taxon.code'] = 'bdtxa.nt:'.$tab['num_taxon'];
372
			if ($this->retour_format == 'max') {
373
				$resultat_json[$tab['id']]['num_taxon'] = $tab['num_taxon'];
374
				$resultat_json[$tab['id']]['nom_retenu.code'] = $tab['num_taxon'];
375
				$resultat_json[$tab['id']]['taxon'] = $tab['num_taxon'];
376
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
377
				$resultat_json[$tab['id']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
378
 
379
				if($this->champs_supp != array()) {
380
					$resultat_json[$tab['id']] = $this->ajouterChampsOntologieLigneResultat($tab);
381
				}
382
			}
383
		}
384
 
385
		if ($this->retour_format == 'max') {
386
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
387
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
388
			$noms_sci = $this->recupererNomTaxons();
389
			foreach ($resultat_json as $num_nom => &$tab) {
390
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
391
				if($tab == null) {
392
					unset($resultat_json[$num_nom]);
393
				}
394
			}
395
		}
396
 
397
		$table_retour_json['resultat'] = $resultat_json;
398
		return $table_retour_json;
399
	}
400
 
401
	/**
402
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
403
	 * en faisant appels aux web services associés
404
	 * @param array $ligne_resultat
405
	 *
406
	 * @return array la ligne modifiée
407
	 */
408
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
409
 
410
		$intitule = '';
411
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
412
			if(in_array($cle, $this->champs_supp)) {
413
				extract($champs_supplementaires);
414
				$valeur_recherche = '';
415
				switch($cle) {
416
					case 'taxon':
417
						$valeur_recherche = $ligne_resultat['num_taxon'];
418
						$intitule = 'taxon.code';
419
						break;
420
				}
421
				$code_valeur = '';
422
				if(trim($valeur_recherche) != '') {
423
					$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
424
					$code_valeur = $this->chercherSignificationCode($url, $nom);
425
				}
426
				$ligne_resultat[$intitule] = $code_valeur;
427
			}
428
		}
429
		return $ligne_resultat;
430
	}
431
 
432
	/**
433
	 * Fonction qui ajoute les attributions à une ligne de résultats
434
	 *
435
	 * @param array $ligne_tableau_resultat
436
	 * @param array $nom_sci
437
	 */
438
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
439
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
440
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
441
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
442
		} else {
443
			$ligne_tableau_resultat = null;
444
		}
445
		return $ligne_tableau_resultat;
446
	}
447
 
448
	private function trierLigneTableau($a, $b) {
449
		$retour = 0;
450
 
451
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
452
			$retour = 0;
453
		}
454
 
455
		if($this->champ_tri == 'code_langue') {
456
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
457
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
458
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
459
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
460
			} else {
461
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
462
			}
463
		} else {
464
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
465
		}
466
		return $retour;
467
	}
468
 
469
	private function comparerChaineSelonDirectionTri($a, $b) {
470
		if($this->direction_tri == 'asc') {
471
			return ($a < $b) ? -1 : 1;
472
		} else {
473
			return ($a > $b) ? -1 : 1;
474
		}
475
	}
476
 
477
	// formatage de la reponse /id ss la forme
478
	// id, nom_vernaculaire, attributions
479
	// langue
480
	// num_nom (correspond à un taxon bdtxa)
481
	public function formaterNomsVernaculairesId($resultat) {
482
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtxa
483
			// on crée les variables qui serviront de clés et on les enléves du tableau
484
			$num_nom = $taxon['id']; // unique pour un trinôme id, langue, taxon
485
			unset($taxon['id']);
486
			$langue = $taxon['code_langue'];
487
			unset($taxon['code_langue']);
488
 
489
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
490
				if (isset($taxon[$key]) && $taxon[$key] != "") {
491
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
492
				}
493
			}
494
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
495
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
496
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
497
				}
498
			}
499
		}
500
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
501
		unset($this->table_retour['href']);
502
		return $this->table_retour;
503
	}
504
 
505
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
506
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
507
			$this->table_retour[$champ] = $valeur;
508
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
509
				switch ($match[1]) {
510
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
511
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
512
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
513
						break;
514
					default : break;
515
				}
516
 
517
		} elseif ($langue != '') {
518
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
519
		} else {
520
			$this->table_retour[$champ] = $valeur;
521
		}
522
	}
523
 
524
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
525
		if (isset($this->champ_infos[$nomChamp])) {
526
			extract($this->champ_infos[$nomChamp]);
527
		}
528
 
529
		if ($this->retour_format == 'max') {
530
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
531
			if ($service == 'taxons') {
532
				$code_valeur = '';
533
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
534
			} else {
535
				$code_valeur = $this->chercherSignificationCode($url, $nom);
536
			}
537
			if ($projet != '') $projet .= '.';
538
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
539
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
540
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
541
		} else {
542
			if ($projet != '') $projet .= '.';
543
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
544
		}
545
	}
546
 
547
	public function chercherSignificationCode($url, $nom) {
548
		if (isset($this->signification_code[$url])) {
549
			$valeur = $this->signification_code[$url];
550
		} else {
551
			$res = $this->consulterHref($url);
552
			$valeur = $res->$nom;
553
			$this->signification_code[$url] = $valeur;
554
		}
555
		return $valeur;
556
	}
557
 
558
	public function afficherTaxons() {
559
		$resultat = $this->recupererNomTaxons();
560
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
561
			foreach ($langue as $num_nom=>$taxon) {
562
				$num_tax = ltrim($taxon['taxon.code'], 'bdtxa.nt:');
563
				if (isset($resultat[$num_tax])) {
564
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
565
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
566
				}
567
			}
568
		}
569
	}
570
 
571
	public function recupererNomTaxons() {
572
		$taxons = array_unique($this->taxons);
573
		$url = Config::get('url_service_base').'bdtxa/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
574
		$res = $this->consulterHref($url);
575
		foreach ($res->resultat as $id=>$taxon) {
576
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtxa.nn:'.$id;
577
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
578
		}
579
		return $resultat;
580
	}
581
 
582
	public function formaterNomsVernaculairesIdChamp($resultat) {
583
		$this->table_retour['id'] = $this->ressources[0];
584
		$champs = explode(' ', $this->ressources[1]);
585
		if (in_array('attributions', $champs) != false) {
586
			$this->formaterNomsVernaculairesId($resultat);
587
			unset($this->table_retour['nom_vernaculaire']);
588
		} else {
589
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
590
			foreach ($resultat as $taxon) {
591
				foreach ($taxon as $key=>$valeur) {
592
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
593
						$this->table_retour['attributions']['langue'][] = $valeur;
594
					} elseif (in_array($key, $champ_attributions) != false) {
595
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
596
					} elseif (in_array($key, $champs) != false) {
597
						$this->table_retour[$key] = $valeur;
598
					}
599
				}
600
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
601
			}
602
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
603
		}
604
		return $this->table_retour;
605
	}
606
 
607
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
608
		preg_match('/^(.*)\.code$/', $champ, $match);
609
		$champ = $match[1];
610
		if (isset($this->champ_infos[$champ])) {
611
			extract($this->champ_infos[$champ]);
612
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
613
			$projet .= '.';
614
		}
615
 
616
		$champs = explode(' ', $this->ressources[1]);
617
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
618
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
619
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
620
		}
621
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
622
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
623
		}
624
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
625
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
626
		}
627
		if (in_array($champ, $champs) !== false) {
628
			if (isset($url)) {
629
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
630
			} else {
631
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
632
			}
633
		}
634
	}
635
 
636
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
637
		if ($this->retour_format == 'max') {
638
				$this->table_retour['attributions'][$nomChamp] = $nom;
639
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
640
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
641
		} else {
642
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
643
		}
644
	}
645
}
646
?>