Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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