Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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