Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 730 Rev 731
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
						 // utilisés par ajouterChampsOntologieLigneResultat()
27
						 // utilisés par ajouterChampsOntologieLigneResultat()
28
						 'intitule' => 'taxon.code', // intitulé du champ tel qu'il sera renvoyé en JSON
28
						 'intitule' => 'taxon.code', // intitulé du champ tel qu'il sera renvoyé en JSON
29
						 'bdd_champ' => 'num_taxon'), // intitulé du champ tel qu'il est présent dans l'enregistrement MySQL
29
						 'bdd_champ' => 'num_taxon'), // intitulé du champ tel qu'il est présent dans l'enregistrement MySQL
30
		'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom',
30
		'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom',
31
								  'intitule' => 'conseil_emploi', 'bdd_champ' => 'num_statut'),
31
								  'intitule' => 'conseil_emploi', 'bdd_champ' => 'num_statut'),
32
		'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom',
32
		'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom',
33
						 'intitule' => 'genre', 'bdd_champ' => 'num_genre'));
33
						 'intitule' => 'genre', 'bdd_champ' => 'num_genre'));
34
 
34
 
35
	protected $service = 'noms-vernaculaires';
35
	protected $service = 'noms-vernaculaires';
36
 
36
 
37
	/**
37
	/**
38
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
38
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
39
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
39
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
40
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
40
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
41
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
41
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
42
	protected $format_reponse = 'noms-vernaculaires';
42
	protected $format_reponse = 'noms-vernaculaires';
43
 
43
 
44
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
44
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
45
	 * selon ressources et paramètres */
45
	 * selon ressources et paramètres */
46
	protected $requete_champ = array(' * ');
46
	protected $requete_champ = array(' * ');
47
	protected $requete_condition = '';
47
	protected $requete_condition = '';
48
	protected $limite_requete = array(
48
	protected $limite_requete = array(
49
		'depart' => 0,
49
		'depart' => 0,
50
		'limite' => 100
50
		'limite' => 100
51
	);
51
	);
52
	
52
	
53
	protected $champ_tri = 'code_langue';
53
	protected $champ_tri = 'code_langue';
54
	protected $direction_tri = 'asc';
54
	protected $direction_tri = 'asc';
55
	
55
	
56
	/**
56
	/**
57
	 * Indique les champs supplémentaires à retourner
57
	 * Indique les champs supplémentaires à retourner
58
	 *  - conseil_emploi = conseil d'emploi du nom vernaculaire
58
	 *  - conseil_emploi = conseil d'emploi du nom vernaculaire
59
	 *  - genre = genre et nombre du nom
59
	 *  - genre = genre et nombre du nom
60
	 *  - taxon = nom retenu associé à ce nom
60
	 *  - taxon = nom retenu associé à ce nom
61
	 */
61
	 */
62
	protected $champs_supp = array();
62
	protected $champs_supp = array();
63
 
63
 
64
	/**
64
	/**
65
	 * Precise la contenance plus ou moins précise du tableau à retourner :
65
	 * Precise la contenance plus ou moins précise du tableau à retourner :
66
	 *  - min = les données présentes dans la table
66
	 *  - min = les données présentes dans la table
67
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
67
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
68
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
68
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
69
	protected $retour_format = 'max';
69
	protected $retour_format = 'max';
70
	/** Valeur du paramètre de requete recherche :
70
	/** Valeur du paramètre de requete recherche :
71
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
71
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
72
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
72
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
73
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
73
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
74
	protected $recherche;
74
	protected $recherche;
75
	
75
	
76
	/** Permet de stocker le tableau de résultat (non encodé en json) */
76
	/** Permet de stocker le tableau de résultat (non encodé en json) */
77
	protected $table_retour = array();
77
	protected $table_retour = array();
78
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
78
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
79
	protected $total_resultat;
79
	protected $total_resultat;
80
	
80
	
81
	private $config;
81
	private $config;
82
	
82
	
83
	public function __construct($config) {
83
	public function __construct($config) {
84
		$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
84
		$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
85
	}
85
	}
86
 
86
 
87
	//+------------------------------------------------------------------------------------------------------+
87
	//+------------------------------------------------------------------------------------------------------+
88
	// créer une condition en fonction du paramétre
88
	// créer une condition en fonction du paramétre
