Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1247 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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