Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 160 Rev 164
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->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
77
						break;
77
						break;
78
					case 'masque.nt' :
78
					case 'masque.nt' :
79
						$this->ajouterLeFiltreMasque('num_taxon', $valeur);
79
						$this->ajouterLeFiltreMasque('num_taxon', $valeur);
80
						break;
80
						break;
81
					case 'masque.nv' :
81
					case 'masque.nv' :
82
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
82
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
83
						break;
83
						break;
84
					case 'masque.lg' :
84
					case 'masque.lg' :
85
						$this->ajouterLeFiltreMasque('code_langue', $valeur);
85
						$this->ajouterLeFiltreMasque('code_langue', $valeur);
86
						break;
86
						break;
87
					case 'masque.cce' :
87
					case 'masque.cce' :
88
						$this->ajouterLeFiltreMasque('num_statut', $valeur);
88
						$this->ajouterLeFiltreMasque('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 ajouterLeFiltreMasque($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
		return $requete;
189
		return $requete;
190
	}
190
	}
191
 
191
 
192
	public  function formerRequeteChamp() {
192
	public  function formerRequeteChamp() {
193
		if (in_array('*', $this->requete_champ)) {
193
		if (in_array('*', $this->requete_champ)) {
194
			$champ = ' * ';
194
			$champ = ' * ';
195
		} else {
195
		} else {
196
			$champ = implode(', ', $this->requete_champ);
196
			$champ = implode(', ', $this->requete_champ);
197
		}
197
		}
198
		return $champ;
198
		return $champ;
199
	}
199
	}
200
 
200
 
201
	public  function formerRequeteCondition() {
201
	public  function formerRequeteCondition() {
202
		$condition = '';
202
		$condition = '';
203
		if ($this->requete_condition != null) {
203
		if ($this->requete_condition != null) {
204
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
204
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
205
		}
205
		}
206
		return $condition;
206
		return $condition;
207
	}
207
	}
208
 
208
 
209
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
209
	//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)
210
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
211
	public function formerRequeteLimite() {
211
	public function formerRequeteLimite() {
212
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
212
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
213
			$this->requete_limite = '';
213
			$this->requete_limite = '';
214
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
214
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
215
			$this->limite_requete['depart'] =
215
			$this->limite_requete['depart'] =
216
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
216
				(($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'];
217
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
218
		} else {
218
		} else {
219
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
219
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
220
		}
220
		}
221
		return $this->requete_limite;
221
		return $this->requete_limite;
222
	}
222
	}
223
 
223
 
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)
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
	public function recupererTotalResultat() {
225
	public function recupererTotalResultat() {
226
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
226
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
227
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
227
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
228
			.$this->table
228
			.$this->table
229
			.$this->formerRequeteCondition();
229
			.$this->formerRequeteCondition();
230
		$res = $this->getBdd()->recuperer($requete);
230
		$res = $this->getBdd()->recuperer($requete);
231
 
231
 
232
		if ($res) {
232
		if ($res) {
233
			$total = $res['nombre'];
233
			$total = $res['nombre'];
234
		} else {
234
		} else {
235
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
235
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
236
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
236
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
237
		}
237
		}
238
		return $total;
238
		return $total;
239
	}
239
	}
240
 
240
 
241
	//+------------------------------------------------------------------------------------------------------+
241
	//+------------------------------------------------------------------------------------------------------+
242
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
242
	// 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.
243
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
244
	public function retournerResultatFormate($resultat) {
244
	public function retournerResultatFormate($resultat) {
245
		$this->recupererTableConfig('correspondance_champs');
245
		$this->recupererTableConfig('correspondance_champs');
246
		switch ($this->format_reponse) {
246
		switch ($this->format_reponse) {
247
			case 'noms-vernaculaires'				: 
247
			case 'noms-vernaculaires'				: 
248
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
248
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
249
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
249
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
250
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
250
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
251
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
251
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
252
			default									:																	break;
252
			default									:																	break;
253
		}
253
		}
254
		return $reponse;
254
		return $reponse;
255
	}
255
	}
256
 
256
 