89
	public function traiterParametres() {
89
	public function traiterParametres() {
90
		if (isset($this->parametres) && !empty($this->parametres)) {
90
		if (isset($this->parametres) && !empty($this->parametres)) {
91
 
91
 
92
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
92
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
93
				$this->recherche = $this->parametres['recherche'];
93
				$this->recherche = $this->parametres['recherche'];
94
			}
94
			}
95
			foreach ($this->parametres as $param => $valeur) {
95
			foreach ($this->parametres as $param => $valeur) {
96
				switch ($param) {
96
				switch ($param) {
97
					case 'masque' :
97
					case 'masque' :
98
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
98
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
99
						break;
99
						break;
100
					case 'masque.nt' :
100
					case 'masque.nt' :
101
						$this->ajouterFiltreMasque('num_taxon', $valeur);
101
						$this->ajouterFiltreMasque('num_taxon', $valeur);
102
						break;
102
						break;
103
					case 'masque.nv' :
103
					case 'masque.nv' :
104
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
104
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
105
						break;
105
						break;
106
					case 'masque.lg' :
106
					case 'masque.lg' :
107
						$this->ajouterFiltreMasque('code_langue', $valeur);
107
						$this->ajouterFiltreMasque('code_langue', $valeur);
108
						break;
108
						break;
109
					case 'masque.cce' :
109
					case 'masque.cce' :
110
						$this->ajouterFiltreMasque('num_statut', $valeur);
110
						$this->ajouterFiltreMasque('num_statut', $valeur);
111
						break;
111
						break;
112
					case 'retour.format' :
112
					case 'retour.format' :
113
						$this->retour_format = $valeur;
113
						$this->retour_format = $valeur;
114
						break;
114
						break;
115
					case 'navigation.depart' :
115
					case 'navigation.depart' :
116
						$this->limite_requete['depart'] = $valeur;
116
						$this->limite_requete['depart'] = $valeur;
117
						break;
117
						break;
118
					case 'navigation.limite' :
118
					case 'navigation.limite' :
119
						$this->limite_requete['limite'] = $valeur;
119
						$this->limite_requete['limite'] = $valeur;
120
						break;
120
						break;
121
					case 'retour.champs' :
121
					case 'retour.champs' :
122
						$this->champs_supp = explode(',',$valeur);
122
						$this->champs_supp = explode(',',$valeur);
123
					break;
123
					break;
124
					case 'recherche' :
124
					case 'recherche' :
125
						break;
125
						break;
126
					case 'version.projet' :
126
					case 'version.projet' :
127
						break;
127
						break;
128
					default :
128
					default :
129
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
129
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
130
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
130
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
131
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
131
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
132
				}
132
				}
133
			}
133
			}
134
		}
134
		}
135
	}
135
	}
136
 
136
 
137
	public function ajouterFiltreMasque($nom_champ, $valeur) {
137
	public function ajouterFiltreMasque($nom_champ, $valeur) {
138
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
138
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
139
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
139
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
140
		} else {
140
		} else {
141
			if ($this->recherche == 'floue') {
141
			if ($this->recherche == 'floue') {
142
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
142
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
143
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
143
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
144
			} else {
144
			} else {
145
				if ($this->recherche == 'etendue') {
145
				if ($this->recherche == 'etendue') {
146
					$valeur = '%'.str_replace(' ','% ', $valeur);
146
					$valeur = '%'.str_replace(' ','% ', $valeur);
147
					$valeur .= '%';
147
					$valeur .= '%';
148
				}
148
				}
149
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
149
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
150
			}
150
			}
151
		}
151
		}
152
	}
152
	}
153
 
153
 
154
	//+------------------------------------------------------------------------------------------------------+
154
	//+------------------------------------------------------------------------------------------------------+
155
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
155
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
156
	public function traiterRessources() {
156
	public function traiterRessources() {
157
		if (isset($this->ressources) && !empty($this->ressources)) {
157
		if (isset($this->ressources) && !empty($this->ressources)) {
158
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
158
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
159
				$this->traiterRessourceId(); // ajoute condition id=#valeur
159
				$this->traiterRessourceId(); // ajoute condition id=#valeur
160
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
160
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
161
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
161
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
162
				}
162
				}
163
			}
163
			}
164
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
164
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
165
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
165
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
166
		}
166
		}
167
	}
167
	}
168
 
168
 
169
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
169
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
170
	public function traiterRessourceId() {
170
	public function traiterRessourceId() {
171
		if (is_numeric($this->ressources[0])) {
171
		if (is_numeric($this->ressources[0])) {
172
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
172
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
173
			$this->format_reponse .= '/id';
173
			$this->format_reponse .= '/id';
174
		} elseif ($this->ressources[0] == 'attributions') {
174
		} elseif ($this->ressources[0] == 'attributions') {
175
			$this->format_reponse .= '/attributions';
175
			$this->format_reponse .= '/attributions';
176
		} else {
176
		} else {
177
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
177
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
178
				' " n\'existe pas.';
178
				' " n\'existe pas.';
179
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
179
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
180
		}
180
		}
181
	}
181
	}
182
 
182
 
183
 
183
 
184
	public function traiterRessourceChamp() {
184
	public function traiterRessourceChamp() {
185
		$this->format_reponse .= '/champ';
185
		$this->format_reponse .= '/champ';
186
		$this->analyserChamp();
186
		$this->analyserChamp();
187
	}
187
	}
188
 
188
 
189
	public function analyserChamp() {
189
	public function analyserChamp() {
190
		$this->requete_champ = array();
190
		$this->requete_champ = array();
191
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
191
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
192
		$champs = explode(' ', $this->ressources[1]);
192
		$champs = explode(' ', $this->ressources[1]);
193
		foreach ($champs as $champ) {
193
		foreach ($champs as $champ) {
194
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
194
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
195
			if (isset($this->champs_possibles[$match[1]])) {
195
			if (isset($this->champs_possibles[$match[1]])) {
196
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
196
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
197
			} elseif (isset($this->champs_possibles[$match[0]])) {
197
			} elseif (isset($this->champs_possibles[$match[0]])) {
198
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
198
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
199
			} else {
199
			} else {
200
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
200
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
201
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
201
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
202
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
202
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
203
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
203
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
204
			}
204
			}
205
		}
205
		}
206
	}
206
	}
