Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1107 | Rev 1109 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 jpm 1
<?php
966 raphael 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
 */
734 raphael 24
 
966 raphael 25
 // Un caractère de concaténation entre le projet et le service.
26
 // Ce caractère ne doit pas faire partie d'aucun des noms de service ou projet
27
 define('RES_VAL_SEP', '@');
28
 define('SPE_INDEX_NVJFL', '_result_ontologies' . RES_VAL_SEP . 'nvjfl');
734 raphael 29
 
966 raphael 30
 class NomsVernaculaires extends Commun {
832 raphael 31
 
966 raphael 32
     static $onto_multi_support = array('conseil_emploi', 'genre');
33
     static $champ_infos = array(
34
         'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci',
35
                          // utilisés par ajouterChampsOntologieLigneResultat()
36
                          'intitule' => 'taxon.code', // intitulé du champ tel qu'il sera renvoyé en JSON
37
                          'bdd_champ' => 'num_taxon'), // intitulé du champ tel qu'il est présent dans l'enregistrement MySQL
38
         'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom',
39
                                   'intitule' => 'conseil_emploi', 'bdd_champ' => 'num_statut'),
40
         'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom',
41
                          'intitule' => 'genre', 'bdd_champ' => 'num_genre'));
109 jpm 42
 
966 raphael 43
     protected $service = 'noms-vernaculaires';
109 jpm 44
 
966 raphael 45
     /**
46
      * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
47
      *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
48
      * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
49
      * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
50
     protected $format_reponse = 'noms-vernaculaires';
109 jpm 51
 
966 raphael 52
     /** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
53
      * selon ressources et paramètres */
54
     protected $requete_champ = array(' * ');
55
     protected $requete_condition = '';
56
     protected $limite_requete = array(
57
         'depart' => 0,
58
         'limite' => 100
59
     );
109 jpm 60
 
1107 mathias 61
	/**
62
	 * Vrai tri SQL
63
	 */
64
	protected $tri;
65
	protected $tri_ordre = 'asc';
109 jpm 66
 
1107 mathias 67
	// wtf ? on trie après avoir exécuté la requête ?
68
    protected $champ_tri = 'code_langue';
69
    protected $direction_tri = 'asc';
70
 
966 raphael 71
     /**
72
      * Indique les champs supplémentaires à retourner
73
      *  - conseil_emploi = conseil d'emploi du nom vernaculaire
74
      *  - genre = genre et nombre du nom
75
      *  - taxon = nom retenu associé à ce nom
76
      */
77
     protected $champs_supp = array();
109 jpm 78
 
966 raphael 79
     /**
80
      * Precise la contenance plus ou moins précise du tableau à retourner :
81
      *  - min = les données présentes dans la table
82
      *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
83
      *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
84
     protected $retour_format = 'max';
85
     /** Valeur du paramètre de requete recherche :
86
      *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
87
      *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
88
      *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
89
     protected $recherche;
109 jpm 90
 
966 raphael 91
     /** Permet de stocker le tableau de résultat (non encodé en json) */
92
     protected $table_retour = array();
