Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 109 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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