Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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