93
     /** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
94
     protected $total_resultat;
6 jpm 95
 
1107 mathias 96
     protected $config;
109 jpm 97
 
966 raphael 98
     public function __construct($config) {
99
         $this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
100
     }
109 jpm 101
 
966 raphael 102
     //+------------------------------------------------------------------------------------------------------+
103
     // créer une condition en fonction du paramétre
104
     public function traiterParametres() {
105
         if (isset($this->parametres) && !empty($this->parametres)) {
109 jpm 106
 
966 raphael 107
             if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
108
                 $this->recherche = $this->parametres['recherche'];
109
             }
110
             foreach ($this->parametres as $param => $valeur) {
111
                 switch ($param) {
112
                     case 'masque' :
113
                         $this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
114
                         break;
115
                     case 'masque.nt' :
116
                         $this->ajouterFiltreMasque('num_taxon', $valeur);
117
                         break;
118
                     case 'masque.nv' :
119
                         $this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
120
                         break;
121
                     case 'masque.lg' :
122
                         $this->ajouterFiltreMasque('code_langue', $valeur);
123
                         break;
124
                     case 'masque.cce' :
125
                         $this->ajouterFiltreMasque('num_statut', $valeur);
126
                         break;
127
                     case 'retour.format' :
128
                         $this->retour_format = $valeur;
129
                         break;
1107 mathias 130
                     case 'retour.tri' :
131
                         $this->tri = $valeur;
132
                         break;
133
                     case 'retour.ordre' :
134
						 if (in_array(strtolower($valeur), aray('asc', 'desc'))) {
135
							$this->tri_ordre = $valeur;
136
						 }
137
                         break;
966 raphael 138
                     case 'navigation.depart' :
139
                         $this->limite_requete['depart'] = $valeur;
140
                         break;
141
                     case 'navigation.limite' :
142
                         $this->limite_requete['limite'] = $valeur;
143
                         break;
144
                     case 'retour.champs' :
145
                         $this->champs_supp = explode(',',$valeur);
146
                     break;
147
                     case 'recherche' :
148
                         break;
149
                     case 'version.projet' :
150
                         break;
151
                     default :
152
                         $p = 'Erreur dans les paramètres de recherche de votre requête : '.
153
                             '</br> Le paramètre " '.$param.' " n\'existe pas.';
154
                             $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
155
                 }
156
             }
157
         }
158
     }
109 jpm 159
 
966 raphael 160
     public function ajouterFiltreMasque($nom_champ, $valeur) {
161
         if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
162
             $this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
163
         } else {
164
             if ($this->recherche == 'floue') {
165
                 $this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
166
                     .' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
167
             } else {
168
                 if ($this->recherche == 'etendue') {
169
                     $valeur = '%'.str_replace(' ','% ', $valeur);
170
                     $valeur .= '%';
171
                 }
172
                 $this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
173
             }
174
         }
175
     }
109 jpm 176
 
966 raphael 177
     //+------------------------------------------------------------------------------------------------------+
178
     // en fonction de la présence des ressources modifie requete_champ et requete_condition
179
     public function traiterRessources() {
180
         if (isset($this->ressources) && !empty($this->ressources)) {
181
             if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
182
                 $this->traiterRessourceId(); // ajoute condition id=#valeur
183
                 if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
184
                     $this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
185
                 }
186
             }
187
         } else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
188
             $this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
1107 mathias 189
			 $this->requete_champ = array_merge($this->requete_champ, $this->champs_supp);
966 raphael 190
         }
191
     }
109 jpm 192
 
966 raphael 193
     //requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
194
     public function traiterRessourceId() {
195
         if (is_numeric($this->ressources[0])) {
196
             $this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
197
             $this->format_reponse .= '/id';
198
         } elseif ($this->ressources[0] == 'attributions') {
199
             $this->format_reponse .= '/attributions';
200
         } else {
201
             $r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
202
                 ' " n\'existe pas.';
203
             $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
204
         }
205
     }
109 jpm 206
 
207
 
966 raphael 208
     public function traiterRessourceChamp() {
209
         $this->format_reponse .= '/champ';
210
         $this->analyserChamp();
211
     }
212
 
213
     public function analyserChamp() {
214
         $this->requete_champ = array();
215
         $this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
216
         $champs = explode(' ', $this->ressources[1]);
217
         foreach ($champs as $champ) {
218
             preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
219
             if (isset($this->champs_possibles[$match[1]])) {
220
                 $this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
221
             } elseif (isset($this->champs_possibles[$match[0]])) {
222
                 $this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
223
             } else {
224
                 $champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
225
                 $c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
226
                     'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
227
                 $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
228
             }
229
         }
230
     }
231
 
1108 mathias 232
	 // fait du neuf avec du vieux
233
	public function assemblerLaRequete() {
234
		$requete = false;
235
		if ($this->format_reponse == 'noms-vernaculaires') {
236
			// mode liste
237
			$requete = $this->assemblerRequeteListe();
238
		} else {
239
			$requete = $this->assemblerRequeteAutre();
240
		}
241
		return $requete;
242
	}
1107 mathias 243
 
1108 mathias 244
	/**
245
	 * Exécute un astucieux GROUP BY afin que le service retourne ce qu'il
246
	 * annonce qu'il retourne (truc de ouf!) - pour le mode "liste"
247
	 */
