Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1107 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
649 delphine 1
<?php
2
/**
3
* Description :
4
* Classe NomsVernaculaires.php fournit une liste de noms vernaculaires et leur liaison à la bdtfx
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 bdtfx.
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' => 'bdtfx', '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
 
1107 mathias 74
	protected $config;
649 delphine 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 'masque.cce' :
103
						$this->ajouterFiltreMasque('num_statut', $valeur);
104
						break;
105
					case 'retour.format' :
106
						$this->retour_format = $valeur;
107
						break;
108
					case 'navigation.depart' :
109
						$this->limite_requete['depart'] = $valeur;
110
						break;
111
					case 'navigation.limite' :
112
						$this->limite_requete['limite'] = $valeur;
113
						break;
114
					case 'retour.champs' :
115
						$this->champs_supp = explode(',',$valeur);
116
					break;
117
					case 'recherche' :
118
						break;
119
					case 'version.projet' :
120
						break;
121
					default :
122
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
123
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
124
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
125
				}
126
			}
127
		}
128
	}
129
 
130
	public function ajouterFiltreMasque($nom_champ, $valeur) {
131
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
132
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
133
		} else {
134
			if ($this->recherche == 'floue') {
135
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
136
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
137
			} else {
138
				if ($this->recherche == 'etendue') {
139
					$valeur = '%'.str_replace(' ','% ', $valeur);
140
					$valeur .= '%';
141
				}
142
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
143
			}
144
		}
145
	}
146
 
147
	//+------------------------------------------------------------------------------------------------------+
148
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
149
	public function traiterRessources() {
150
		if (isset($this->ressources) && !empty($this->ressources)) {
151
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
152
				$this->traiterRessourceId(); // ajoute condition id=#valeur
153
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
154
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
155
				}
156
			}
157
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
158
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
159
		}
160
	}
161
 
162
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
163
	public function traiterRessourceId() {
164
		if (is_numeric($this->ressources[0])) {
165
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
166
			$this->format_reponse .= '/id';
167
		} elseif ($this->ressources[0] == 'attributions') {
168
			$this->format_reponse .= '/attributions';
169
		} else {
170
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
171
				' " n\'existe pas.';
172
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
173
		}
174
	}
175
 
176
 
177
	public function traiterRessourceChamp() {
178
		$this->format_reponse .= '/champ';
179
		$this->analyserChamp();
180
	}
181
 
182
	public function analyserChamp() {
183
		$this->requete_champ = array();
184
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
185
		$champs = explode(' ', $this->ressources[1]);
186
		foreach ($champs as $champ) {
187
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
188
			if (isset($this->champs_possibles[$match[1]])) {
189
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
190
			} elseif (isset($this->champs_possibles[$match[0]])) {
191
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
192
			} else {
193
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
194
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
195
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
196
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
197
			}
198
		}
199
	}
200
 
201
	//+------------------------------------------------------------------------------------------------------+
202
	public function assemblerLaRequete() {
203
		$requete = ' SELECT '.$this->formerRequeteChamp().
204
					' FROM '.$this->table
205
					.$this->formerRequeteCondition()
206
					.$this->formerRequeteLimite();
207
		return $requete;
208
	}
209
 
210
	public  function formerRequeteChamp() {
211
		if (in_array('*', $this->requete_champ)) {
212
			$champ = ' * ';
213
		} else {
214
			$champ = implode(', ', $this->requete_champ);
215
		}
216
		return $champ;
217
	}
218
 
219
	public  function formerRequeteCondition() {
220
		$condition = '';
221
		if ($this->requete_condition != null) {
222
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
223
		}
224
		return $condition;
225
	}
226
 
227
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
228
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
229
	public function formerRequeteLimite() {
230
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
231
			$this->requete_limite = '';
232
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
233
			$this->limite_requete['depart'] =
234
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
235
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
236
		} else {
237
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
238
		}
239
		return $this->requete_limite;
240
	}
241
 
242
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
243
	public function recupererTotalResultat() {
244
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
245
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
246
			.$this->table
247
			.$this->formerRequeteCondition();
248
		$res = $this->getBdd()->recuperer($requete);
249
 
250
		if ($res) {
251
			$total = $res['nombre'];
252
		} else {
253
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
254
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
255
		}
256
		return $total;
257
	}
258
 
259
	//+------------------------------------------------------------------------------------------------------+
260
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
261
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
262
	public function retournerResultatFormate($resultat) {
263
		$this->recupererTableConfig('correspondance_champs');
264
		switch ($this->format_reponse) {
265
			case 'noms-vernaculaires'				:
266
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
267
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
268
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
269
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
270
			default									:																	break;
271
		}
272
		return $reponse;
273
	}
274
 
275
	public function ajouterJsonEnTeteNV() {
276
		$table_retour_json['masque'] = $this->recupererMasque();
277
		$table_retour_json['depart'] = $this->limite_requete['depart'];
278
		$table_retour_json['limite'] = $this->limite_requete['limite'];
279
		$table_retour_json['total']  = $this->total_resultat;
280
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
281
		if (isset($url['precedent']) && $url['precedent'] != '') {
282
			$table_retour_json['href.precedent'] = $url['precedent'];
283
		}
284
		if (isset($url['suivant']) && $url['suivant']   != '') {
285
			$table_retour_json['href.suivant']   = $url['suivant'];
286
		}
287
		return $table_retour_json;
288
	}
289
 
290
	public function ajouterJsonResultatNV($resultat) {
291
		foreach ($resultat as $tab) {
292
			foreach ($tab as $key => $valeur) {
293
				if ($valeur != '') {
294
					switch ($key) {
295
						case 'id'				: $num = $valeur;								break;
296
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
297
						default					:												break;
298
					}
299
				}
300
			}
301
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
302
			$resultat_json[$num] = $this->table_retour;
303
			$this->table_retour = array();
304
		}
305
		return  $resultat_json;
306
	}
307
 
308
 
309
	public function formaterNomsVernaculaires($resultat) {
310
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
311
		$resultat = $this->hierarchiserResultat($resultat);
312
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
313
		return $table_retour_json;
314
	}
315
 
316
	public function hierarchiserResultat($resultat) {
317
		//tri recherche floue
318
		if (isset($this->parametres['masque.nv'])) {
319
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
320
		}
321
		if (isset($this->parametres['masque'])) {
322
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
323
		}
324
		return $resultat;
325
	}
326
 
327
	public function recupererMasque() {
328
		$tab_masque = array();
329
		foreach ($this->parametres as $param=>$valeur) {
330
			if (strstr($param, 'masque') != false) {
331
				$tab_masque[] = $param.'='.$valeur;
332
			}
333
		}
334
		$masque = implode('&', $tab_masque);
335
		return $masque;
336
	}
337
 
338
	public function formaterEnOss($resultat) {
339
		$table_nom = array();
340
		$oss = '';
341
		foreach ($resultat as $tab) {
342
			if (isset($tab['nom_vernaculaire']) ) {
343
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
344
					$table_nom[] = $tab['nom_vernaculaire'];
345
					$oss [] = $tab['nom_vernaculaire'];
346
				}
347
			}
348
		}
349
		if (isset($this->masque)) $masque = implode('&', $this->masque);
350
		else $masque = 'Pas de masque';
351
		$table_retour_oss = array($masque, $oss);
352
		return $table_retour_oss;
353
	}
354
 
355
	public function formaterNomsVernaculairesAttributions($resultat) {
356
		//on remplie la table $table_retour_json['entete']
357
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
358
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
359
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
360
		$table_retour_json['entete']['total']  = $this->total_resultat;
361
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
362
		if (isset($url['precedent']) && $url['precedent'] != '') {
363
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
364
		}
365
		if (isset($url['suivant']) && $url['suivant']   != '') {
366
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
367
		}
368
		foreach ($resultat as &$tab) {
369
			$resultat_json[$tab['id']]['id'] = $tab['id'];
370
			$resultat_json[$tab['id']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
371
			$resultat_json[$tab['id']]['code_langue'] = $tab['code_langue'];
372
			$resultat_json[$tab['id']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
373
			if ($this->retour_format == 'max') {
374
				$resultat_json[$tab['id']]['num_taxon'] = $tab['num_taxon'];
375
				$resultat_json[$tab['id']]['nom_retenu.code'] = $tab['num_taxon'];
376
				$resultat_json[$tab['id']]['taxon'] = $tab['num_taxon'];
377
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
378
				$resultat_json[$tab['id']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
379
 
380
				if($this->champs_supp != array()) {
381
					$resultat_json[$tab['id']] = $this->ajouterChampsOntologieLigneResultat($tab);
382
				}
383
			}
384
		}
385
 
386
		if ($this->retour_format == 'max') {
387
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
388
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
389
			$noms_sci = $this->recupererNomTaxons();
390
			foreach ($resultat_json as $num_nom => &$tab) {
391
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
392
				if($tab == null) {
393
					unset($resultat_json[$num_nom]);
394
				}
395
			}
396
		}
397
 
398
		uasort($resultat_json, array($this,'trierLigneTableau'));
399
		$table_retour_json['resultat'] = $resultat_json;
400
		return $table_retour_json;
401
	}
402
 
403
	/**
404
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
405
	 * en faisant appels aux web services associés
406
	 * @param array $ligne_resultat
407
	 *
408
	 * @return array la ligne modifiée
409
	 */
