Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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