248
	protected function assemblerRequeteListe() {
249
		$count = $this->recupererTotalResultat();
250
		$limiteClause = self::formerRequeteLimite( // LIMIT
251
			$this->limite_requete['depart'],
252
			$count,
253
			$this->limite_requete['limite']
254
		);
966 raphael 255
 
1108 mathias 256
        $req = sprintf(
257
            'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' .
258
            ' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
966 raphael 259
 
1108 mathias 260
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
261
            $this->table,
262
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
263
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
264
            $limiteClause,
265
            __FILE__, __LINE__);
266
		//echo "REQ: $req\n";
267
		return $req;
268
	}
269
 
270
	 /**
271
	  * Ancien système d'assemblage de requête
272
	  */
273
	protected function assemblerRequeteAutre() {
274
        $nolimit = in_array(
275
            $this->format_reponse,
276
            array($this->service.'/id', $this->service.'/id/champs'));
277
        if(!$nolimit) {
278
            $count = $this->recupererTotalResultat();
279
            $limiteClause = self::formerRequeteLimite( // LIMIT
280
                $this->limite_requete['depart'],
281
                $count,
282
                $this->limite_requete['limite']);
283
        }
284
 
285
        $req = sprintf(
286
            'SELECT %s, IF(num_statut="",1,0) AS is_null' .
287
            ' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
288
 
289
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
290
            $this->table,
291
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
292
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
293
            $nolimit ? '' : $limiteClause,
294
            __FILE__, __LINE__);
295
		//echo "REQ 2: $req\n";
296
		return $req;
297
	}
298
 
109 jpm 299
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
6 jpm 300
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
966 raphael 301
	static function formerRequeteLimite(&$depart, $total, $limite) {
302
        if ($depart > $total) {
303
			$depart = $total - $limite < 0 ? 0 : ($total - $limite);
304
			return ' LIMIT ' . $depart . ', ' . $limite;
305
        }
306
        return ' LIMIT ' . $depart . ', ' . $limite;
6 jpm 307
	}
109 jpm 308
 
