Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1107 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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