1 |
<?php
|
1 |
<?php
|
243 |
|
239 |
|
244 |
//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
|
240 |
//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
|
245 |
// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
|
241 |
// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
|
246 |
public function formerRequeteLimite() {
|
242 |
static function formerRequeteLimite(&$depart, $total, $limite) {
|
247 |
if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
|
- |
|
248 |
$this->requete_limite = '';
|
243 |
if ($depart > $total) {
|
249 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
- |
|
250 |
$this->limite_requete['depart'] =
|
- |
|
251 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
244 |
$depart = $total - $limite < 0 ? 0 : ($total - $limite);
|
252 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
245 |
return ' LIMIT ' . $depart . ', ' . $limite;
|
253 |
} else {
|
246 |
}
|
254 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
- |
|
255 |
}
|
- |
|
256 |
return $this->requete_limite;
|
247 |
return ' LIMIT ' . $depart . ', ' . $limite;
|
257 |
}
|
248 |
}
|
258 |
|
249 |
|
259 |
//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
|
250 |
//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
|
260 |
public function recupererTotalResultat() {
|
251 |
public function recupererTotalResultat() {
|
- |
|
252 |
$res = $this->getBdd()->recuperer(sprintf(
|
- |
|
253 |
'SELECT COUNT(%s) AS nombre FROM %s WHERE %s -- %s:%d',
|
- |
|
254 |
|
261 |
$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
|
255 |
$this->format_reponse == 'noms-vernaculaires/attributions' ? 'id' : 'distinct(id)',
|
262 |
$requete = 'SELECT count('.$distinct.') as nombre FROM '
|
- |
|
263 |
.$this->table
|
256 |
$this->table,
|
264 |
.$this->formerRequeteCondition();
|
257 |
$this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
|
265 |
$res = $this->getBdd()->recuperer($requete);
|
258 |
__FILE__, __LINE__));
|
266 |
|
259 |
|
267 |
if ($res) {
|
260 |
if (! $res)
|
- |
|
261 |
throw new Exception('Données introuvables', RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
|
268 |
$total = $res['nombre'];
|
262 |
if($res['nombre'] == 0) {
|
- |
|
263 |
print json_encode(
|
269 |
} else {
|
264 |
array(
|
- |
|
265 |
"entete" => array(
|
270 |
$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
|
266 |
"depart" => $this->limite_requete['depart'],
|
271 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
|
267 |
"limite" => $this->limite_requete['limite'],
|
- |
|
268 |
"masque" => $this->recupererMasque(),
|
- |
|
269 |
"total" => 0
|
- |
|
270 |
),
|
- |
|
271 |
"resultat" => array()
|
- |
|
272 |
));
|
- |
|
273 |
die; // die() très dommage (pour phpunit), mais la stack d'imbrication ne nous permet pas de retourner proprement
|
- |
|
274 |
}
|
272 |
}
|
275 |
|
273 |
return $total;
|
276 |
return $res['nombre'];
|
274 |
}
|
277 |
}
|
275 |
|
278 |
|
276 |
//+------------------------------------------------------------------------------------------------------+
|
279 |
//+------------------------------------------------------------------------------------------------------+
|
277 |
// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
|
280 |
// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
|
278 |
// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
|
281 |
// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
|
279 |
public function retournerResultatFormate($resultat) {
|
282 |
public function retournerResultatFormate($resultat) {
|
280 |
$this->recupererTableConfig('correspondance_champs');
|
283 |
$this->recupererTableConfig('correspondance_champs');
|
281 |
switch ($this->format_reponse) {
|
284 |
switch ($this->format_reponse) {
|
282 |
case 'noms-vernaculaires' :
|
285 |
case 'noms-vernaculaires' :
|
283 |
$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat); break;
|
286 |
$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat); break;
|
284 |
case 'noms-vernaculaires/attributions' : $reponse = $this->formaterNomsVernaculairesAttributions($resultat); break;
|
287 |
case 'noms-vernaculaires/attributions' : $reponse = $this->formaterNomsVernaculairesAttributions($resultat); break;
|
285 |
case 'noms-vernaculaires/id' : $reponse = $this->formaterNomsVernaculairesId($resultat); break;
|
288 |
case 'noms-vernaculaires/id' : $reponse = $this->formaterNomsVernaculairesId($resultat); break;
|
286 |
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
|
289 |
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
|
287 |
default : break;
|
290 |
default : break;
|
288 |
}
|
291 |
}
|
289 |
return $reponse;
|
292 |
return $reponse;
|
290 |
}
|
293 |
}
|
291 |
|
294 |
|
292 |
public function ajouterJsonEnTeteNV() {
|
295 |
public function ajouterJsonEnTeteNV() {
|
293 |
$table_retour_json['masque'] = $this->recupererMasque();
|
296 |
$table_retour_json['masque'] = $this->recupererMasque();
|
294 |
$table_retour_json['depart'] = $this->limite_requete['depart'];
|
297 |
$table_retour_json['depart'] = $this->limite_requete['depart'];
|
295 |
$table_retour_json['limite'] = $this->limite_requete['limite'];
|
298 |
$table_retour_json['limite'] = $this->limite_requete['limite'];
|
296 |
$table_retour_json['total'] = $this->total_resultat;
|
299 |
$table_retour_json['total'] = $this->total_resultat;
|
297 |
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
|
300 |
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
|
298 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
301 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
299 |
$table_retour_json['href.precedent'] = $url['precedent'];
|
302 |
$table_retour_json['href.precedent'] = $url['precedent'];
|
300 |
}
|
303 |
}
|
301 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
304 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
302 |
$table_retour_json['href.suivant'] = $url['suivant'];
|
305 |
$table_retour_json['href.suivant'] = $url['suivant'];
|
303 |
}
|
306 |
}
|
304 |
return $table_retour_json;
|
307 |
return $table_retour_json;
|
305 |
}
|
308 |
}
|
306 |
|
309 |
|
307 |
public function ajouterJsonResultatNV($resultat) {
|
310 |
public function ajouterJsonResultatNV($resultat) {
|
308 |
foreach ($resultat as $tab) {
|
311 |
foreach ($resultat as $tab) {
|
309 |
foreach ($tab as $key => $valeur) {
|
312 |
foreach ($tab as $key => $valeur) {
|
310 |
if ($valeur != '') {
|
313 |
if ($valeur != '') {
|
311 |
switch ($key) {
|
314 |
switch ($key) {
|
312 |
case 'id' : $num = $valeur; break;
|
315 |
case 'id' : $num = $valeur; break;
|
313 |
case 'nom_vernaculaire' : $this->table_retour['nom'] = $valeur; break;
|
316 |
case 'nom_vernaculaire' : $this->table_retour['nom'] = $valeur; break;
|
314 |
default : break;
|
317 |
default : break;
|
315 |
}
|
318 |
}
|
316 |
}
|
319 |
}
|
317 |
}
|
320 |
}
|
318 |
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
|
321 |
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
|
319 |
$resultat_json[$num] = $this->table_retour;
|
322 |
$resultat_json[$num] = $this->table_retour;
|
320 |
$this->table_retour = array();
|
323 |
$this->table_retour = array();
|
321 |
}
|
324 |
}
|
322 |
return $resultat_json;
|
325 |
return $resultat_json;
|
323 |
}
|
326 |
}
|
324 |
|
327 |
|
325 |
|
328 |
|
326 |
public function formaterNomsVernaculaires($resultat) {
|
329 |
public function formaterNomsVernaculaires($resultat) {
|
327 |
$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
|
330 |
$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
|
328 |
$resultat = $this->hierarchiserResultat($resultat);
|
331 |
$resultat = $this->hierarchiserResultat($resultat);
|
329 |
$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
|
332 |
$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
|
330 |
return $table_retour_json;
|
333 |
return $table_retour_json;
|
331 |
}
|
334 |
}
|
332 |
|
335 |
|
333 |
public function hierarchiserResultat($resultat) {
|
336 |
public function hierarchiserResultat($resultat) {
|
334 |
//tri recherche floue
|
337 |
//tri recherche floue
|
335 |
if (isset($this->parametres['masque.nv'])) {
|
338 |
if (isset($this->parametres['masque.nv'])) {
|
336 |
$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
|
339 |
return $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
|
337 |
}
|
340 |
}
|
338 |
if (isset($this->parametres['masque'])) {
|
341 |
if (isset($this->parametres['masque'])) {
|
339 |
$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
|
342 |
return $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
|
340 |
}
|
343 |
}
|
341 |
return $resultat;
|
344 |
return $resultat;
|
342 |
}
|
345 |
}
|
343 |
|
346 |
|
344 |
public function recupererMasque() {
|
347 |
public function recupererMasque() {
|
345 |
$tab_masque = array();
|
348 |
$tab_masque = array();
|
346 |
foreach ($this->parametres as $param=>$valeur) {
|
349 |
foreach ($this->parametres as $param=>$valeur) {
|
347 |
if (strstr($param, 'masque') != false) {
|
350 |
if (strstr($param, 'masque') != false) {
|
348 |
$tab_masque[] = $param.'='.$valeur;
|
351 |
$tab_masque[] = $param.'='.$valeur;
|
349 |
}
|
352 |
}
|
350 |
}
|
353 |
}
|
351 |
$masque = implode('&', $tab_masque);
|
354 |
return implode('&', $tab_masque);
|
352 |
return $masque;
|
- |
|
353 |
}
|
355 |
}
|
354 |
|
356 |
|
355 |
public function formaterEnOss($resultat) {
|
357 |
public function formaterEnOss($resultat) {
|
356 |
$table_nom = array();
|
358 |
$table_nom = array();
|
357 |
$oss = '';
|
359 |
$oss = '';
|
358 |
foreach ($resultat as $tab) {
|
360 |
foreach ($resultat as $tab) {
|
359 |
if (isset($tab['nom_vernaculaire']) ) {
|
361 |
if (isset($tab['nom_vernaculaire']) ) {
|
360 |
if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
|
362 |
if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
|
361 |
$table_nom[] = $tab['nom_vernaculaire'];
|
363 |
$table_nom[] = $tab['nom_vernaculaire'];
|
362 |
$oss [] = $tab['nom_vernaculaire'];
|
364 |
$oss [] = $tab['nom_vernaculaire'];
|
363 |
}
|
365 |
}
|
364 |
}
|
366 |
}
|
365 |
}
|
367 |
}
|
366 |
if (isset($this->masque)) $masque = implode('&', $this->masque);
|
368 |
if (isset($this->masque)) $masque = implode('&', $this->masque);
|
367 |
else $masque = 'Pas de masque';
|
369 |
else $masque = 'Pas de masque';
|
368 |
$table_retour_oss = array($masque, $oss);
|
370 |
return array($masque, $oss);
|
369 |
return $table_retour_oss;
|
- |
|
370 |
}
|
371 |
}
|
371 |
|
372 |
|
372 |
public function formaterNomsVernaculairesAttributions($resultat) {
|
373 |
public function formaterNomsVernaculairesAttributions($resultat) {
|
373 |
//on remplie la table $table_retour_json['entete']
|
374 |
//on remplie la table $table_retour_json['entete']
|
374 |
$table_retour_json['entete']['masque'] = $this->recupererMasque();
|
375 |
$table_retour_json['entete']['masque'] = $this->recupererMasque();
|
375 |
$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
|
376 |
$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
|
376 |
$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
|
377 |
$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
|
377 |
$table_retour_json['entete']['total'] = $this->total_resultat;
|
378 |
$table_retour_json['entete']['total'] = $this->total_resultat;
|
378 |
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
|
379 |
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
|
379 |
if (!empty($url['precedent'])) {
|
380 |
if (!empty($url['precedent'])) {
|
380 |
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
|
381 |
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
|
381 |
}
|
382 |
}
|
382 |
if (!empty($url['suivant'])) {
|
383 |
if (!empty($url['suivant'])) {
|
383 |
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
|
384 |
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
|
384 |
}
|
385 |
}
|
385 |
foreach ($resultat as &$tab) {
|
386 |
foreach ($resultat as &$tab) {
|
386 |
$nnv = $tab['num_nom_vernaculaire'];
|
387 |
$nnv = $tab['num_nom_vernaculaire'];
|
387 |
$resultat_json[$nnv]['id'] = $tab['id'];
|
388 |
$resultat_json[$nnv]['id'] = $tab['id'];
|
388 |
$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
|
389 |
$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
|
389 |
$resultat_json[$nnv]['langue.code'] = $resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
|
390 |
$resultat_json[$nnv]['langue.code'] = $resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
|
390 |
$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
|
391 |
$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
|
391 |
if ($this->retour_format == 'max') {
|
392 |
if ($this->retour_format == 'max') {
|
392 |
$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
|
393 |
$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
|
393 |
if($this->champs_supp) {
|
394 |
if($this->champs_supp) {
|
394 |
//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
|
395 |
//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
|
395 |
// simple initialisation par copie de la référence de l'original
|
396 |
// simple initialisation par copie de la référence de l'original
|
396 |
$resultat_json[$nnv] = &$tab;
|
397 |
$resultat_json[$nnv] = &$tab;
|
397 |
}
|
398 |
}
|
398 |
else {
|
399 |
else {
|
399 |
$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
|
400 |
$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
|
400 |
$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
|
401 |
$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
|
401 |
$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
|
402 |
$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
|
402 |
$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
|
403 |
$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
|
403 |
}
|
404 |
}
|
404 |
}
|
405 |
}
|
405 |
}
|
406 |
}
|
406 |
|
407 |
|
407 |
// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
|
408 |
// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
|
408 |
// vers le tableau de valeurs original
|
409 |
// vers le tableau de valeurs original
|
409 |
if ($this->retour_format == 'max' && $this->champs_supp) {
|
410 |
if ($this->retour_format == 'max' && $this->champs_supp) {
|
410 |
// récupérons désormais les ontologies
|
411 |
// récupérons désormais les ontologies
|
411 |
$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
|
412 |
$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
|
412 |
}
|
413 |
}
|
413 |
|
414 |
|
414 |
if ($this->retour_format == 'max') {
|
415 |
if ($this->retour_format == 'max') {
|
415 |
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
|
416 |
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
|
416 |
// fois et les attribuer aux noms car c'est beaucoup plus rapide
|
417 |
// fois et les attribuer aux noms car c'est beaucoup plus rapide
|
417 |
$noms_sci = $this->recupererNomTaxons();
|
418 |
$noms_sci = $this->recupererNomTaxons();
|
418 |
foreach ($resultat_json as $num_nom => &$tab) {
|
419 |
foreach ($resultat_json as $num_nom => &$tab) {
|
419 |
$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
|
420 |
$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
|
420 |
if($tab == null) {
|
421 |
if($tab == null) {
|
421 |
unset($resultat_json[$num_nom]);
|
422 |
unset($resultat_json[$num_nom]);
|
422 |
}
|
423 |
}
|
423 |
}
|
424 |
}
|
424 |
}
|
425 |
}
|
425 |
|
426 |
|
426 |
$table_retour_json['resultat'] = $resultat_json;
|
427 |
$table_retour_json['resultat'] = $resultat_json;
|
427 |
return $table_retour_json;
|
428 |
return $table_retour_json;
|
428 |
}
|
429 |
}
|
429 |
|
430 |
|
430 |
/**
|
431 |
/**
|
431 |
* Ajoute les champs d'ontologie supplémentaires si necéssaire
|
432 |
* Ajoute les champs d'ontologie supplémentaires si necéssaire
|
432 |
* en faisant appels aux web services associés.
|
433 |
* en faisant appels aux web services associés.
|
433 |
* Les appels peuvent être fait individuellement (pour un couple <ontologie:valeur>) ou bien
|
434 |
* Les appels peuvent être fait individuellement (pour un couple <ontologie:valeur>) ou bien
|
434 |
* regroupés, **si le webservice correspondant le supporte**.
|
435 |
* regroupés, **si le webservice correspondant le supporte**.
|
435 |
*
|
436 |
*
|
436 |
* Nous disposons à ce jour de 3 (trois) webservices d'ontologies correspondant aux noms vernaculaires (cf $champ_infos)
|
437 |
* Nous disposons à ce jour de 3 (trois) webservices d'ontologies correspondant aux noms vernaculaires (cf $champ_infos)
|
437 |
* Mais 2 d'entre eux sont identiques, il s'agit de /nvjfl/ontologies/. Or ce webservice supporte le multi-critère.
|
438 |
* Mais 2 d'entre eux sont identiques, il s'agit de /nvjfl/ontologies/. Or ce webservice supporte le multi-critère.
|
438 |
* Nous pouvons donc factorisé l'appel pour "conseil_emploi" et "genre", mais pas pour "taxon".
|
439 |
* Nous pouvons donc factorisé l'appel pour "conseil_emploi" et "genre", mais pas pour "taxon".
|
439 |
*
|
440 |
*
|
440 |
* @param array in/out $resultats: tous les résultats
|
441 |
* @param array in/out $resultats: tous les résultats
|
441 |
*/
|
442 |
*/
|
442 |
public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
|
443 |
public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
|
443 |
$champs_sup = array_intersect($this->champs_supp, array_keys(self::$champ_infos));
|
444 |
$champs_sup = array_intersect($this->champs_supp, array_keys(self::$champ_infos));
|
444 |
|
445 |
|
445 |
// La regroupement des toutes les valeurs recherchées (pour tous les
|
446 |
// La regroupement des toutes les valeurs recherchées (pour tous les
|
446 |
// résultats), pour "les" onotologies supportant le multi-critère est effectué ci-dessous.
|
447 |
// résultats), pour "les" onotologies supportant le multi-critère est effectué ci-dessous.
|
447 |
// Dans les faits ce n'est le cas que pour nvjfl.
|
448 |
// Dans les faits ce n'est le cas que pour nvjfl.
|
448 |
$ontologieParamPending = self::NvjflOntologieIndex($resultats, $champs_sup);
|
449 |
$ontologieParamPending = self::NvjflOntologieIndex($resultats, $champs_sup);
|
449 |
$this->NvjflOntologieExpand($ontologieParamPending);
|
450 |
$this->NvjflOntologieExpand($ontologieParamPending);
|
450 |
self::NvjflOntologieCombine($resultats);
|
451 |
self::NvjflOntologieCombine($resultats);
|
451 |
|
452 |
|
452 |
// pour les ontologies multi-critères, on vient de le régler ci-dessus
|
453 |
// pour les ontologies multi-critères, on vient de le régler ci-dessus
|
453 |
$champs_sup = array_diff($champs_sup, self::$onto_multi_support);
|
454 |
$champs_sup = array_diff($champs_sup, self::$onto_multi_support);
|
454 |
|
455 |
|
455 |
|
456 |
|
456 |
// ici, $champs_sup ne peut contenir, au plus, que "taxon".
|
457 |
// ici, $champs_sup ne peut contenir, au plus, que "taxon".
|
457 |
// code historique:
|
458 |
// code historique:
|
458 |
foreach($champs_sup as $cle) {
|
459 |
foreach($champs_sup as $cle) {
|
459 |
$champs_supplementaires = self::$champ_infos[$cle];
|
460 |
$champs_supplementaires = self::$champ_infos[$cle];
|
460 |
// extrait, depuis un élément de $champ_infos:
|
461 |
// extrait, depuis un élément de $champ_infos:
|
461 |
// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
|
462 |
// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
|
462 |
extract($champs_supplementaires);
|
463 |
extract($champs_supplementaires);
|
463 |
|
464 |
|
464 |
foreach ($resultats as &$tab) {
|
465 |
foreach ($resultats as &$tab) {
|
465 |
$valeur_recherche = $tab[$bdd_champ];
|
466 |
$valeur_recherche = $tab[$bdd_champ];
|
466 |
if(!trim($valeur_recherche)) continue;
|
467 |
if(!trim($valeur_recherche)) continue;
|
467 |
|
468 |
|
468 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
469 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
469 |
$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
|
470 |
$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
|
470 |
}
|
471 |
}
|
471 |
}
|
472 |
}
|
472 |
}
|
473 |
}
|
473 |
|
474 |
|
474 |
/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
|
475 |
/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
|
475 |
spécifiquement au service d'Ontologies de NVJFL.
|
476 |
spécifiquement au service d'Ontologies de NVJFL.
|
476 |
Aggrège les valeurs dans le tableau retourné.
|
477 |
Aggrège les valeurs dans le tableau retourné.
|
477 |
Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
|
478 |
Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
|
478 |
un élément du résultat. */
|
479 |
un élément du résultat. */
|
479 |
static function NvjflOntologieIndex(&$resultats, $champs_sup) {
|
480 |
static function NvjflOntologieIndex(&$resultats, $champs_sup) {
|
480 |
// nous ne supportons le multi-critère que sur les ontologies nvjfl, et nous
|
481 |
// nous ne supportons le multi-critère que sur les ontologies nvjfl, et nous
|
481 |
// avons précisé celles qui sont concernées dans self::$onto_multi_support
|
482 |
// avons précisé celles qui sont concernées dans self::$onto_multi_support
|
482 |
$champs_sup = array_intersect($champs_sup, self::$onto_multi_support);
|
483 |
$champs_sup = array_intersect($champs_sup, self::$onto_multi_support);
|
483 |
$ontologieParamPending = Array();
|
484 |
$ontologieParamPending = Array();
|
484 |
foreach($resultats as &$resultat) {
|
485 |
foreach($resultats as &$resultat) {
|
485 |
foreach($champs_sup as $v) {
|
486 |
foreach($champs_sup as $v) {
|
486 |
// de cet extract() nous n'utilisons que $bdd_champ et $ressource
|
487 |
// de cet extract() nous n'utilisons que $bdd_champ et $ressource
|
487 |
extract(self::$champ_infos[$v]);
|
488 |
extract(self::$champ_infos[$v]);
|
488 |
if(!isset($resultat[$bdd_champ])) continue;
|
489 |
if(!isset($resultat[$bdd_champ])) continue;
|
489 |
|
490 |
|
490 |
$valeur_recherche = $resultat[$bdd_champ];
|
491 |
$valeur_recherche = $resultat[$bdd_champ];
|
491 |
if(!trim($valeur_recherche)) continue;
|
492 |
if(!trim($valeur_recherche)) continue;
|
492 |
|
493 |
|
493 |
// XXX: $ressource contient déjà ':' comme suffixe
|
494 |
// XXX: $ressource contient déjà ':' comme suffixe
|
494 |
$critere = $ressource . $valeur_recherche;
|
495 |
$critere = $ressource . $valeur_recherche;
|
495 |
$ontologieParamPending[$critere] = NULL;
|
496 |
$ontologieParamPending[$critere] = NULL;
|
496 |
// placeholder pour le résultat
|
497 |
// placeholder pour le résultat
|
497 |
$resultat[SPE_INDEX_NVJFL][$v][$critere] =
|
498 |
$resultat[SPE_INDEX_NVJFL][$v][$critere] =
|
498 |
&$ontologieParamPending[$critere];
|
499 |
&$ontologieParamPending[$critere];
|
499 |
}
|
500 |
}
|
500 |
}
|
501 |
}
|
501 |
return $ontologieParamPending;
|
502 |
return $ontologieParamPending;
|
502 |
}
|
503 |
}
|
503 |
|
504 |
|
504 |
// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
|
505 |
// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
|
505 |
/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
|
506 |
/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
|
506 |
créé une URL multi-critère.
|
507 |
créé une URL multi-critère.
|
507 |
Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
|
508 |
Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
|
508 |
des couples <ressource:ValeurRecherchée>.
|
509 |
des couples <ressource:ValeurRecherchée>.
|
509 |
L'URL est appelée et la valeur correspondante est remplacée dans $criteres_requete.
|
510 |
L'URL est appelée et la valeur correspondante est remplacée dans $criteres_requete.
|
510 |
|
511 |
|
511 |
Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
|
512 |
Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
|
512 |
la valeur est référencée par un élément d'une ou plusieurs lignes de $resultat correspondantes.
|
513 |
la valeur est référencée par un élément d'une ou plusieurs lignes de $resultat correspondantes.
|
513 |
Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
|
514 |
Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
|
514 |
public function NvjflOntologieExpand(&$criteres_requete) {
|
515 |
public function NvjflOntologieExpand(&$criteres_requete) {
|
515 |
// équivalent spécifique de ajouterHrefAutreProjet()
|
516 |
// équivalent spécifique de ajouterHrefAutreProjet()
|
516 |
$valeurs_requises = implode(',', array_keys($criteres_requete));
|
517 |
$valeurs_requises = implode(',', array_keys($criteres_requete));
|
517 |
// en vérité, nous ne supportons ceci ici que pour nvjfl et non n'importe quel url_service
|
518 |
// en vérité, nous ne supportons ceci ici que pour nvjfl et non n'importe quel url_service
|
518 |
$url = Config::get('url_service').'/ontologies/'.$valeurs_requises;
|
519 |
$url = Config::get('url_service').'/ontologies/'.$valeurs_requises;
|
519 |
$val = $this->consulterHref($url);
|
520 |
$val = $this->consulterHref($url);
|
520 |
|
521 |
|
521 |
// TODO, le webservice d'ontologies devrait être modifié pour retourner un tableau
|
522 |
// TODO, le webservice d'ontologies devrait être modifié pour retourner un tableau
|
522 |
// indexé par critère requesté à *CHAQUE* fois, y compris lorsque 1 seul critère est
|
523 |
// indexé par critère requesté à *CHAQUE* fois, y compris lorsque 1 seul critère est
|
523 |
// demandé.
|
524 |
// demandé.
|
524 |
if(array_key_exists('id', $val) && count($criteres_requete) == 1) {
|
525 |
if(array_key_exists('id', $val) && count($criteres_requete) == 1) {
|
525 |
$k = key($criteres_requete);
|
526 |
$k = key($criteres_requete);
|
526 |
$criteres_requete[$k] = $val;
|
527 |
$criteres_requete[$k] = $val;
|
527 |
return;
|
528 |
return;
|
528 |
}
|
529 |
}
|
529 |
|
530 |
|
530 |
// subtilité, cette affectation modifie par conséquent les valeurs dans
|
531 |
// subtilité, cette affectation modifie par conséquent les valeurs dans
|
531 |
// $resultats[X][SPE_INDEX_NVJFL]
|
532 |
// $resultats[X][SPE_INDEX_NVJFL]
|
532 |
// dont la référence pointe toujours sur $v
|
533 |
// dont la référence pointe toujours sur $v
|
533 |
foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
|
534 |
foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
|
534 |
}
|
535 |
}
|
535 |
|
536 |
|
536 |
/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
|
537 |
/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
|
537 |
NVJFL en adéquation avec les champs attendus en sortie.
|
538 |
NVJFL en adéquation avec les champs attendus en sortie.
|
538 |
Dès l'indexation des critères, nous avons associé une (ou plusieurs) référence(s) du
|
539 |
Dès l'indexation des critères, nous avons associé une (ou plusieurs) référence(s) du
|
539 |
tableau de résultats vers le tableau de retour des ontologies à l'aide d'un index
|
540 |
tableau de résultats vers le tableau de retour des ontologies à l'aide d'un index
|
540 |
particulier l'index SPE_INDEX_NVJFL qui contient comme élément(s)
|
541 |
particulier l'index SPE_INDEX_NVJFL qui contient comme élément(s)
|
541 |
un ou plusieurs ontologies (les indexes de self::$champ_infos) qui elles-mêmes contiennent
|
542 |
un ou plusieurs ontologies (les indexes de self::$champ_infos) qui elles-mêmes contiennent
|
542 |
une ou plusieurs valeurs représentant les valeurs recherchées appartement à cette ontologies.
|
543 |
une ou plusieurs valeurs représentant les valeurs recherchées appartement à cette ontologies.
|
543 |
Celui-ci est supprimé après avoir été correctement copié. */
|
544 |
Celui-ci est supprimé après avoir été correctement copié. */
|
544 |
/**
|
545 |
/**
|
545 |
* @param array in/out $resultats: tous les résultats
|
546 |
* @param array in/out $resultats: tous les résultats
|
546 |
* @param array in $critere: tableau des ontologies:valeur demandées, de la forme [ numStatut:1, genreNombre:11, ... ]
|
547 |
* @param array in $critere: tableau des ontologies:valeur demandées, de la forme [ numStatut:1, genreNombre:11, ... ]
|
547 |
*/
|
548 |
*/
|
548 |
static function NvjflOntologieCombine(&$resultats) {
|
549 |
static function NvjflOntologieCombine(&$resultats) {
|
549 |
foreach($resultats as &$resultat) {
|
550 |
foreach($resultats as &$resultat) {
|
550 |
if(!array_key_exists(SPE_INDEX_NVJFL, $resultat)) continue;
|
551 |
if(!array_key_exists(SPE_INDEX_NVJFL, $resultat)) continue;
|
551 |
|
552 |
|
552 |
/* Note: la complétude d'un résultat peut dépendre de plusieurs ontologies différentes,
|
553 |
/* Note: la complétude d'un résultat peut dépendre de plusieurs ontologies différentes,
|
553 |
d'où cette boucle. Cependant une seule valeur sera demandé pour cette ontologie, c'est pourquoi
|
554 |
d'où cette boucle. Cependant une seule valeur sera demandé pour cette ontologie, c'est pourquoi
|
554 |
$resultat[SPE_INDEX_NVJFL][$onto_name], s'il existe, ne contiendra toujours qu'un seul élément.
|
555 |
$resultat[SPE_INDEX_NVJFL][$onto_name], s'il existe, ne contiendra toujours qu'un seul élément.
|
555 |
Puisque par définition un résultat contenant des valeurs d'ontologie n'aura jamais qu'un seul et unique
|
556 |
Puisque par définition un résultat contenant des valeurs d'ontologie n'aura jamais qu'un seul et unique
|
556 |
attribut num_genre (ou num_statut, ou autre) */
|
557 |
attribut num_genre (ou num_statut, ou autre) */
|
557 |
foreach(self::$onto_multi_support as $onto_name) {
|
558 |
foreach(self::$onto_multi_support as $onto_name) {
|
558 |
if(!array_key_exists($onto_name, $resultat[SPE_INDEX_NVJFL])) continue;
|
559 |
if(!array_key_exists($onto_name, $resultat[SPE_INDEX_NVJFL])) continue;
|
559 |
|
560 |
|
560 |
/* $onto_name est un nom d'ontologie (l'une des clefs, parmi conseil_emploi et genre,
|
561 |
/* $onto_name est un nom d'ontologie (l'une des clefs, parmi conseil_emploi et genre,
|
561 |
cf la boucle sur $champs_sup dans NvjflOntologieIndex()
|
562 |
cf la boucle sur $champs_sup dans NvjflOntologieIndex()
|
562 |
de cet extract() nous n'utilisons que $intitule et $nom */
|
563 |
de cet extract() nous n'utilisons que $intitule et $nom */
|
563 |
extract(self::$champ_infos[$onto_name]);
|
564 |
extract(self::$champ_infos[$onto_name]);
|
564 |
|
565 |
|
565 |
// equivalent de l'affectation finale de chercherSignificationCode()
|
566 |
// equivalent de l'affectation finale de chercherSignificationCode()
|
566 |
// (utilisé lors de recherches d'ontologies en mono-critère)
|
567 |
// (utilisé lors de recherches d'ontologies en mono-critère)
|
567 |
// XXX: PHP-5.3 pas de récupération d'attribut sur fonction
|
568 |
// XXX: PHP-5.3 pas de récupération d'attribut sur fonction
|
568 |
$r = current($resultat[SPE_INDEX_NVJFL][$onto_name]);
|
569 |
$r = current($resultat[SPE_INDEX_NVJFL][$onto_name]);
|
569 |
$resultat[$intitule] = $r->$nom;
|
570 |
$resultat[$intitule] = $r->$nom;
|
570 |
|
571 |
|
571 |
// XXX: certes nous pourrions nous contenter du unset() final
|
572 |
// XXX: certes nous pourrions nous contenter du unset() final
|
572 |
unset($resultat[SPE_INDEX_NVJFL][$onto_name]);
|
573 |
unset($resultat[SPE_INDEX_NVJFL][$onto_name]);
|
573 |
}
|
574 |
}
|
574 |
unset($resultat[SPE_INDEX_NVJFL]);
|
575 |
unset($resultat[SPE_INDEX_NVJFL]);
|
575 |
}
|
576 |
}
|
576 |
}
|
577 |
}
|
577 |
|
578 |
|
578 |
/**
|
579 |
/**
|
579 |
* Ajoute les champs d'ontologie supplémentaires si necéssaire
|
580 |
* Ajoute les champs d'ontologie supplémentaires si necéssaire
|
580 |
* en faisant appels aux web services associés
|
581 |
* en faisant appels aux web services associés
|
581 |
* @param array $ligne_resultat
|
582 |
* @param array $ligne_resultat
|
582 |
*
|
583 |
*
|
583 |
* @return array la ligne modifiée
|
584 |
* @return array la ligne modifiée
|
584 |
*/
|
585 |
*/
|
585 |
public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
|
586 |
public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
|
586 |
foreach(self::$champ_infos as $cle => $champs_supplementaires) {
|
587 |
foreach(self::$champ_infos as $cle => $champs_supplementaires) {
|
587 |
if(!in_array($cle, $this->champs_supp)) continue;
|
588 |
if(!in_array($cle, $this->champs_supp)) continue;
|
588 |
// extrait, depuis un élément de $champ_infos:
|
589 |
// extrait, depuis un élément de $champ_infos:
|
589 |
// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
|
590 |
// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
|
590 |
extract($champs_supplementaires);
|
591 |
extract($champs_supplementaires);
|
591 |
$valeur_recherche = $ligne_resultat[$bdd_champ];
|
592 |
$valeur_recherche = $ligne_resultat[$bdd_champ];
|
592 |
if(!trim($valeur_recherche)) continue;
|
593 |
if(!trim($valeur_recherche)) continue;
|
593 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
594 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
594 |
$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
|
595 |
$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
|
595 |
}
|
596 |
}
|
596 |
return $ligne_resultat;
|
597 |
return $ligne_resultat;
|
597 |
}
|
598 |
}
|
598 |
|
599 |
|
599 |
/**
|
600 |
/**
|
600 |
* Fonction qui ajoute les attributions à une ligne de résultats
|
601 |
* Fonction qui ajoute les attributions à une ligne de résultats
|
601 |
*
|
602 |
*
|
602 |
* @param array $ligne_tableau_resultat
|
603 |
* @param array $ligne_tableau_resultat
|
603 |
* @param array $nom_sci
|
604 |
* @param array $nom_sci
|
604 |
*/
|
605 |
*/
|
605 |
public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
|
606 |
public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
|
606 |
if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
|
607 |
if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
|
607 |
$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
|
608 |
$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
|
608 |
$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
|
609 |
$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
|
609 |
} else {
|
610 |
} else {
|
610 |
$ligne_tableau_resultat = null;
|
611 |
$ligne_tableau_resultat = null;
|
611 |
}
|
612 |
}
|
612 |
return $ligne_tableau_resultat;
|
613 |
return $ligne_tableau_resultat;
|
613 |
}
|
614 |
}
|
614 |
|
615 |
|
615 |
private function trierLigneTableau($a, $b) {
|
616 |
private function trierLigneTableau($a, $b) {
|
616 |
$retour = 0;
|
617 |
$retour = 0;
|
617 |
|
618 |
|
618 |
if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
|
619 |
if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
|
619 |
$retour = 0;
|
620 |
$retour = 0;
|
620 |
}
|
621 |
}
|
621 |
|
622 |
|
622 |
if($this->champ_tri == 'code_langue') {
|
623 |
if($this->champ_tri == 'code_langue') {
|
623 |
if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
|
624 |
if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
|
624 |
$retour = ($this->direction_tri == 'asc') ? -1 : 1;
|
625 |
$retour = ($this->direction_tri == 'asc') ? -1 : 1;
|
625 |
} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
|
626 |
} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
|
626 |
$retour = ($this->direction_tri == 'asc') ? 1 : -1;
|
627 |
$retour = ($this->direction_tri == 'asc') ? 1 : -1;
|
627 |
} else {
|
628 |
} else {
|
628 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
629 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
629 |
}
|
630 |
}
|
630 |
} else {
|
631 |
} else {
|
631 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
632 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
632 |
}
|
633 |
}
|
633 |
return $retour;
|
634 |
return $retour;
|
634 |
}
|
635 |
}
|
635 |
|
636 |
|
636 |
private function comparerChaineSelonDirectionTri($a, $b) {
|
637 |
private function comparerChaineSelonDirectionTri($a, $b) {
|
637 |
if($this->direction_tri == 'asc') {
|
638 |
if($this->direction_tri == 'asc') {
|
638 |
return ($a < $b) ? -1 : 1;
|
639 |
return ($a < $b) ? -1 : 1;
|
639 |
} else {
|
640 |
} else {
|
640 |
return ($a > $b) ? -1 : 1;
|
641 |
return ($a > $b) ? -1 : 1;
|
641 |
}
|
642 |
}
|
642 |
}
|
643 |
}
|
643 |
|
644 |
|
644 |
// formatage de la reponse /id ss la forme
|
645 |
// formatage de la reponse /id ss la forme
|
645 |
// id, nom_vernaculaire, attributions
|
646 |
// id, nom_vernaculaire, attributions
|
646 |
// langue
|
647 |
// langue
|
647 |
// num_nom (correspond à un taxon bdtfx)
|
648 |
// num_nom (correspond à un taxon bdtfx)
|
648 |
public function formaterNomsVernaculairesId($resultat) {
|
649 |
public function formaterNomsVernaculairesId($resultat) {
|
649 |
foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
|
650 |
foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
|
650 |
// on crée les variables qui serviront de clés et on les enléves du tableau
|
651 |
// on crée les variables qui serviront de clés et on les enléves du tableau
|
651 |
$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
|
652 |
$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
|
652 |
unset($taxon['num_nom_vernaculaire']);
|
653 |
unset($taxon['num_nom_vernaculaire']);
|
653 |
$langue = $taxon['code_langue'];
|
654 |
$langue = $taxon['code_langue'];
|
654 |
unset($taxon['code_langue']);
|
655 |
unset($taxon['code_langue']);
|
655 |
|
656 |
|
656 |
foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
|
657 |
foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
|
657 |
if (isset($taxon[$key]) && $taxon[$key] != "") {
|
658 |
if (isset($taxon[$key]) && $taxon[$key] != "") {
|
658 |
$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
|
659 |
$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
|
659 |
}
|
660 |
}
|
660 |
}
|
661 |
}
|
661 |
foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
|
662 |
foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
|
662 |
if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
|
663 |
if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
|
663 |
$this->afficherDonnees($key, $valeur, $langue, $num_nom);
|
664 |
$this->afficherDonnees($key, $valeur, $langue, $num_nom);
|
664 |
}
|
665 |
}
|
665 |
}
|
666 |
}
|
666 |
if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
|
667 |
if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
|
667 |
}
|
668 |
}
|
668 |
if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
|
669 |
if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
|
669 |
unset($this->table_retour['href']);
|
670 |
unset($this->table_retour['href']);
|
670 |
return $this->table_retour;
|
671 |
return $this->table_retour;
|
671 |
}
|
672 |
}
|
672 |
|
673 |
|
673 |
public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
|
674 |
public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
|
674 |
if ($champ == 'id' || $champ == 'nom_vernaculaire') {
|
675 |
if ($champ == 'id' || $champ == 'nom_vernaculaire') {
|
675 |
$this->table_retour[$champ] = $valeur;
|
676 |
$this->table_retour[$champ] = $valeur;
|
676 |
} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
|
677 |
} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
|
677 |
switch ($match[1]) {
|
678 |
switch ($match[1]) {
|
678 |
case 'taxon' : if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
|
679 |
case 'taxon' : if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
|
679 |
$this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
680 |
$this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
680 |
case 'langue' : //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
|
681 |
case 'langue' : //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
|
681 |
break;
|
682 |
break;
|
682 |
case 'genre' : $this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
683 |
case 'genre' : $this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
683 |
case 'conseil_emploi' : $this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
684 |
case 'conseil_emploi' : $this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
|
684 |
default : break;
|
685 |
default : break;
|
685 |
}
|
686 |
}
|
686 |
|
687 |
|
687 |
} elseif ($langue != '') {
|
688 |
} elseif ($langue != '') {
|
688 |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
|
689 |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
|
689 |
} else {
|
690 |
} else {
|
690 |
$this->table_retour[$champ] = $valeur;
|
691 |
$this->table_retour[$champ] = $valeur;
|
691 |
}
|
692 |
}
|
692 |
}
|
693 |
}
|
693 |
|
694 |
|
694 |
public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
|
695 |
public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
|
695 |
if (isset(self::$champ_infos[$nomChamp])) {
|
696 |
if (isset(self::$champ_infos[$nomChamp])) {
|
696 |
extract(self::$champ_infos[$nomChamp]);
|
697 |
extract(self::$champ_infos[$nomChamp]);
|
697 |
}
|
698 |
}
|
698 |
|
699 |
|
699 |
if ($this->retour_format == 'max') {
|
700 |
if ($this->retour_format == 'max') {
|
700 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
|
701 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
|
701 |
if ($service == 'taxons') {
|
702 |
if ($service == 'taxons') {
|
702 |
$code_valeur = '';
|
703 |
$code_valeur = '';
|
703 |
$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
|
704 |
$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
|
704 |
} else {
|
705 |
} else {
|
705 |
$code_valeur = $this->chercherSignificationCode($url, $nom);
|
706 |
$code_valeur = $this->chercherSignificationCode($url, $nom);
|
706 |
}
|
707 |
}
|
707 |
if ($projet != '') $projet .= '.';
|
708 |
if ($projet != '') $projet .= '.';
|
708 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
|
709 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
|
709 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
710 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
710 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
|
711 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
|
711 |
} else {
|
712 |
} else {
|
712 |
if ($projet != '') $projet .= '.';
|
713 |
if ($projet != '') $projet .= '.';
|
713 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
714 |
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
714 |
}
|
715 |
}
|
715 |
}
|
716 |
}
|
716 |
|
717 |
|
717 |
public function chercherSignificationCode($url, $nom) {
|
718 |
public function chercherSignificationCode($url, $nom) {
|
718 |
if (isset($this->signification_code[$url])) {
|
719 |
if (isset($this->signification_code[$url])) {
|
719 |
$valeur = $this->signification_code[$url];
|
720 |
$valeur = $this->signification_code[$url];
|
720 |
} else {
|
721 |
} else {
|
721 |
$res = $this->consulterHref($url);
|
722 |
$res = $this->consulterHref($url);
|
722 |
$valeur = $res->$nom;
|
723 |
$valeur = $res->$nom;
|
723 |
$this->signification_code[$url] = $valeur;
|
724 |
$this->signification_code[$url] = $valeur;
|
724 |
}
|
725 |
}
|
725 |
return $valeur;
|
726 |
return $valeur;
|
726 |
}
|
727 |
}
|
727 |
|
728 |
|
728 |
public function afficherTaxons() {
|
729 |
public function afficherTaxons() {
|
729 |
$resultat = $this->recupererNomTaxons();
|
730 |
$resultat = $this->recupererNomTaxons();
|
730 |
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
|
731 |
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
|
731 |
foreach ($langue as $num_nom=>$taxon) {
|
732 |
foreach ($langue as $num_nom=>$taxon) {
|
732 |
$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
|
733 |
$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
|
733 |
if (isset($resultat[$num_tax])) {
|
734 |
if (isset($resultat[$num_tax])) {
|
734 |
$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
|
735 |
$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
|
735 |
$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
|
736 |
$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
|
736 |
}
|
737 |
}
|
737 |
}
|
738 |
}
|
738 |
}
|
739 |
}
|
739 |
}
|
740 |
}
|
740 |
|
741 |
|
741 |
public function recupererNomTaxons() {
|
742 |
public function recupererNomTaxons() {
|
742 |
$taxons = array_unique($this->taxons);
|
743 |
$taxons = array_unique($this->taxons);
|
743 |
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
|
744 |
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
|
744 |
$res = $this->consulterHref($url);
|
745 |
$res = $this->consulterHref($url);
|
745 |
foreach ($res->resultat as $id=>$taxon) {
|
746 |
foreach ($res->resultat as $id=>$taxon) {
|
746 |
$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
|
747 |
$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
|
747 |
$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
|
748 |
$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
|
748 |
}
|
749 |
}
|
749 |
return $resultat;
|
750 |
return $resultat;
|
750 |
}
|
751 |
}
|
751 |
|
752 |
|
752 |
public function formaterNomsVernaculairesIdChamp($resultat) {
|
753 |
public function formaterNomsVernaculairesIdChamp($resultat) {
|
753 |
$this->table_retour['id'] = $this->ressources[0];
|
754 |
$this->table_retour['id'] = $this->ressources[0];
|
754 |
$champs = explode(' ', $this->ressources[1]);
|
755 |
$champs = explode(' ', $this->ressources[1]);
|
755 |
if (in_array('attributions', $champs) != false) {
|
756 |
if (in_array('attributions', $champs) != false) {
|
756 |
$this->formaterNomsVernaculairesId($resultat);
|
757 |
$this->formaterNomsVernaculairesId($resultat);
|
757 |
unset($this->table_retour['nom_vernaculaire']);
|
758 |
unset($this->table_retour['nom_vernaculaire']);
|
758 |
} else {
|
759 |
} else {
|
759 |
$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
|
760 |
$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
|
760 |
foreach ($resultat as $taxon) {
|
761 |
foreach ($resultat as $taxon) {
|
761 |
foreach ($taxon as $key=>$valeur) {
|
762 |
foreach ($taxon as $key=>$valeur) {
|
762 |
if ($key == 'code_langue' && in_array('langue', $champs) != false) {
|
763 |
if ($key == 'code_langue' && in_array('langue', $champs) != false) {
|
763 |
$this->table_retour['attributions']['langue'][] = $valeur;
|
764 |
$this->table_retour['attributions']['langue'][] = $valeur;
|
764 |
} elseif (in_array($key, $champ_attributions) != false) {
|
765 |
} elseif (in_array($key, $champ_attributions) != false) {
|
765 |
$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
|
766 |
$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
|
766 |
} elseif (in_array($key, $champs) != false) {
|
767 |
} elseif (in_array($key, $champs) != false) {
|
767 |
$this->table_retour[$key] = $valeur;
|
768 |
$this->table_retour[$key] = $valeur;
|
768 |
}
|
769 |
}
|
769 |
}
|
770 |
}
|
770 |
if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
|
771 |
if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
|
771 |
}
|
772 |
}
|
772 |
if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
|
773 |
if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
|
773 |
}
|
774 |
}
|
774 |
return $this->table_retour;
|
775 |
return $this->table_retour;
|
775 |
}
|
776 |
}
|
776 |
|
777 |
|
777 |
public function afficherPoint($champ, $valeur, $langue, $num_nom) {
|
778 |
public function afficherPoint($champ, $valeur, $langue, $num_nom) {
|
778 |
preg_match('/^(.*)\.code$/', $champ, $match);
|
779 |
preg_match('/^(.*)\.code$/', $champ, $match);
|
779 |
$champ = $match[1];
|
780 |
$champ = $match[1];
|
780 |
if (isset(self::$champ_infos[$champ])) {
|
781 |
if (isset(self::$champ_infos[$champ])) {
|
781 |
extract(self::$champ_infos[$champ]);
|
782 |
extract(self::$champ_infos[$champ]);
|
782 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
|
783 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
|
783 |
$projet .= '.';
|
784 |
$projet .= '.';
|
784 |
}
|
785 |
}
|
785 |
|
786 |
|
786 |
$champs = explode(' ', $this->ressources[1]);
|
787 |
$champs = explode(' ', $this->ressources[1]);
|
787 |
if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
|
788 |
if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
|
788 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
|
789 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
|
789 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
|
790 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
|
790 |
}
|
791 |
}
|
791 |
if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
|
792 |
if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
|
792 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
|
793 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
|
793 |
}
|
794 |
}
|
794 |
if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
|
795 |
if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
|
795 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
|
796 |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
|
796 |
}
|
797 |
}
|
797 |
if (in_array($champ, $champs) !== false) {
|
798 |
if (in_array($champ, $champs) !== false) {
|
798 |
if (isset($url)) {
|
799 |
if (isset($url)) {
|
799 |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
|
800 |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
|
800 |
} else {
|
801 |
} else {
|
801 |
$this->table_retour['attributions'][$langue][$champ] = $valeur;
|
802 |
$this->table_retour['attributions'][$langue][$champ] = $valeur;
|
802 |
}
|
803 |
}
|
803 |
}
|
804 |
}
|
804 |
}
|
805 |
}
|
805 |
|
806 |
|
806 |
public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
|
807 |
public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
|
807 |
if ($this->retour_format == 'max') {
|
808 |
if ($this->retour_format == 'max') {
|
808 |
$this->table_retour['attributions'][$nomChamp] = $nom;
|
809 |
$this->table_retour['attributions'][$nomChamp] = $nom;
|
809 |
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
810 |
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
810 |
$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
|
811 |
$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
|
811 |
} else {
|
812 |
} else {
|
812 |
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
813 |
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
|
813 |
}
|
814 |
}
|
814 |
}
|
815 |
}
|
815 |
|
816 |
|
816 |
public function chargerBiblio($num_nom, $langue) {
|
817 |
public function chargerBiblio($num_nom, $langue) {
|
817 |
list($table, $version) = explode('_v',$this->table);
|
818 |
list($table, $version) = explode('_v',$this->table);
|
818 |
$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
|
819 |
$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
|
819 |
"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
|
820 |
"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
|
820 |
$resultat = $this->getBdd()->recupererTous($requete);
|
821 |
$resultat = $this->getBdd()->recupererTous($requete);
|
821 |
|
822 |
|
822 |
if ($resultat == '') { //cas ou la requete comporte des erreurs
|
823 |
if ($resultat == '') { //cas ou la requete comporte des erreurs
|
823 |
$r = 'La requête SQL formée comporte une erreur !!';
|
824 |
$r = 'La requête SQL formée comporte une erreur !!';
|
824 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
|
825 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
|
825 |
Debug::printr($requete);
|
826 |
Debug::printr($requete);
|
826 |
} elseif ($resultat) {
|
827 |
} elseif ($resultat) {
|
827 |
foreach ($resultat as $res) {
|
828 |
foreach ($resultat as $res) {
|
828 |
foreach ($res as $cle => $valeur) {
|
829 |
foreach ($res as $cle => $valeur) {
|
829 |
if ($valeur !== "") {
|
830 |
if ($valeur !== "") {
|
830 |
$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
|
831 |
$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
|
831 |
}
|
832 |
}
|
832 |
}
|
833 |
}
|
833 |
}
|
834 |
}
|
834 |
}
|
835 |
}
|
835 |
}
|
836 |
}
|
836 |
|
837 |
|
837 |
}
|
838 |
}
|
838 |
?>
|
839 |
?>
|