6 jpm 309
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
310
	public function recupererTotalResultat() {
966 raphael 311
        $res = $this->getBdd()->recuperer(sprintf(
312
            'SELECT COUNT(%s) AS nombre FROM %s WHERE %s -- %s:%d',
313
 
314
            $this->format_reponse == 'noms-vernaculaires/attributions' ? 'id' : 'distinct(id)',
315
            $this->table,
316
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
317
            __FILE__, __LINE__));
109 jpm 318
 
966 raphael 319
		if (! $res)
320
            throw new Exception('Données introuvables', RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
321
        if($res['nombre'] == 0) {
322
            print json_encode(
323
                array(
324
                    "entete" => array(
325
                        "depart" => $this->limite_requete['depart'],
326
                        "limite" => $this->limite_requete['limite'],
327
                        "masque" => $this->recupererMasque(),
328
                        "total" => 0
329
                    ),
330
                    "resultat" => array()
331
                ));
332
            die; // die() très dommage (pour phpunit), mais la stack d'imbrication ne nous permet pas de retourner proprement
333
            }
334
 
980 mathias 335
        $this->total_resultat = $res['nombre'];
966 raphael 336
        return $res['nombre'];
6 jpm 337
	}
109 jpm 338
 
339
	//+------------------------------------------------------------------------------------------------------+
340
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
6 jpm 341
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
342
	public function retournerResultatFormate($resultat) {
343
		$this->recupererTableConfig('correspondance_champs');
344
		switch ($this->format_reponse) {
132 aurelien 345
			case 'noms-vernaculaires'				:
346
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
160 delphine 347
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
6 jpm 348
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
349
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
350
			default									:																	break;
351
		}
1108 mathias 352
		//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n";
6 jpm 353
		return $reponse;
354
	}
608 mathilde 355
 
356
	public function ajouterJsonEnTeteNV() {
357
		$table_retour_json['masque'] = $this->recupererMasque();
358
		$table_retour_json['depart'] = $this->limite_requete['depart'];
359
		$table_retour_json['limite'] = $this->limite_requete['limite'];
360
		$table_retour_json['total']  = $this->total_resultat;
6 jpm 361
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
608 mathilde 362
		if (isset($url['precedent']) && $url['precedent'] != '') {
363
			$table_retour_json['href.precedent'] = $url['precedent'];
6 jpm 364
		}
608 mathilde 365
		if (isset($url['suivant']) && $url['suivant']   != '') {
366
			$table_retour_json['href.suivant']   = $url['suivant'];
152 delphine 367
		}
608 mathilde 368
		return $table_retour_json;
369
	}
1108 mathias 370
 
371
	/**
372
	 * @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
373
	 * évite d'écraser des clefs etc.)
374
	 */
608 mathilde 375
	public function ajouterJsonResultatNV($resultat) {
1108 mathias 376
		//echo "CPT RES: " . count($resultat) . "\n\n";
377
		$resultat_json = array();
6 jpm 378
		foreach ($resultat as $tab) {
1108 mathias 379
			$this->table_retour = array();
6 jpm 380
			foreach ($tab as $key => $valeur) {
381
				if ($valeur != '') {
382
					switch ($key) {
383
						case 'id'				: $num = $valeur;								break;
384
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
385
						default					:												break;
386
					}
1107 mathias 387
					// champs supplémentaires
388
					if (in_array($key, $this->champs_supp)) {
389
						$this->table_retour[$key] = $valeur;
390
					}
6 jpm 391
				}
392
			}
608 mathilde 393
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
6 jpm 394
			$resultat_json[$num] = $this->table_retour;
395
		}
1108 mathias 396
		return $resultat_json;
608 mathilde 397
	}
109 jpm 398
 
608 mathilde 399
 
400
	public function formaterNomsVernaculaires($resultat) {
401
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
402
		$resultat = $this->hierarchiserResultat($resultat);
403
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
6 jpm 404
		return $table_retour_json;
405
	}
132 aurelien 406
 
608 mathilde 407
	public function hierarchiserResultat($resultat) {
408
		//tri recherche floue
409
		if (isset($this->parametres['masque.nv'])) {
966 raphael 410
			return $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
608 mathilde 411
		}
412
		if (isset($this->parametres['masque'])) {
966 raphael 413
			return $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
608 mathilde 414
		}
415
		return $resultat;
416
	}
417
 
160 delphine 418
	public function recupererMasque() {
419
		$tab_masque = array();
420
		foreach ($this->parametres as $param=>$valeur) {
421
			if (strstr($param, 'masque') != false) {
422
				$tab_masque[] = $param.'='.$valeur;
423
			}
424
		}
966 raphael 425
		return implode('&', $tab_masque);
160 delphine 426
	}
427
 
132 aurelien 428
	public function formaterEnOss($resultat) {
429
		$table_nom = array();
430
		$oss = '';
431
		foreach ($resultat as $tab) {
432
			if (isset($tab['nom_vernaculaire']) ) {
433
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
434
					$table_nom[] = $tab['nom_vernaculaire'];
435
					$oss [] = $tab['nom_vernaculaire'];
436
				}
437
			}
438
		}
439
		if (isset($this->masque)) $masque = implode('&', $this->masque);
440
		else $masque = 'Pas de masque';
966 raphael 441
		return array($masque, $oss);
132 aurelien 442
	}
160 delphine 443
 
444
	public function formaterNomsVernaculairesAttributions($resultat) {
445
		//on remplie la table $table_retour_json['entete']
446
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
447
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
448
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
449
		$table_retour_json['entete']['total']  = $this->total_resultat;
450
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
729 raphael 451
		if (!empty($url['precedent'])) {
160 delphine 452
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
453
		}
729 raphael 454
		if (!empty($url['suivant'])) {
160 delphine 455
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
456
		}
888 raphael 457
		foreach ($resultat as &$tab) {
730 raphael 458
			$nnv = $tab['num_nom_vernaculaire'];
459
			$resultat_json[$nnv]['id'] = $tab['id'];
460
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
888 raphael 461
			$resultat_json[$nnv]['langue.code'] = $resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
730 raphael 462
			$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
160 delphine 463
			if ($this->retour_format == 'max') {
284 jpm 464
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
729 raphael 465
				if($this->champs_supp) {
730 raphael 466
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
467
					// simple initialisation par copie de la référence de l'original
468
					$resultat_json[$nnv] = &$tab;
286 aurelien 469
				}
729 raphael 470
				else {
730 raphael 471
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
472
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
473
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
474
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
729 raphael 475
				}
160 delphine 476
			}
280 aurelien 477
		}
730 raphael 478
 
479
		// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
480
		// vers le tableau de valeurs original
481
		if ($this->retour_format == 'max' && $this->champs_supp) {
482
			// récupérons désormais les ontologies
483
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
484
		}
485
 
280 aurelien 486
		if ($this->retour_format == 'max') {
284 jpm 487
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
488
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
489
			$noms_sci = $this->recupererNomTaxons();
286 aurelien 490
			foreach ($resultat_json as $num_nom => &$tab) {
491
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
627 aurelien 492
				if($tab == null) {
493
					unset($resultat_json[$num_nom]);
494
				}
284 jpm 495
			}
160 delphine 496
		}
280 aurelien 497
 
160 delphine 498
		$table_retour_json['resultat'] = $resultat_json;
499
		return $table_retour_json;
500
	}
