8,6 → 8,9 |
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut). |
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1¶m2=val2&... |
* |
* ATTENTION : /attributions groupe par taxon, le nombre de résultats est donc |
* inférieur ou égal au nombre demandé par navigation.limite |
* |
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche, |
* distinct, retour.format, navigation.depart et navigation.limite. |
* |
51,7 → 54,7 |
|
/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie |
* selon ressources et paramètres */ |
protected $requete_champ = array(' * '); |
protected $requete_champ = array('*'); |
protected $requete_condition = ''; |
protected $limite_requete = array( |
'depart' => 0, |
210,24 → 213,29 |
$this->analyserChamp(); |
} |
|
public function analyserChamp() { |
$this->requete_champ = array(); |
$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des | |
$champs = explode(' ', $this->ressources[1]); |
foreach ($champs as $champ) { |
preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match); |
if (isset($this->champs_possibles[$match[1]])) { |
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]); |
} elseif (isset($this->champs_possibles[$match[0]])) { |
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]); |
} else { |
$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles)); |
$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '. |
public function analyserChamp() { |
$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des | |
$champs = explode(' ', $this->ressources[1]); |
//$this->requete_champ = array(); // * car absence de mappings |
foreach ($champs as $champ) { |
preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match); |
if (isset($this->champs_possibles[$match[1]])) { |
// wtf? |
//$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]); |
// marche pas, pour chaque champ il faut en retourner un qui a un |
// autre nom etc. , pas le temps de faire des mappings |
$this->requete_champ[] = $match[1]; |
} elseif (isset($this->champs_possibles[$match[0]])) { |
// wtf ? |
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]); |
} else { |
$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles)); |
$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '. |
'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").'; |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c); |
} |
} |
} |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c); |
} |
} |
} |
|
// fait du neuf avec du vieux |
public function assemblerLaRequete() { |
252,7 → 260,6 |
$count, |
$this->limite_requete['limite'] |
); |
|
$req = sprintf( |
'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' . |
' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d', |
263,7 → 270,6 |
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '', |
$limiteClause, |
__FILE__, __LINE__); |
//echo "REQ: $req\n"; |
return $req; |
} |
|
281,7 → 287,6 |
$count, |
$this->limite_requete['limite']); |
} |
|
$req = sprintf( |
'SELECT %s, IF(num_statut="",1,0) AS is_null' . |
' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d', |
292,7 → 297,6 |
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '', |
$nolimit ? '' : $limiteClause, |
__FILE__, __LINE__); |
//echo "REQ 2: $req\n"; |
return $req; |
} |
|
349,7 → 353,6 |
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break; |
default : break; |
} |
//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n"; |
return $reponse; |
} |
|
373,7 → 376,6 |
* évite d'écraser des clefs etc.) |
*/ |
public function ajouterJsonResultatNV($resultat) { |
//echo "CPT RES: " . count($resultat) . "\n\n"; |
$resultat_json = array(); |
foreach ($resultat as $tab) { |
$this->table_retour = array(); |
454,6 → 456,7 |
if (!empty($url['suivant'])) { |
$table_retour_json['entete']['href.suivant'] = $url['suivant']; |
} |
$resultat_json = array(); |
foreach ($resultat as &$tab) { |
$nnv = $tab['num_nom_vernaculaire']; |
$resultat_json[$nnv]['id'] = $tab['id']; |
466,8 → 469,7 |
//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab); |
// simple initialisation par copie de la référence de l'original |
$resultat_json[$nnv] = &$tab; |
} |
else { |
} else { |
$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon']; |
$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon']; |
$resultat_json[$nnv]['taxon'] = $tab['num_taxon']; |
484,7 → 486,7 |
} |
|
if ($this->retour_format == 'max') { |
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une |
// Deuxième boucle pour demander tous lestaxons présents en une |
// fois et les attribuer aux noms car c'est beaucoup plus rapide |
$noms_sci = $this->recupererNomTaxons(); |
foreach ($resultat_json as $num_nom => &$tab) { |
797,6 → 799,10 |
return $valeur; |
} |
|
/** |
* Apparemment, regroupe les noms vernaculaires par taxons (élimine donc |
* certains noms) - j'ai bon ? |
*/ |
public function afficherTaxons() { |
$resultat = $this->recupererNomTaxons(); |
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) { |
812,9 → 818,10 |
|
public function recupererNomTaxons() { |
$taxons = array_unique($this->taxons); |
// @TODO attention à la limite de taille de l'URL - faire un POST plutôt |
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons); |
$res = $this->consulterHref($url); |
foreach ($res->resultat as $id=>$taxon) { |
foreach ($res->resultat as $id => $taxon) { |
$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id; |
$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet; |
} |
846,32 → 853,37 |
return $this->table_retour; |
} |
|
/** |
* Quelqu'un sait-il ce que fait cette foutue fonction ? :-/ |
*/ |
public function afficherPoint($champ, $valeur, $langue, $num_nom) { |
preg_match('/^(.*)\.code$/', $champ, $match); |
$champ = $match[1]; |
if (isset(self::$champ_infos[$champ])) { |
extract(self::$champ_infos[$champ]); |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet); |
$projet .= '.'; |
} |
$aMatche = preg_match('/^(.*)\.code$/', $champ, $match); |
if ($aMatche !== false && $aMatche !== 0) { |
$champ = $match[1]; |
if (isset(self::$champ_infos[$champ])) { |
extract(self::$champ_infos[$champ]); |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet); |
$projet .= '.'; |
} |
|
$champs = explode(' ', $this->ressources[1]); |
if (in_array($champ.'.*', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur; |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url; |
} |
if (in_array($champ.'.code', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur; |
} |
if (in_array($champ.'.href', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url; |
} |
if (in_array($champ, $champs) !== false) { |
if (isset($url)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom); |
} else { |
$this->table_retour['attributions'][$langue][$champ] = $valeur; |
$champs = explode(' ', $this->ressources[1]); |
if (in_array($champ.'.*', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur; |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url; |
} |
if (in_array($champ.'.code', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur; |
} |
if (in_array($champ.'.href', $champs) !== false && isset($projet)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url; |
} |
if (in_array($champ, $champs) !== false) { |
if (isset($url)) { |
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom); |
} else { |
$this->table_retour['attributions'][$langue][$champ] = $valeur; |
} |
} |
} |
} |
|