207
 
207
 
208
	//+------------------------------------------------------------------------------------------------------+
208
	//+------------------------------------------------------------------------------------------------------+
209
	public function assemblerLaRequete() {
209
	public function assemblerLaRequete() {
210
		$requete = ' SELECT '.$this->formerRequeteChamp().
210
		$requete = ' SELECT '.$this->formerRequeteChamp().
211
					', CASE num_statut WHEN "" THEN 1 ELSE 0 END AS is_null '.
211
					', CASE num_statut WHEN "" THEN 1 ELSE 0 END AS is_null '.
212
					' FROM '.$this->table
212
					' FROM '.$this->table
213
					.$this->formerRequeteCondition().
213
					.$this->formerRequeteCondition().
214
					' ORDER BY is_null ASC, num_statut ASC '
214
					' ORDER BY is_null ASC, num_statut ASC '
215
					.$this->formerRequeteLimite();
215
					.$this->formerRequeteLimite();
216
		return $requete;
216
		return $requete;
217
	}
217
	}
218
 
218
 
219
	public  function formerRequeteChamp() {
219
	public  function formerRequeteChamp() {
220
		if (in_array('*', $this->requete_champ)) {
220
		if (in_array('*', $this->requete_champ)) {
221
			$champ = ' * ';
221
			$champ = ' * ';
222
		} else {
222
		} else {
223
			$champ = implode(', ', $this->requete_champ);
223
			$champ = implode(', ', $this->requete_champ);
224
		}
224
		}
225
		return $champ;
225
		return $champ;
226
	}
226
	}
227
 
227
 
228
	public  function formerRequeteCondition() {
228
	public  function formerRequeteCondition() {
229
		$condition = '';
229
		$condition = '';
230
		if ($this->requete_condition != null) {
230
		if ($this->requete_condition != null) {
231
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
231
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
232
		}
232
		}
233
		return $condition;
233
		return $condition;
234
	}
234
	}
235
 
235
 
236
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
236
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
237
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
237
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
238
	public function formerRequeteLimite() {
238
	public function formerRequeteLimite() {
239
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
239
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
240
			$this->requete_limite = '';
240
			$this->requete_limite = '';
241
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
241
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
242
			$this->limite_requete['depart'] =
242
			$this->limite_requete['depart'] =
243
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
243
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
244
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
244
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
245
		} else {
245
		} else {
246
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
246
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
247
		}
247
		}
248
		return $this->requete_limite;
248
		return $this->requete_limite;
249
	}
249
	}
250
 
250
 
251
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
251
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
252
	public function recupererTotalResultat() {
252
	public function recupererTotalResultat() {
253
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
253
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
254
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
254
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
255
			.$this->table
255
			.$this->table
256
			.$this->formerRequeteCondition();
256
			.$this->formerRequeteCondition();
257
		$res = $this->getBdd()->recuperer($requete);
257
		$res = $this->getBdd()->recuperer($requete);
258
 
258
 
259
		if ($res) {
259
		if ($res) {
260
			$total = $res['nombre'];
260
			$total = $res['nombre'];
261
		} else {
261
		} else {
262
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
262
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
263
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
263
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
264
		}
264
		}
265
		return $total;
265
		return $total;
266
	}
266
	}
267
 
267
 
268
	//+------------------------------------------------------------------------------------------------------+
268
	//+------------------------------------------------------------------------------------------------------+
269
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
269
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
270
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
270
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
271
	public function retournerResultatFormate($resultat) {
271
	public function retournerResultatFormate($resultat) {
272
		$this->recupererTableConfig('correspondance_champs');
272
		$this->recupererTableConfig('correspondance_champs');
273
		switch ($this->format_reponse) {
273
		switch ($this->format_reponse) {
274
			case 'noms-vernaculaires'				: 
274
			case 'noms-vernaculaires'				: 
275
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
275
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
276
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
276
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
277
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
277
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
278
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
278
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
279
			default									:																	break;
279
			default									:																	break;
280
		}
280
		}
281
		return $reponse;
281
		return $reponse;
282
	}
282
	}
283
	
283
	
284
	public function ajouterJsonEnTeteNV() {
284
	public function ajouterJsonEnTeteNV() {
285
		$table_retour_json['masque'] = $this->recupererMasque();
285
		$table_retour_json['masque'] = $this->recupererMasque();
286
		$table_retour_json['depart'] = $this->limite_requete['depart'];
286
		$table_retour_json['depart'] = $this->limite_requete['depart'];
287
		$table_retour_json['limite'] = $this->limite_requete['limite'];
287
		$table_retour_json['limite'] = $this->limite_requete['limite'];
288
		$table_retour_json['total']  = $this->total_resultat;
288
		$table_retour_json['total']  = $this->total_resultat;
289
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
289
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
290
		if (isset($url['precedent']) && $url['precedent'] != '') {
290
		if (isset($url['precedent']) && $url['precedent'] != '') {
291
			$table_retour_json['href.precedent'] = $url['precedent'];
291
			$table_retour_json['href.precedent'] = $url['precedent'];
292
		}
292
		}
293
		if (isset($url['suivant']) && $url['suivant']   != '') {
293
		if (isset($url['suivant']) && $url['suivant']   != '') {
294
			$table_retour_json['href.suivant']   = $url['suivant'];
294
			$table_retour_json['href.suivant']   = $url['suivant'];
295
		}
295
		}
296
		return $table_retour_json;
296
		return $table_retour_json;
297
	}
297
	}