410
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
411
 
412
		$intitule = '';
413
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
414
			if(in_array($cle, $this->champs_supp)) {
415
				extract($champs_supplementaires);
416
				$valeur_recherche = '';
417
				switch($cle) {
418
					case 'taxon':
419
						$valeur_recherche = $ligne_resultat['num_taxon'];
420
						$intitule = 'taxon.code';
421
						break;
422
 
423
				}
424
				$code_valeur = '';
425
				if(trim($valeur_recherche) != '') {
426
					$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
427
					$code_valeur = $this->chercherSignificationCode($url, $nom);
428
				}
429
				$ligne_resultat[$intitule] = $code_valeur;
430
			}
431
		}
432
		return $ligne_resultat;
433
	}
434
 
435
	/**
436
	 * Fonction qui ajoute les attributions à une ligne de résultats
437
	 *
438
	 * @param array $ligne_tableau_resultat
439
	 * @param array $nom_sci
440
	 */
441
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
442
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
443
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
444
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
445
		} else {
446
			$ligne_tableau_resultat = null;
447
		}
448
		return $ligne_tableau_resultat;
449
	}
450
 
451
	private function trierLigneTableau($a, $b) {
452
		$retour = 0;
453
 
454
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
455
			$retour = 0;
456
		}
457
 