257
	public function formaterNomsVernaculaires($resultat) {
257
	public function formaterNomsVernaculaires($resultat) {
258
		//on remplit la table $table_retour_json['entete']
258
		//on remplit la table $table_retour_json['entete']
259
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
259
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
260
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
260
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
261
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
261
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
262
		$table_retour_json['entete']['total']  = $this->total_resultat;
262
		$table_retour_json['entete']['total']  = $this->total_resultat;
263
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
263
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
264
		if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
264
		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']; }
265
		if (isset($url['suivant']) && $url['suivant']   != '') { $table_retour_json['entete']['href.suivant']   = $url['suivant']; }
266
		
266
		
267
		//on remplit la table $table_retour_json['resultat']
267
		//on remplit la table $table_retour_json['resultat']
268
		if (isset($this->parametres['masque.nv'])) {
268
		if (isset($this->parametres['masque.nv'])) {
269
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
269
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
270
		}
270
		}
271
		if (isset($this->parametres['masque'])) {
271
		if (isset($this->parametres['masque'])) {
272
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
272
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
273
		}
273
		}
274
		foreach ($resultat as $tab) {
274
		foreach ($resultat as $tab) {
275
			foreach ($tab as $key => $valeur) {
275
			foreach ($tab as $key => $valeur) {
276
				if ($valeur != '') {
276
				if ($valeur != '') {
277
					switch ($key) {
277
					switch ($key) {
278
						case 'id'				: $num = $valeur;								break;
278
						case 'id'				: $num = $valeur;								break;
279
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
279
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
280
						default					:												break;
280
						default					:												break;
281
					}
281
					}
282
				}
282
				}
283
			}
283
			}
284
			if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
284
			if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
285
			$resultat_json[$num] = $this->table_retour;
285
			$resultat_json[$num] = $this->table_retour;
286
			$this->table_retour = array();
286
			$this->table_retour = array();
287
		}
287
		}
288
 
288
 
289
		$table_retour_json['resultat'] = $resultat_json;
289
		$table_retour_json['resultat'] = $resultat_json;
290
		return $table_retour_json;
290
		return $table_retour_json;
291
	}
291
	}
292
	
292
	
293
	public function recupererMasque() {
293
	public function recupererMasque() {
294
		$tab_masque = array();
294
		$tab_masque = array();
295
		foreach ($this->parametres as $param=>$valeur) {
295
		foreach ($this->parametres as $param=>$valeur) {
296
			if (strstr($param, 'masque') != false) {
296
			if (strstr($param, 'masque') != false) {
297
				$tab_masque[] = $param.'='.$valeur;
297
				$tab_masque[] = $param.'='.$valeur;
298
			}
298
			}
299
		}
299
		}
300
		$masque = implode('&', $tab_masque);
300
		$masque = implode('&', $tab_masque);
301
		return $masque;
301
		return $masque;
302
	}
302
	}
303
	
303
	
304
	public function formaterEnOss($resultat) {
304
	public function formaterEnOss($resultat) {
305
		$table_nom = array();
305
		$table_nom = array();
306
		$oss = '';
306
		$oss = '';
307
		foreach ($resultat as $tab) {
307
		foreach ($resultat as $tab) {
308
			if (isset($tab['nom_vernaculaire']) ) {
308
			if (isset($tab['nom_vernaculaire']) ) {
309
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
309
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
310
					$table_nom[] = $tab['nom_vernaculaire'];
310
					$table_nom[] = $tab['nom_vernaculaire'];
311
					$oss [] = $tab['nom_vernaculaire'];
311
					$oss [] = $tab['nom_vernaculaire'];
312
				}
312
				}
313
			}
313
			}
314
		}
314
		}
315
		if (isset($this->masque)) $masque = implode('&', $this->masque);
315
		if (isset($this->masque)) $masque = implode('&', $this->masque);
316
		else $masque = 'Pas de masque';
316
		else $masque = 'Pas de masque';
317
		$table_retour_oss = array($masque, $oss);
317
		$table_retour_oss = array($masque, $oss);
318
		return $table_retour_oss;
318
		return $table_retour_oss;
319
	}
319
	}
320
	
320
	