501
 
286 aurelien 502
	/**
503
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
832 raphael 504
	 * en faisant appels aux web services associés.
505
	 * Les appels peuvent être fait individuellement (pour un couple <ontologie:valeur>) ou bien
506
	 * regroupés, **si le webservice correspondant le supporte**.
507
	 *
508
	 * Nous disposons à ce jour de 3 (trois) webservices d'ontologies correspondant aux noms vernaculaires (cf $champ_infos)
509
	 * Mais 2 d'entre eux sont identiques, il s'agit de /nvjfl/ontologies/. Or ce webservice supporte le multi-critère.
510
	 * Nous pouvons donc factorisé l'appel pour "conseil_emploi" et "genre", mais pas pour "taxon".
511
	 *
730 raphael 512
	 * @param array in/out $resultats: tous les résultats
513
	 */
514
	public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
832 raphael 515
		$champs_sup = array_intersect($this->champs_supp, array_keys(self::$champ_infos));
730 raphael 516
 
832 raphael 517
		// La regroupement des toutes les valeurs recherchées (pour tous les
518
		// résultats), pour "les" onotologies supportant le multi-critère est effectué ci-dessous.
519
		// Dans les faits ce n'est le cas que pour nvjfl.
520
		$ontologieParamPending = self::NvjflOntologieIndex($resultats, $champs_sup);
521
		$this->NvjflOntologieExpand($ontologieParamPending);
522
		self::NvjflOntologieCombine($resultats);
730 raphael 523
 
832 raphael 524
		// pour les ontologies multi-critères, on vient de le régler ci-dessus
525
		$champs_sup = array_diff($champs_sup, self::$onto_multi_support);
526
 
527
 
528
		// ici, $champs_sup ne peut contenir, au plus, que "taxon".
529
		// code historique:
530
		foreach($champs_sup as $cle) {
531
			$champs_supplementaires = self::$champ_infos[$cle];
730 raphael 532
			// extrait, depuis un élément de $champ_infos:
533
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
534
			extract($champs_supplementaires);
535
 
536
			foreach ($resultats as &$tab) {
537
				$valeur_recherche = $tab[$bdd_champ];
538
				if(!trim($valeur_recherche)) continue;
539
 
540
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
541
				$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
542
			}
543
		}
544
	}
545
 
731 raphael 546
	/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
547
	   spécifiquement au service d'Ontologies de NVJFL.
548
	   Aggrège les valeurs dans le tableau retourné.
549
	   Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
550
	   un élément du résultat. */
832 raphael 551
	static function NvjflOntologieIndex(&$resultats, $champs_sup) {
552
		// nous ne supportons le multi-critère que sur les ontologies nvjfl, et nous
553
		// avons précisé celles qui sont concernées dans self::$onto_multi_support
554
		$champs_sup = array_intersect($champs_sup, self::$onto_multi_support);
731 raphael 555
		$ontologieParamPending = Array();
556
		foreach($resultats as &$resultat) {
832 raphael 557
			foreach($champs_sup as $v) {
558
				// de cet extract() nous n'utilisons que $bdd_champ et $ressource
559
				extract(self::$champ_infos[$v]);
560
				if(!isset($resultat[$bdd_champ])) continue;
561
 
562
				$valeur_recherche = $resultat[$bdd_champ];
563
				if(!trim($valeur_recherche)) continue;
564
 
565
				// XXX: $ressource contient déjà ':' comme suffixe
566
				$critere = $ressource . $valeur_recherche;
567
				$ontologieParamPending[$critere] = NULL;
568
				// placeholder pour le résultat
569
				$resultat[SPE_INDEX_NVJFL][$v][$critere] =
570
					&$ontologieParamPending[$critere];
571
			}
731 raphael 572
		}
573
		return $ontologieParamPending;
574
	}