298
	
298
	
299
	public function ajouterJsonResultatNV($resultat) {
299
	public function ajouterJsonResultatNV($resultat) {
300
		foreach ($resultat as $tab) {
300
		foreach ($resultat as $tab) {
301
			foreach ($tab as $key => $valeur) {
301
			foreach ($tab as $key => $valeur) {
302
				if ($valeur != '') {
302
				if ($valeur != '') {
303
					switch ($key) {
303
					switch ($key) {
304
						case 'id'				: $num = $valeur;								break;
304
						case 'id'				: $num = $valeur;								break;
305
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
305
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
306
						default					:												break;
306
						default					:												break;
307
					}
307
					}
308
				}
308
				}
309
			}
309
			}
310
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
310
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
311
			$resultat_json[$num] = $this->table_retour;
311
			$resultat_json[$num] = $this->table_retour;
312
			$this->table_retour = array();
312
			$this->table_retour = array();
313
		}
313
		}
314
		return  $resultat_json;
314
		return  $resultat_json;
315
	}
315
	}
316
 
316
 
317
	
317
	
318
	public function formaterNomsVernaculaires($resultat) {
318
	public function formaterNomsVernaculaires($resultat) {
319
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
319
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
320
		$resultat = $this->hierarchiserResultat($resultat);
320
		$resultat = $this->hierarchiserResultat($resultat);
321
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
321
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
322
		return $table_retour_json;
322
		return $table_retour_json;
323
	}
323
	}
324
	
324
	
325
	public function hierarchiserResultat($resultat) {
325
	public function hierarchiserResultat($resultat) {
326
		//tri recherche floue
326
		//tri recherche floue
327
		if (isset($this->parametres['masque.nv'])) {
327
		if (isset($this->parametres['masque.nv'])) {
328
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
328
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
329
		}
329
		}
330
		if (isset($this->parametres['masque'])) {
330
		if (isset($this->parametres['masque'])) {
331
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
331
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
332
		}
332
		}
333
		return $resultat;
333
		return $resultat;
334
	}
334
	}
335
	
335
	
336
	public function recupererMasque() {
336
	public function recupererMasque() {
337
		$tab_masque = array();
337
		$tab_masque = array();
338
		foreach ($this->parametres as $param=>$valeur) {
338
		foreach ($this->parametres as $param=>$valeur) {
339
			if (strstr($param, 'masque') != false) {
339
			if (strstr($param, 'masque') != false) {
340
				$tab_masque[] = $param.'='.$valeur;
340
				$tab_masque[] = $param.'='.$valeur;
341
			}
341
			}
342
		}
342
		}
343
		$masque = implode('&', $tab_masque);
343
		$masque = implode('&', $tab_masque);
344
		return $masque;
344
		return $masque;
345
	}
345
	}
346
	
346
	
347
	public function formaterEnOss($resultat) {
347
	public function formaterEnOss($resultat) {
348
		$table_nom = array();
348
		$table_nom = array();
349
		$oss = '';
349
		$oss = '';
350
		foreach ($resultat as $tab) {
350
		foreach ($resultat as $tab) {
351
			if (isset($tab['nom_vernaculaire']) ) {
351
			if (isset($tab['nom_vernaculaire']) ) {
352
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
352
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
353
					$table_nom[] = $tab['nom_vernaculaire'];
353
					$table_nom[] = $tab['nom_vernaculaire'];
354
					$oss [] = $tab['nom_vernaculaire'];
354
					$oss [] = $tab['nom_vernaculaire'];
355
				}
355
				}
356
			}
356
			}
357
		}
357
		}
358
		if (isset($this->masque)) $masque = implode('&', $this->masque);
358
		if (isset($this->masque)) $masque = implode('&', $this->masque);
359
		else $masque = 'Pas de masque';
359
		else $masque = 'Pas de masque';
360
		$table_retour_oss = array($masque, $oss);
360
		$table_retour_oss = array($masque, $oss);
361
		return $table_retour_oss;
361
		return $table_retour_oss;
362
	}
362
	}
363
	
363
	