321
	public function formaterNomsVernaculairesAttributions($resultat) {
321
	public function formaterNomsVernaculairesAttributions($resultat) {
322
		//on remplie la table $table_retour_json['entete']
322
		//on remplie la table $table_retour_json['entete']
323
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
323
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
324
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
324
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
325
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
325
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
326
		$table_retour_json['entete']['total']  = $this->total_resultat;
326
		$table_retour_json['entete']['total']  = $this->total_resultat;
327
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
327
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
328
		if (isset($url['precedent']) && $url['precedent'] != '') {
328
		if (isset($url['precedent']) && $url['precedent'] != '') {
329
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
329
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
330
		}
330
		}
331
		if (isset($url['suivant']) && $url['suivant']   != '') {
331
		if (isset($url['suivant']) && $url['suivant']   != '') {
332
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
332
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
333
		}
333
		}
334
	
334
	
335
		//on remplie la table $table_retour_json['resultat']
335
		//on remplie la table $table_retour_json['resultat']
336
		if (isset($this->parametres['masque.nv'])) {
336
		if (isset($this->parametres['masque.nv'])) {
337
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
337
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
338
		}
338
		}
339
		if (isset($this->parametres['masque'])) {
339
		if (isset($this->parametres['masque'])) {
340
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
340
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
341
		}
341
		}
342
		foreach ($resultat as $tab) {
342
		foreach ($resultat as $tab) {
343
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
343
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
344
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
344
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
345
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
345
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
346
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
346
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
347
			if ($this->retour_format == 'max') {
347
			if ($this->retour_format == 'max') {
348
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
348
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
-
 
349
				$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
349
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
350
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
350
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
351
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
351
			}
352
			}
352
		}
353
		}
353
		
354
		
354
		if ($this->retour_format == 'max') {
355
		if ($this->retour_format == 'max') {
355
			$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
356
			$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
356
		}
357
		}
357
		
358
		
358
		$table_retour_json['resultat'] = $resultat_json;
359
		$table_retour_json['resultat'] = $resultat_json;
359
		return $table_retour_json;
360
		return $table_retour_json;
360
	}
361
	}
361
	
362
	
362
	public function afficherTaxonsAttributions($resultat) {
363
	public function afficherTaxonsAttributions($resultat) {
363
		$nom_sci = $this->recupererNomTaxons();
364
		$nom_sci = $this->recupererNomTaxons();
364
		foreach ($resultat as $num=>$tab) {
365
		foreach ($resultat as $num=>$tab) {
365
			if (isset($nom_sci[$tab['taxon']])) {
366
			if (isset($nom_sci[$tab['taxon']])) {
-
 
367
				$resultat[$num]['nom_retenu.code'] = $nom_sci[$tab['taxon']]['id'];
366
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']];
368
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']]['nom_sci'];
367
			}
369
			}
368
		}
370
		}
369
		return $resultat;
371
		return $resultat;
370
	}
372
	}
371
	
373
	
372
	// formatage de la reponse /id ss la forme
374
	// formatage de la reponse /id ss la forme
373
	// id, nom_vernaculaire, attributions
375
	// id, nom_vernaculaire, attributions
374
	// langue
376
	// langue
375
	// num_nom (correspond à un taxon bdtfx)
377
	// num_nom (correspond à un taxon bdtfx)
376
	public function formaterNomsVernaculairesId($resultat) {
378
	public function formaterNomsVernaculairesId($resultat) {
377
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
379
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
378
			// on crée les variables qui serviront de clés et on les enléves du tableau
380
			// on crée les variables qui serviront de clés et on les enléves du tableau
379
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
381
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
380
			unset($taxon['num_nom_vernaculaire']);
382
			unset($taxon['num_nom_vernaculaire']);
381
			$langue = $taxon['code_langue'];
383
			$langue = $taxon['code_langue'];
382
			unset($taxon['code_langue']);
384
			unset($taxon['code_langue']);
383
 
385
 
384
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
386
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
385
				if (isset($taxon[$key]) && $taxon[$key] != "") {
387
				if (isset($taxon[$key]) && $taxon[$key] != "") {
386
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
388
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
387
				}
389
				}
388
			}
390
			}
389
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
391
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
390
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
392
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
391
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
393
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
392
				}
394
				}
393
			}
395
			}
394
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
396
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
395
		}
397
		}
396
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
398
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
397
		unset($this->table_retour['href']);
399
		unset($this->table_retour['href']);
398
		return $this->table_retour;
400
		return $this->table_retour;
399
	}
401
	}
400
 
402
 
401
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
403
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
402
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
404
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
403
			$this->table_retour[$champ] = $valeur;
405
			$this->table_retour[$champ] = $valeur;