575
 
576
	// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
577
	/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
578
	   créé une URL multi-critère.
579
	   Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
832 raphael 580
	   des couples <ressource:ValeurRecherchée>.
581
	   L'URL est appelée et la valeur correspondante est remplacée dans $criteres_requete.
731 raphael 582
 
583
	   Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
832 raphael 584
	   la valeur est référencée par un élément d'une ou plusieurs lignes de $resultat correspondantes.
731 raphael 585
	   Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
586
	public function NvjflOntologieExpand(&$criteres_requete) {
587
		// équivalent spécifique de ajouterHrefAutreProjet()
588
		$valeurs_requises = implode(',', array_keys($criteres_requete));
832 raphael 589
		// en vérité, nous ne supportons ceci ici que pour nvjfl et non n'importe quel url_service
809 raphael 590
		$url = Config::get('url_service').'/ontologies/'.$valeurs_requises;
731 raphael 591
		$val = $this->consulterHref($url);
831 raphael 592
 
593
		// TODO, le webservice d'ontologies devrait être modifié pour retourner un tableau
594
		// indexé par critère requesté à *CHAQUE* fois, y compris lorsque 1 seul critère est
595
		// demandé.
596
		if(array_key_exists('id', $val) && count($criteres_requete) == 1) {
597
			$k = key($criteres_requete);
598
			$criteres_requete[$k] = $val;
599
			return;
600
		}
601
 
832 raphael 602
		// subtilité, cette affectation modifie par conséquent les valeurs dans
603
		// $resultats[X][SPE_INDEX_NVJFL]
731 raphael 604
		// dont la référence pointe toujours sur $v
605
		foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
606
	}
607
 
608
	/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
832 raphael 609
	   NVJFL en adéquation avec les champs attendus en sortie.
610
	   Dès l'indexation des critères, nous avons associé une (ou plusieurs) référence(s) du
611
	   tableau de résultats vers le tableau de retour des ontologies à l'aide d'un index
612
	   particulier l'index SPE_INDEX_NVJFL qui contient comme élément(s)
613
	   un ou plusieurs ontologies (les indexes de self::$champ_infos) qui elles-mêmes contiennent
614
	   une ou plusieurs valeurs représentant les valeurs recherchées appartement à cette ontologies.
615
	   Celui-ci est supprimé après avoir été correctement copié. */
616
	/**
617
	 * @param array in/out $resultats: tous les résultats
618
	 * @param array in $critere: tableau des ontologies:valeur demandées, de la forme [ numStatut:1, genreNombre:11, ... ]
619
	 */
848 raphael 620
	static function NvjflOntologieCombine(&$resultats) {
731 raphael 621
		foreach($resultats as &$resultat) {
832 raphael 622
			if(!array_key_exists(SPE_INDEX_NVJFL, $resultat)) continue;
623
 
624
			/* Note: la complétude d'un résultat peut dépendre de plusieurs ontologies différentes,
625
			   d'où cette boucle. Cependant une seule valeur sera demandé pour cette ontologie, c'est pourquoi
626
			   $resultat[SPE_INDEX_NVJFL][$onto_name], s'il existe, ne contiendra toujours qu'un seul élément.
627
			   Puisque par définition un résultat contenant des valeurs d'ontologie n'aura jamais qu'un seul et unique
628
			   attribut num_genre (ou num_statut, ou autre) */
629
			foreach(self::$onto_multi_support as $onto_name) {
848 raphael 630
				if(!array_key_exists($onto_name, $resultat[SPE_INDEX_NVJFL])) continue;
631
 
832 raphael 632
				/* $onto_name est un nom d'ontologie (l'une des clefs, parmi conseil_emploi et genre,
633
				   cf la boucle sur $champs_sup dans  NvjflOntologieIndex()
634
				   de cet extract() nous n'utilisons que $intitule et $nom */
635
				extract(self::$champ_infos[$onto_name]);
636
 
637
				// equivalent de l'affectation finale de chercherSignificationCode()
638
				// (utilisé lors de recherches d'ontologies en mono-critère)
639
				// XXX: PHP-5.3 pas de récupération d'attribut sur fonction
640
				$r = current($resultat[SPE_INDEX_NVJFL][$onto_name]);
641
				$resultat[$intitule] = $r->$nom;
642
 
643
				// XXX: certes nous pourrions nous contenter du unset() final
644
				unset($resultat[SPE_INDEX_NVJFL][$onto_name]);
645
			}
646
			unset($resultat[SPE_INDEX_NVJFL]);
731 raphael 647
		}
648
	}
