Subversion Repositories eFlore/Projets.eflore-projets

Rev

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