364
	public function formaterNomsVernaculairesAttributions($resultat) {
364
	public function formaterNomsVernaculairesAttributions($resultat) {
365
		//on remplie la table $table_retour_json['entete']
365
		//on remplie la table $table_retour_json['entete']
366
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
366
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
367
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
367
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
368
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
368
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
369
		$table_retour_json['entete']['total']  = $this->total_resultat;
369
		$table_retour_json['entete']['total']  = $this->total_resultat;
370
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
370
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
371
		if (!empty($url['precedent'])) {
371
		if (!empty($url['precedent'])) {
372
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
372
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
373
		}
373
		}
374
		if (!empty($url['suivant'])) {
374
		if (!empty($url['suivant'])) {
375
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
375
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
376
		}
376
		}
377
		foreach ($resultat as &$tab) {			
377
		foreach ($resultat as &$tab) {			
378
			$nnv = $tab['num_nom_vernaculaire'];
378
			$nnv = $tab['num_nom_vernaculaire'];
379
			$resultat_json[$nnv]['id'] = $tab['id'];
379
			$resultat_json[$nnv]['id'] = $tab['id'];
380
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
380
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
381
			$resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
381
			$resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
382
			$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
382
			$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
383
			if ($this->retour_format == 'max') {
383
			if ($this->retour_format == 'max') {
384
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
384
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
385
				if($this->champs_supp) {
385
				if($this->champs_supp) {
386
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
386
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
387
					// simple initialisation par copie de la référence de l'original
387
					// simple initialisation par copie de la référence de l'original
388
					$resultat_json[$nnv] = &$tab;
388
					$resultat_json[$nnv] = &$tab;
389
				}
389
				}
390
				else {
390
				else {
391
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
391
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
392
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
392
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
393
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
393
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
394
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
394
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
395
				}
395
				}
396
			}
396
			}
397
		}
397
		}
398
 
398
 
399
		// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
399
		// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
400
		// vers le tableau de valeurs original
400
		// vers le tableau de valeurs original
401
		if ($this->retour_format == 'max' && $this->champs_supp) {
401
		if ($this->retour_format == 'max' && $this->champs_supp) {
402
			// récupérons désormais les ontologies
402
			// récupérons désormais les ontologies
403
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
403
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
404
		}
404
		}
405
 
405
 
406
		if ($this->retour_format == 'max') {
406
		if ($this->retour_format == 'max') {
407
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
407
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
408
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
408
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
409
			$noms_sci = $this->recupererNomTaxons();
409
			$noms_sci = $this->recupererNomTaxons();
410
			foreach ($resultat_json as $num_nom => &$tab) {
410
			foreach ($resultat_json as $num_nom => &$tab) {
411
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
411
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
412
				if($tab == null) {
412
				if($tab == null) {
413
					unset($resultat_json[$num_nom]);
413
					unset($resultat_json[$num_nom]);
414
				}
414
				}
415
			}
415
			}
416
		}
416
		}
417
		
417
		
418
		$table_retour_json['resultat'] = $resultat_json;
418
		$table_retour_json['resultat'] = $resultat_json;
419
		return $table_retour_json;
419
		return $table_retour_json;
420
	}
420
	}
421
	
421
	
422
	/**
422
	/**
423
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
423
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
424
	 * en faisant appels aux web services associés
424
	 * en faisant appels aux web services associés
425
	 * @param array in/out $resultats: tous les résultats
425
	 * @param array in/out $resultats: tous les résultats
426
	 */
426
	 */
427
	public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
427
	public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
428
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
428
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
429
			if(!in_array($cle, $this->champs_supp)) continue;
429
			if(!in_array($cle, $this->champs_supp)) continue;
-
 
430
 
430
 
431
			// TODO: n'activer QUE lorsque le webservice ontologie Nvjfl supportera le multi-critère
431
			// TODO:
432
			// cf: services/modules/0.1/commun/Ontologies.php
432
			if($cle == 'conseil_emploi') {
433
			if(FALSE && $cle == 'conseil_emploi') {
433
				// la factorisation des toutes les valeurs recherchées (pour tous les
434
				// la factorisation des toutes les valeurs recherchées (pour tous les
-
 
435
				// résultats, peut [potentiellement] être effectuée ci-dessous)
434
				// résultats, peut [potentiellement] être effectuée ci-dessous)
436
				$ontologieParamPending = static::NvjflOntologieIndex($resultats, $champs_supplementaires);
-
 
437
				$this->NvjflOntologieExpand($ontologieParamPending);
435
				// $this->ajouterChampsOntologieNVJFL($resultats);
438
				self::NvjflOntologieCombine($resultats, $champs_supplementaires);
436
				// continue;
-
 
437
				
439
				continue;
438
			}
440
			}
439
 
441
 
440
			// extrait, depuis un élément de $champ_infos:
442
			// extrait, depuis un élément de $champ_infos:
441
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
443
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
442
			extract($champs_supplementaires);
444
			extract($champs_supplementaires);
443
 
445
 
444
			foreach ($resultats as &$tab) {
446
			foreach ($resultats as &$tab) {
445
				$valeur_recherche = $tab[$bdd_champ];
447
				$valeur_recherche = $tab[$bdd_champ];
446
				if(!trim($valeur_recherche)) continue;
448
				if(!trim($valeur_recherche)) continue;
447
 
449
 
448
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
450
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
449
				$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
451
				$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
450
			}
452
			}
451
		}
453
		}
-
 
454
	}
-
 
455
 
-
 
456
	/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
-
 
457
	   spécifiquement au service d'Ontologies de NVJFL.
-
 
458
	   Aggrège les valeurs dans le tableau retourné.
-
 
459
	   Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
-
 
460
	   un élément du résultat. */
-
 
461
	static function NvjflOntologieIndex(&$resultats, $champs_infos) {
-
 
462
		$ontologieParamPending = Array();
-
 
463
		extract($champs_infos);
-
 
464
		foreach($resultats as &$resultat) {
-
 
465
			$valeur_recherche = $resultat[$bdd_champ];
-
 
466
			if(!trim($valeur_recherche)) continue;
-
 
467
			$ontologieParamPending[$ressource . $valeur_recherche] = NULL;
-
 
468
			// placeholder pour le résultat
-
 
469
			$resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'] =
-
 
470
				&$ontologieParamPending[$ressource . $valeur_recherche];
-
 
471
		}
-
 
472
		return $ontologieParamPending;
-
 
473
	}
