Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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