458
		if($this->champ_tri == 'code_langue') {
459
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
460
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
461
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
462
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
463
			} else {
464
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
465
			}
466
		} else {
467
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
468
		}
469
		return $retour;
470
	}
471
 
472
	private function comparerChaineSelonDirectionTri($a, $b) {
473
		if($this->direction_tri == 'asc') {
474
			return ($a < $b) ? -1 : 1;
475
		} else {
476
			return ($a > $b) ? -1 : 1;
477
		}
478
	}
479
 
480
	// formatage de la reponse /id ss la forme
481
	// id, nom_vernaculaire, attributions
482
	// langue
483
	// num_nom (correspond à un taxon bdtfx)
484
	public function formaterNomsVernaculairesId($resultat) {
485
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
486
			// on crée les variables qui serviront de clés et on les enléves du tableau
487
			$num_nom = $taxon['id']; // unique pour un trinôme id, langue, taxon
488
			$langue = $taxon['code_langue'];
489
			unset($taxon['code_langue']);
490
 
491
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
492
				if (isset($taxon[$key]) && $taxon[$key] != "") {
493
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
494
				}
495
			}
496
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
497
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
498
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
499
				}
500
			}
501
 
502
		}
503
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
504
		unset($this->table_retour['href']);
505
		return $this->table_retour;
