Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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