649
 
730 raphael 650
	/**
651
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
652
	 * en faisant appels aux web services associés
286 aurelien 653
	 * @param array $ligne_resultat
654
	 *
655
	 * @return array la ligne modifiée
656
	 */
284 jpm 657
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
832 raphael 658
		foreach(self::$champ_infos as $cle => $champs_supplementaires) {
729 raphael 659
			if(!in_array($cle, $this->champs_supp)) continue;
660
			// extrait, depuis un élément de $champ_infos:
661
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
662
			extract($champs_supplementaires);
663
			$valeur_recherche = $ligne_resultat[$bdd_champ];
664
			if(!trim($valeur_recherche)) continue;
665
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
666
			$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
277 aurelien 667
		}
284 jpm 668
		return $ligne_resultat;
277 aurelien 669
	}
670
 
284 jpm 671
	/**
672
	 * Fonction qui ajoute les attributions à une ligne de résultats
673
	 *
674
	 * @param array $ligne_tableau_resultat
675
	 * @param array $nom_sci
676
	 */
677
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
285 aurelien 678
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
679
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
680
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
627 aurelien 681
		} else {
682
			$ligne_tableau_resultat = null;
284 jpm 683
		}
684
		return $ligne_tableau_resultat;
685
	}
686
 
687
	private function trierLigneTableau($a, $b) {
688
		$retour = 0;
689
 
690
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
691
			$retour = 0;
692
		}
693
 
694
		if($this->champ_tri == 'code_langue') {
695
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
696
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
697
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
698
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
699
			} else {
700
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
701
			}
702
		} else {
703
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
704
		}
705
		return $retour;
706
	}
707
 
708
	private function comparerChaineSelonDirectionTri($a, $b) {
709
		if($this->direction_tri == 'asc') {
710
			return ($a < $b) ? -1 : 1;
711
		} else {
712
			return ($a > $b) ? -1 : 1;
713
		}
714
	}
715
 
6 jpm 716
	// formatage de la reponse /id ss la forme
717
	// id, nom_vernaculaire, attributions
718
	// langue
719
	// num_nom (correspond à un taxon bdtfx)
720
	public function formaterNomsVernaculairesId($resultat) {
721
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
722
			// on crée les variables qui serviront de clés et on les enléves du tableau
723
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
724
			unset($taxon['num_nom_vernaculaire']);
725
			$langue = $taxon['code_langue'];
726
			unset($taxon['code_langue']);
109 jpm 727
 
6 jpm 728
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
729
				if (isset($taxon[$key]) && $taxon[$key] != "") {
730
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
731
				}
732
			}
733
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
734
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
735
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
736
				}
737
			}
738
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
739
		}
740
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
741
		unset($this->table_retour['href']);
742
		return $this->table_retour;
743
	}
109 jpm 744
 
6 jpm 745
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
746
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
747
			$this->table_retour[$champ] = $valeur;
748
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
749
				switch ($match[1]) {
750
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
751
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
109 jpm 752
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
6 jpm 753
						break;
754
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
755
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
756
					default : break;
757
				}
109 jpm 758
 
6 jpm 759
		} elseif ($langue != '') {
760
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
761
		} else {
762
			$this->table_retour[$champ] = $valeur;
763
		}
764
	}
109 jpm 765
 
6 jpm 766
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
832 raphael 767
		if (isset(self::$champ_infos[$nomChamp])) {
768
			extract(self::$champ_infos[$nomChamp]);
6 jpm 769
		}
109 jpm 770
 
