Subversion Repositories eFlore/Projets.eflore-projets

Rev

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