-
 
474
 
-
 
475
	// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
-
 
476
	/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
-
 
477
	   créé une URL multi-critère.
-
 
478
	   Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
-
 
479
	   des couples <ressource - valeur recherchée>.
-
 
480
	   L'URL est appelée et la valeur correspondante, dans $criteres_requete, remplacée.
-
 
481
 
-
 
482
	   Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
-
 
483
	   la valeur est référencée par une élément d'une ou plusieurs lignes de $resultat correspondantes.
-
 
484
	   Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
-
 
485
	public function NvjflOntologieExpand(&$criteres_requete) {
-
 
486
		// équivalent spécifique de ajouterHrefAutreProjet()
-
 
487
		$valeurs_requises = implode(',', array_keys($criteres_requete));
-
 
488
		$url = Config::get('url_service_base').'nvjfl/ontologies/'.$valeurs_requises;
-
 
489
		$val = $this->consulterHref($url);
-
 
490
		// modifie par conséquent $resultats[X]['_result_ontologies' . RES_VAL_SEP . 'nvjfl']
-
 
491
		// dont la référence pointe toujours sur $v
-
 
492
		foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
-
 
493
	}
-
 
494
 
-
 
495
	/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
-
 
496
	   NVJFL en adéquation avec les champs attendus en sortie. Pour ce faire, $champs_infos
-
 
497
	   est nécessaire. D'autre part, l'index spécifique '_result_ontologies' . RES_VAL_SEP . 'nvjfl'
-
 
498
	   est supprimé après avoir été correctement copié. */
-
 
499
	static function NvjflOntologieCombine(&$resultats, $champs_infos) {
-
 
500
		extract($champs_infos);
-
 
501
		foreach($resultats as &$resultat) {
-
 
502
			if(!isset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'])) continue;
-
 
503
			// equivalent de chercher signification
-
 
504
			$resultat[$intitule] = $resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']->$nom;
-
 
505
			unset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']);
-
 
506
		}
452
	}
507
	}
453
 
508
 
454
	/**
509
	/**
455
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
510
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
456
	 * en faisant appels aux web services associés
511
	 * en faisant appels aux web services associés
457
	 * @param array $ligne_resultat
512
	 * @param array $ligne_resultat
458
	 * 
513
	 * 
459
	 * @return array la ligne modifiée
514
	 * @return array la ligne modifiée
460
	 */
515
	 */
461
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
516
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
462
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
517
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
463
			if(!in_array($cle, $this->champs_supp)) continue;
518
			if(!in_array($cle, $this->champs_supp)) continue;
464
			// extrait, depuis un élément de $champ_infos:
519
			// extrait, depuis un élément de $champ_infos:
465
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
520
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
466
			extract($champs_supplementaires);
521
			extract($champs_supplementaires);
467
			$valeur_recherche = $ligne_resultat[$bdd_champ];
522
			$valeur_recherche = $ligne_resultat[$bdd_champ];
468
			if(!trim($valeur_recherche)) continue;
523
			if(!trim($valeur_recherche)) continue;
469
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
524
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
470
			$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
525
			$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
471
		}
526
		}
472
		return $ligne_resultat;
527
		return $ligne_resultat;
473
	}
528
	}
474
	
529
	
475
	/**
530
	/**
476
	 * Fonction qui ajoute les attributions à une ligne de résultats
531
	 * Fonction qui ajoute les attributions à une ligne de résultats
477
	 *
532
	 *
478
	 * @param array $ligne_tableau_resultat
533
	 * @param array $ligne_tableau_resultat
479
	 * @param array $nom_sci
534
	 * @param array $nom_sci
480
	 */
535
	 */
481
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
536
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
482
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
537
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
483
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
538
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
484
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
539
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
485
		} else {
540
		} else {
486
			$ligne_tableau_resultat = null;
541
			$ligne_tableau_resultat = null;
487
		}
542
		}
488
		return $ligne_tableau_resultat;
543
		return $ligne_tableau_resultat;
489
	}
544
	}
490
	
545
	
491
	private function trierLigneTableau($a, $b) {
546
	private function trierLigneTableau($a, $b) {
492
		$retour = 0;
547
		$retour = 0;
493
		
548
		
494
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
549
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
495
			$retour = 0;
550
			$retour = 0;
496
		}
551
		}
497
				
552
				
498
		if($this->champ_tri == 'code_langue') {
553
		if($this->champ_tri == 'code_langue') {
499
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
554
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
500
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
555
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
501
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
556
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
502
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
557
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
503
			} else {
558
			} else {
504
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
559
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
505
			}
560
			}
506
		} else {
561
		} else {
507
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
562
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
508
		}
563
		}
509
		return $retour;
564
		return $retour;
510
	}
565
	}
511
	
566
	
512
	private function comparerChaineSelonDirectionTri($a, $b) {
567
	private function comparerChaineSelonDirectionTri($a, $b) {
513
		if($this->direction_tri == 'asc') {
568
		if($this->direction_tri == 'asc') {
514
			return ($a < $b) ? -1 : 1;
569
			return ($a < $b) ? -1 : 1;
515
		} else {
570
		} else {
516
			return ($a > $b) ? -1 : 1;
571
			return ($a > $b) ? -1 : 1;
517
		}
572
		}
518
	}
573
	}