6 jpm 771
		if ($this->retour_format == 'max') {
772
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
773
			if ($service == 'taxons') {
774
				$code_valeur = '';
164 delphine 775
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
109 jpm 776
			} else {
6 jpm 777
				$code_valeur = $this->chercherSignificationCode($url, $nom);
778
			}
779
			if ($projet != '') $projet .= '.';
780
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
781
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
782
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
783
		} else {
784
			if ($projet != '') $projet .= '.';
785
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
786
		}
787
	}
109 jpm 788
 
6 jpm 789
	public function chercherSignificationCode($url, $nom) {
790
		if (isset($this->signification_code[$url])) {
791
			$valeur = $this->signification_code[$url];
792
		} else {
793
			$res = $this->consulterHref($url);
794
			$valeur = $res->$nom;
795
			$this->signification_code[$url] = $valeur;
796
		}
797
		return $valeur;
798
	}
109 jpm 799
 
6 jpm 800
	public function afficherTaxons() {
160 delphine 801
		$resultat = $this->recupererNomTaxons();
6 jpm 802
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
803
			foreach ($langue as $num_nom=>$taxon) {
804
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
805
				if (isset($resultat[$num_tax])) {
164 delphine 806
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
807
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
6 jpm 808
				}
809
			}
810
		}
811
	}
160 delphine 812
 
813
	public function recupererNomTaxons() {
627 aurelien 814
		$taxons = array_unique($this->taxons);
815
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
160 delphine 816
		$res = $this->consulterHref($url);
817
		foreach ($res->resultat as $id=>$taxon) {
164 delphine 818
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
627 aurelien 819
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
160 delphine 820
		}
821
		return $resultat;
822
	}
6 jpm 823
 
824
	public function formaterNomsVernaculairesIdChamp($resultat) {
109 jpm 825
		$this->table_retour['id'] = $this->ressources[0];
826
		$champs = explode(' ', $this->ressources[1]);
6 jpm 827
		if (in_array('attributions', $champs) != false) {
828
			$this->formaterNomsVernaculairesId($resultat);
829
			unset($this->table_retour['nom_vernaculaire']);
160 delphine 830
		} else {
6 jpm 831
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
832
			foreach ($resultat as $taxon) {
833
				foreach ($taxon as $key=>$valeur) {
834
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
835
						$this->table_retour['attributions']['langue'][] = $valeur;
836
					} elseif (in_array($key, $champ_attributions) != false) {
837
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
838
					} elseif (in_array($key, $champs) != false) {
839
						$this->table_retour[$key] = $valeur;
840
					}
841
				}
842
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
843
			}
844
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
845
		}
846
		return $this->table_retour;
847
	}
109 jpm 848
 
6 jpm 849
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
850
		preg_match('/^(.*)\.code$/', $champ, $match);
851
		$champ = $match[1];
832 raphael 852
		if (isset(self::$champ_infos[$champ])) {
853
			extract(self::$champ_infos[$champ]);
6 jpm 854
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
855
			$projet .= '.';
856
		}
109 jpm 857
 
858
		$champs = explode(' ', $this->ressources[1]);
6 jpm 859
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
860
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
861
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
109 jpm 862
		}
6 jpm 863
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
864
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
109 jpm 865
		}
6 jpm 866
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
867
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
109 jpm 868
		}
6 jpm 869
		if (in_array($champ, $champs) !== false) {
870
			if (isset($url)) {
871
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
872
			} else {
873
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
874
			}
109 jpm 875
		}
6 jpm 876
	}
877
 
878
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
879
		if ($this->retour_format == 'max') {
880
				$this->table_retour['attributions'][$nomChamp] = $nom;
881
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
882
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
883
		} else {
884
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
885
		}
886
	}
109 jpm 887
 
6 jpm 888
	public function chargerBiblio($num_nom, $langue) {
889
		list($table, $version) = explode('_v',$this->table);
890
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
891
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
284 jpm 892
		$resultat = $this->getBdd()->recupererTous($requete);
109 jpm 893
 
6 jpm 894
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
895
		 	$r = 'La requête SQL formée comporte une erreur !!';
896
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
897
			Debug::printr($requete);
898
		 } elseif ($resultat) {
899
			foreach ($resultat as $res) {
900
			   	foreach ($res as $cle => $valeur) {
901
			   		if ($valeur !== "") {
902
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
903
			   		}
904
			    }
905
			}
906
		}
907
	}
109 jpm 908
 
6 jpm 909
}
910
?>