506
	}
507
 
508
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
509
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
510
			$this->table_retour[$champ] = $valeur;
511
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
512
				switch ($match[1]) {
513
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
514
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
515
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
516
						break;
517
					default : break;
518
				}
519
 
520
		} elseif ($langue != '') {
521
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
522
		} else {
523
			$this->table_retour[$champ] = $valeur;
524
		}
525
	}
526
 
527
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
528
		if (isset($this->champ_infos[$nomChamp])) {
529
			extract($this->champ_infos[$nomChamp]);
530
		}
531
 
532
		if ($this->retour_format == 'max') {
533
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
534
			if ($service == 'taxons') {
535
				$code_valeur = '';
536
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
537
			} else {
538
				$code_valeur = $this->chercherSignificationCode($url, $nom);
539
			}
540
			if ($projet != '') $projet .= '.';
541
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
542
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
543
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
544
		} else {
545
			if ($projet != '') $projet .= '.';
546
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
547
		}
548
	}
549
 
550
	public function chercherSignificationCode($url, $nom) {
551
		if (isset($this->signification_code[$url])) {
552
			$valeur = $this->signification_code[$url];
553
		} else {
554
			$res = $this->consulterHref($url);
555
			$valeur = $res->$nom;
556
			$this->signification_code[$url] = $valeur;
557
		}
558
		return $valeur;
559
	}
560
 
561
	public function afficherTaxons() {
562
		$resultat = $this->recupererNomTaxons();
563
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
564
			foreach ($langue as $num_nom=>$taxon) {
565
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
566
				if (isset($resultat[$num_tax])) {
567
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
568
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
569
				}
570
			}
571
		}
572
	}
573
 
574
	public function recupererNomTaxons() {
575
		$taxons = array_unique($this->taxons);
576
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
577
		$res = $this->consulterHref($url);
578
		foreach ($res->resultat as $id=>$taxon) {
579
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
580
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
581
		}
582
		return $resultat;
583
	}
584
 
585
	public function formaterNomsVernaculairesIdChamp($resultat) {
586
		$this->table_retour['id'] = $this->ressources[0];
587
		$champs = explode(' ', $this->ressources[1]);
588
		if (in_array('attributions', $champs) != false) {
589
			$this->formaterNomsVernaculairesId($resultat);
590
			unset($this->table_retour['nom_vernaculaire']);
591
		} else {
592
			$champ_attributions = array('num_taxon', 'genre', 'notes');
593
			foreach ($resultat as $taxon) {
594
				foreach ($taxon as $key=>$valeur) {
595
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
596
						$this->table_retour['attributions']['langue'][] = $valeur;
597
					} elseif (in_array($key, $champ_attributions) != false) {
598
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['id']);
599
					} elseif (in_array($key, $champs) != false) {
600
						$this->table_retour[$key] = $valeur;
601
					}
602
				}
603
 
604
			}
605
 
606
		}
607
		return $this->table_retour;
608
	}
609
 
610
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
611
		preg_match('/^(.*)\.code$/', $champ, $match);
612
		$champ = $match[1];
613
		if (isset($this->champ_infos[$champ])) {
614
			extract($this->champ_infos[$champ]);
615
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
616
			$projet .= '.';
617
		}
618
 
619
		$champs = explode(' ', $this->ressources[1]);
620
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
621
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
622
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
623
		}
624
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
625
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
626
		}
627
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
628
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
629
		}
630
		if (in_array($champ, $champs) !== false) {
631
			if (isset($url)) {
632
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
633
			} else {
634
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
635
			}
636
		}
637
	}
638
 
639
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
640
		if ($this->retour_format == 'max') {
641
				$this->table_retour['attributions'][$nomChamp] = $nom;
642
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
643
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
644
		} else {
645
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
646
		}
647
	}
648
 
649
 
650
 
651
}
652
?>