404
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
406
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
405
				switch ($match[1]) {
407
				switch ($match[1]) {
406
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
408
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
407
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
409
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
408
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
410
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
409
						break;
411
						break;
410
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
412
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
411
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
413
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
412
					default : break;
414
					default : break;
413
				}
415
				}
414
 
416
 
415
		} elseif ($langue != '') {
417
		} elseif ($langue != '') {
416
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
418
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
417
		} else {
419
		} else {
418
			$this->table_retour[$champ] = $valeur;
420
			$this->table_retour[$champ] = $valeur;
419
		}
421
		}
420
	}
422
	}
421
 
423
 
422
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
424
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
423
		if (isset($this->champ_infos[$nomChamp])) {
425
		if (isset($this->champ_infos[$nomChamp])) {
424
			extract($this->champ_infos[$nomChamp]);
426
			extract($this->champ_infos[$nomChamp]);
425
		}
427
		}
426
 
428
 
427
		if ($this->retour_format == 'max') {
429
		if ($this->retour_format == 'max') {
428
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
430
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
429
			if ($service == 'taxons') {
431
			if ($service == 'taxons') {
430
				$code_valeur = '';
432
				$code_valeur = '';
-
 
433
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
431
			} else {
434
			} else {
432
				$code_valeur = $this->chercherSignificationCode($url, $nom);
435
				$code_valeur = $this->chercherSignificationCode($url, $nom);
433
			}
436
			}
434
			if ($projet != '') $projet .= '.';
437
			if ($projet != '') $projet .= '.';
435
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
438
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
436
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
439
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
437
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
440
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
438
		} else {
441
		} else {
439
			if ($projet != '') $projet .= '.';
442
			if ($projet != '') $projet .= '.';
440
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
443
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
441
		}
444
		}
442
	}
445
	}
443
 
446
 
444
	public function chercherSignificationCode($url, $nom) {
447
	public function chercherSignificationCode($url, $nom) {
445
		if (isset($this->signification_code[$url])) {
448
		if (isset($this->signification_code[$url])) {
446
			$valeur = $this->signification_code[$url];
449
			$valeur = $this->signification_code[$url];
447
		} else {
450
		} else {
448
			$res = $this->consulterHref($url);
451
			$res = $this->consulterHref($url);
449
			$valeur = $res->$nom;
452
			$valeur = $res->$nom;
450
			$this->signification_code[$url] = $valeur;
453
			$this->signification_code[$url] = $valeur;
451
		}
454
		}
452
		return $valeur;
455
		return $valeur;
453
	}
456
	}
454
 
457
 
455
	public function afficherTaxons() {
458
	public function afficherTaxons() {
456
		$resultat = $this->recupererNomTaxons();
459
		$resultat = $this->recupererNomTaxons();
457
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
460
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
458
			foreach ($langue as $num_nom=>$taxon) {
461
			foreach ($langue as $num_nom=>$taxon) {
459
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
462
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
460
				if (isset($resultat[$num_tax])) {
463
				if (isset($resultat[$num_tax])) {
-
 
464
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
461
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax];
465
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
462
				}
466
				}
463
			}
467
			}
464
		}
468
		}
465
	}
469
	}
466
	
470
	
467
	public function recupererNomTaxons() {
471
	public function recupererNomTaxons() {
468
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.
472
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.
469
			$this->getBdd()->proteger(implode(',', $this->taxons));
473
			$this->getBdd()->proteger(implode(',', $this->taxons));
470
		$res = $this->consulterHref($url);
474
		$res = $this->consulterHref($url);
471
		foreach ($res->resultat as $id=>$taxon) {
475
		foreach ($res->resultat as $id=>$taxon) {
-
 
476
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
472
			$resultat[$taxon->num_taxonomique] = $taxon->nom_sci;
477
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci;
473
		}
478
		}
474
		return $resultat;
479
		return $resultat;
475
	}
480
	}
476
 
481
 
