Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 649 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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