519
	
574
	
520
	// formatage de la reponse /id ss la forme
575
	// formatage de la reponse /id ss la forme
521
	// id, nom_vernaculaire, attributions
576
	// id, nom_vernaculaire, attributions
522
	// langue
577
	// langue
523
	// num_nom (correspond à un taxon bdtfx)
578
	// num_nom (correspond à un taxon bdtfx)
524
	public function formaterNomsVernaculairesId($resultat) {
579
	public function formaterNomsVernaculairesId($resultat) {
525
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
580
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
526
			// on crée les variables qui serviront de clés et on les enléves du tableau
581
			// on crée les variables qui serviront de clés et on les enléves du tableau
527
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
582
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
528
			unset($taxon['num_nom_vernaculaire']);
583
			unset($taxon['num_nom_vernaculaire']);
529
			$langue = $taxon['code_langue'];
584
			$langue = $taxon['code_langue'];
530
			unset($taxon['code_langue']);
585
			unset($taxon['code_langue']);
531
 
586
 
532
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
587
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
533
				if (isset($taxon[$key]) && $taxon[$key] != "") {
588
				if (isset($taxon[$key]) && $taxon[$key] != "") {
534
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
589
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
535
				}
590
				}
536
			}
591
			}
537
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
592
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
538
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
593
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
539
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
594
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
540
				}
595
				}
541
			}
596
			}
542
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
597
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
543
		}
598
		}
544
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
599
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
545
		unset($this->table_retour['href']);
600
		unset($this->table_retour['href']);
546
		return $this->table_retour;
601
		return $this->table_retour;
547
	}
602
	}
548
 
603
 
549
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
604
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
550
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
605
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
551
			$this->table_retour[$champ] = $valeur;
606
			$this->table_retour[$champ] = $valeur;
552
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
607
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
553
				switch ($match[1]) {
608
				switch ($match[1]) {
554
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
609
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
555
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
610
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
556
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
611
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
557
						break;
612
						break;
558
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
613
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
559
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
614
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
560
					default : break;
615
					default : break;
561
				}
616
				}
562
 
617
 
563
		} elseif ($langue != '') {
618
		} elseif ($langue != '') {
564
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
619
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
565
		} else {
620
		} else {
566
			$this->table_retour[$champ] = $valeur;
621
			$this->table_retour[$champ] = $valeur;
567
		}
622
		}
568
	}
623
	}
569
 
624
 
570
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
625
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
571
		if (isset($this->champ_infos[$nomChamp])) {
626
		if (isset($this->champ_infos[$nomChamp])) {
572
			extract($this->champ_infos[$nomChamp]);
627
			extract($this->champ_infos[$nomChamp]);
573
		}
628
		}
574
 
629
 
575
		if ($this->retour_format == 'max') {
630
		if ($this->retour_format == 'max') {
576
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
631
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
577
			if ($service == 'taxons') {
632
			if ($service == 'taxons') {
578
				$code_valeur = '';
633
				$code_valeur = '';
579
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
634
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
580
			} else {
635
			} else {
581
				$code_valeur = $this->chercherSignificationCode($url, $nom);
636
				$code_valeur = $this->chercherSignificationCode($url, $nom);
582
			}
637
			}
583
			if ($projet != '') $projet .= '.';
638
			if ($projet != '') $projet .= '.';
584
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
639
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
585
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
640
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
586
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
641
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
587
		} else {
642
		} else {
588
			if ($projet != '') $projet .= '.';
643
			if ($projet != '') $projet .= '.';
589
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
644
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
590
		}
645
		}
591
	}
646
	}
592
 
647
 
593
	public function chercherSignificationCode($url, $nom) {
648
	public function chercherSignificationCode($url, $nom) {
594
		if (isset($this->signification_code[$url])) {
649
		if (isset($this->signification_code[$url])) {
595
			$valeur = $this->signification_code[$url];
650
			$valeur = $this->signification_code[$url];
596
		} else {
651
		} else {
597
			$res = $this->consulterHref($url);
652
			$res = $this->consulterHref($url);
598
			$valeur = $res->$nom;
653
			$valeur = $res->$nom;
599
			$this->signification_code[$url] = $valeur;
654
			$this->signification_code[$url] = $valeur;
600
		}
655
		}
601
		return $valeur;
656
		return $valeur;
602
	}
657
	}
603
 
658
 
604
	public function afficherTaxons() {
659
	public function afficherTaxons() {
605
		$resultat = $this->recupererNomTaxons();
660
		$resultat = $this->recupererNomTaxons();
606
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
661
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
607
			foreach ($langue as $num_nom=>$taxon) {
662
			foreach ($langue as $num_nom=>$taxon) {
608
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
663
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
609
				if (isset($resultat[$num_tax])) {
664
				if (isset($resultat[$num_tax])) {
610
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
665
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
611
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
666
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
612
				}
667
				}
613
			}
668
			}
614
		}
669
		}
615
	}
670
	}
616
	
671
	