477
	public function formaterNomsVernaculairesIdChamp($resultat) {
482
	public function formaterNomsVernaculairesIdChamp($resultat) {
478
		$this->table_retour['id'] = $this->ressources[0];
483
		$this->table_retour['id'] = $this->ressources[0];
479
		$champs = explode(' ', $this->ressources[1]);
484
		$champs = explode(' ', $this->ressources[1]);
480
		if (in_array('attributions', $champs) != false) {
485
		if (in_array('attributions', $champs) != false) {
481
			$this->formaterNomsVernaculairesId($resultat);
486
			$this->formaterNomsVernaculairesId($resultat);
482
			unset($this->table_retour['nom_vernaculaire']);
487
			unset($this->table_retour['nom_vernaculaire']);
483
		} else {
488
		} else {
484
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
489
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
485
			foreach ($resultat as $taxon) {
490
			foreach ($resultat as $taxon) {
486
				foreach ($taxon as $key=>$valeur) {
491
				foreach ($taxon as $key=>$valeur) {
487
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
492
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
488
						$this->table_retour['attributions']['langue'][] = $valeur;
493
						$this->table_retour['attributions']['langue'][] = $valeur;
489
					} elseif (in_array($key, $champ_attributions) != false) {
494
					} elseif (in_array($key, $champ_attributions) != false) {
490
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
495
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
491
					} elseif (in_array($key, $champs) != false) {
496
					} elseif (in_array($key, $champs) != false) {
492
						$this->table_retour[$key] = $valeur;
497
						$this->table_retour[$key] = $valeur;
493
					}
498
					}
494
				}
499
				}
495
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
500
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
496
			}
501
			}
497
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
502
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
498
		}
503
		}
499
		return $this->table_retour;
504
		return $this->table_retour;
500
	}
505
	}
501
 
506
 
502
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
507
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
503
		preg_match('/^(.*)\.code$/', $champ, $match);
508
		preg_match('/^(.*)\.code$/', $champ, $match);
504
		$champ = $match[1];
509
		$champ = $match[1];
505
		if (isset($this->champ_infos[$champ])) {
510
		if (isset($this->champ_infos[$champ])) {
506
			extract($this->champ_infos[$champ]);
511
			extract($this->champ_infos[$champ]);
507
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
512
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
508
			$projet .= '.';
513
			$projet .= '.';
509
		}
514
		}
510
 
515
 
511
		$champs = explode(' ', $this->ressources[1]);
516
		$champs = explode(' ', $this->ressources[1]);
512
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
517
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
513
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
518
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
514
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
519
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
515
		}
520
		}
516
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
521
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
517
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
522
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
518
		}
523
		}
519
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
524
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
520
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
525
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
521
		}
526
		}
522
		if (in_array($champ, $champs) !== false) {
527
		if (in_array($champ, $champs) !== false) {
523
			if (isset($url)) {
528
			if (isset($url)) {
524
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
529
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
525
			} else {
530
			} else {
526
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
531
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
527
			}
532
			}
528
		}
533
		}
529
	}
534
	}
530
 
535
 
531
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
536
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
532
		if ($this->retour_format == 'max') {
537
		if ($this->retour_format == 'max') {
533
				$this->table_retour['attributions'][$nomChamp] = $nom;
538
				$this->table_retour['attributions'][$nomChamp] = $nom;
534
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
539
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
535
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
540
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
536
		} else {
541
		} else {
537
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
542
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
538
		}
543
		}
539
	}
544
	}
540
 
545
 
541
	public function chargerBiblio($num_nom, $langue) {
546
	public function chargerBiblio($num_nom, $langue) {
542
		list($table, $version) = explode('_v',$this->table);
547
		list($table, $version) = explode('_v',$this->table);
543
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
548
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
544
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
549
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
545
		$resultat = $this->getBdd()->recupererTous($requete); //Debug::printr($resultat);
550
		$resultat = $this->getBdd()->recupererTous($requete); //Debug::printr($resultat);
546
 
551
 
547
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
552
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
548
		 	$r = 'La requête SQL formée comporte une erreur !!';
553
		 	$r = 'La requête SQL formée comporte une erreur !!';
549
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
554
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
550
			Debug::printr($requete);
555
			Debug::printr($requete);
551
		 } elseif ($resultat) {
556
		 } elseif ($resultat) {
552
			foreach ($resultat as $res) {
557
			foreach ($resultat as $res) {
553
			   	foreach ($res as $cle => $valeur) {
558
			   	foreach ($res as $cle => $valeur) {
554
			   		if ($valeur !== "") {
559
			   		if ($valeur !== "") {
555
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
560
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
556
			   		}
561
			   		}
557
			    }
562
			    }
558
			}
563
			}
559
		}
564
		}
560
	}
565
	}
561
 
566
 
562
}
567
}
563
?>
568
?>