617
	public function recupererNomTaxons() {
672
	public function recupererNomTaxons() {
618
		$taxons = array_unique($this->taxons);
673
		$taxons = array_unique($this->taxons);
619
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
674
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
620
		$res = $this->consulterHref($url);
675
		$res = $this->consulterHref($url);
621
		foreach ($res->resultat as $id=>$taxon) {
676
		foreach ($res->resultat as $id=>$taxon) {
622
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
677
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
623
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
678
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
624
		}
679
		}
625
		return $resultat;
680
		return $resultat;
626
	}
681
	}
627
 
682
 
628
	public function formaterNomsVernaculairesIdChamp($resultat) {
683
	public function formaterNomsVernaculairesIdChamp($resultat) {
629
		$this->table_retour['id'] = $this->ressources[0];
684
		$this->table_retour['id'] = $this->ressources[0];
630
		$champs = explode(' ', $this->ressources[1]);
685
		$champs = explode(' ', $this->ressources[1]);
631
		if (in_array('attributions', $champs) != false) {
686
		if (in_array('attributions', $champs) != false) {
632
			$this->formaterNomsVernaculairesId($resultat);
687
			$this->formaterNomsVernaculairesId($resultat);
633
			unset($this->table_retour['nom_vernaculaire']);
688
			unset($this->table_retour['nom_vernaculaire']);
634
		} else {
689
		} else {
635
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
690
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
636
			foreach ($resultat as $taxon) {
691
			foreach ($resultat as $taxon) {
637
				foreach ($taxon as $key=>$valeur) {
692
				foreach ($taxon as $key=>$valeur) {
638
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
693
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
639
						$this->table_retour['attributions']['langue'][] = $valeur;
694
						$this->table_retour['attributions']['langue'][] = $valeur;
640
					} elseif (in_array($key, $champ_attributions) != false) {
695
					} elseif (in_array($key, $champ_attributions) != false) {
641
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
696
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
642
					} elseif (in_array($key, $champs) != false) {
697
					} elseif (in_array($key, $champs) != false) {
643
						$this->table_retour[$key] = $valeur;
698
						$this->table_retour[$key] = $valeur;
644
					}
699
					}
645
				}
700
				}
646
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
701
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
647
			}
702
			}
648
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
703
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
649
		}
704
		}
650
		return $this->table_retour;
705
		return $this->table_retour;
651
	}
706
	}
652
 
707
 
653
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
708
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
654
		preg_match('/^(.*)\.code$/', $champ, $match);
709
		preg_match('/^(.*)\.code$/', $champ, $match);
655
		$champ = $match[1];
710
		$champ = $match[1];
656
		if (isset($this->champ_infos[$champ])) {
711
		if (isset($this->champ_infos[$champ])) {
657
			extract($this->champ_infos[$champ]);
712
			extract($this->champ_infos[$champ]);
658
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
713
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
659
			$projet .= '.';
714
			$projet .= '.';
660
		}
715
		}
661
 
716
 
662
		$champs = explode(' ', $this->ressources[1]);
717
		$champs = explode(' ', $this->ressources[1]);
663
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
718
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
664
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
719
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
665
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
720
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
666
		}
721
		}
667
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
722
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
668
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
723
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
669
		}
724
		}
670
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
725
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
671
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
726
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
672
		}
727
		}
673
		if (in_array($champ, $champs) !== false) {
728
		if (in_array($champ, $champs) !== false) {
674
			if (isset($url)) {
729
			if (isset($url)) {
675
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
730
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
676
			} else {
731
			} else {
677
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
732
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
678
			}
733
			}
679
		}
734
		}
680
	}
735
	}
681
 
736
 
682
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
737
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
683
		if ($this->retour_format == 'max') {
738
		if ($this->retour_format == 'max') {
684
				$this->table_retour['attributions'][$nomChamp] = $nom;
739
				$this->table_retour['attributions'][$nomChamp] = $nom;
685
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
740
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
686
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
741
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
687
		} else {
742
		} else {
688
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
743
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
689
		}
744
		}
690
	}
745
	}
691
 
746
 
692
	public function chargerBiblio($num_nom, $langue) {
747
	public function chargerBiblio($num_nom, $langue) {
693
		list($table, $version) = explode('_v',$this->table);
748
		list($table, $version) = explode('_v',$this->table);
694
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
749
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
695
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
750
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
696
		$resultat = $this->getBdd()->recupererTous($requete);
751
		$resultat = $this->getBdd()->recupererTous($requete);
697
 
752
 
698
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
753
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
699
		 	$r = 'La requête SQL formée comporte une erreur !!';
754
		 	$r = 'La requête SQL formée comporte une erreur !!';
700
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
755
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
701
			Debug::printr($requete);
756
			Debug::printr($requete);
702
		 } elseif ($resultat) {
757
		 } elseif ($resultat) {
703
			foreach ($resultat as $res) {
758
			foreach ($resultat as $res) {
704
			   	foreach ($res as $cle => $valeur) {
759
			   	foreach ($res as $cle => $valeur) {
705
			   		if ($valeur !== "") {
760
			   		if ($valeur !== "") {
706
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
761
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
707
			   		}
762
			   		}
708
			    }
763
			    }
709
			}
764
			}
710
		}
765
		}
711
	}
766
	}
712
 
767
 
713
}
768
}
714
?>
769
?>