Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 159 → Rev 160

/trunk/services/modules/0.1/nvjfl/NomsVernaculaires.php
133,7 → 133,7
if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
$this->traiterRessourceId(); // ajoute condition id=#valeur
if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
$this->traiterRessourceChampOuRelations(); //modifie requete_champ ou requete_condition
$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
}
}
} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
146,6 → 146,8
if (is_numeric($this->ressources[0])) {
$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
$this->format_reponse .= '/id';
} elseif ($this->ressources[0] == 'attributions') {
$this->format_reponse .= '/attributions';
} else {
$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
' " n\'existe pas.';
154,17 → 156,9
}
 
 
public function traiterRessourceChampOuRelations() {
//requete = /noms-vernaculaires/#id/relations :
if ($this->ressources[1] == 'relations') {
$this->format_reponse .= '/relations';
$this->requete_condition[] = 'num_taxon = (SELECT region FROM '.$this->table.' WHERE '
.implode(' AND ', $this->requete_condition).')';
//requete = /noms-vernaculaires/#id/#champ :
} else {
$this->format_reponse .= '/champ';
$this->analyserChamp();
}
public function traiterRessourceChamp() {
$this->format_reponse .= '/champ';
$this->analyserChamp();
}
 
public function analyserChamp() {
229,7 → 223,8
 
//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
public function recupererTotalResultat() {
$requete = 'SELECT count(distinct(id)) as nombre FROM '
$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
$requete = 'SELECT count('.$distinct.') as nombre FROM '
.$this->table
.$this->formerRequeteCondition();
$res = $this->getBdd()->recuperer($requete);
237,7 → 232,7
if ($res) {
$total = $res['nombre'];
} else {
$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base';
$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
}
return $total;
251,6 → 246,7
switch ($this->format_reponse) {
case 'noms-vernaculaires' :
$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat); break;
case 'noms-vernaculaires/attributions' : $reponse = $this->formaterNomsVernaculairesAttributions($resultat); break;
case 'noms-vernaculaires/id' : $reponse = $this->formaterNomsVernaculairesId($resultat); break;
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
default : break;
260,7 → 256,7
 
public function formaterNomsVernaculaires($resultat) {
//on remplit la table $table_retour_json['entete']
$table_retour_json['entete']['masque'] = implode('&', $this->parametres);
$table_retour_json['entete']['masque'] = $this->recupererMasque();
$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
$table_retour_json['entete']['total'] = $this->total_resultat;
267,7 → 263,7
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
if (isset($url['suivant']) && $url['suivant'] != '') { $table_retour_json['entete']['href.suivant'] = $url['suivant']; }
 
//on remplit la table $table_retour_json['resultat']
if (isset($this->parametres['masque.nv'])) {
$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
294,6 → 290,17
return $table_retour_json;
}
public function recupererMasque() {
$tab_masque = array();
foreach ($this->parametres as $param=>$valeur) {
if (strstr($param, 'masque') != false) {
$tab_masque[] = $param.'='.$valeur;
}
}
$masque = implode('&', $tab_masque);
return $masque;
}
public function formaterEnOss($resultat) {
$table_nom = array();
$oss = '';
310,7 → 317,58
$table_retour_oss = array($masque, $oss);
return $table_retour_oss;
}
 
public function formaterNomsVernaculairesAttributions($resultat) {
//on remplie la table $table_retour_json['entete']
$table_retour_json['entete']['masque'] = $this->recupererMasque();
$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
$table_retour_json['entete']['total'] = $this->total_resultat;
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
if (isset($url['precedent']) && $url['precedent'] != '') {
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
}
if (isset($url['suivant']) && $url['suivant'] != '') {
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
}
//on remplie la table $table_retour_json['resultat']
if (isset($this->parametres['masque.nv'])) {
$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
}
if (isset($this->parametres['masque'])) {
$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
}
foreach ($resultat as $tab) {
$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
if ($this->retour_format == 'max') {
$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
}
}
if ($this->retour_format == 'max') {
$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
}
$table_retour_json['resultat'] = $resultat_json;
return $table_retour_json;
}
public function afficherTaxonsAttributions($resultat) {
$nom_sci = $this->recupererNomTaxons();
foreach ($resultat as $num=>$tab) {
if (isset($nom_sci[$tab['taxon']])) {
$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']];
}
}
return $resultat;
}
// formatage de la reponse /id ss la forme
// id, nom_vernaculaire, attributions
// langue
395,11 → 453,7
}
 
public function afficherTaxons() {
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.$this->getBdd()->proteger(implode(',', $this->taxons));
$res = $this->consulterHref($url);
foreach ($res->resultat as $id=>$taxon) {
$resultat[$id] = $taxon->nom_sci;
}
$resultat = $this->recupererNomTaxons();
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
foreach ($langue as $num_nom=>$taxon) {
$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
409,6 → 463,16
}
}
}
public function recupererNomTaxons() {
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.
$this->getBdd()->proteger(implode(',', $this->taxons));
$res = $this->consulterHref($url);
foreach ($res->resultat as $id=>$taxon) {
$resultat[$taxon->num_taxonomique] = $taxon->nom_sci;
}
return $resultat;
}
 
public function formaterNomsVernaculairesIdChamp($resultat) {
$this->table_retour['id'] = $this->ressources[0];
416,7 → 480,7
if (in_array('attributions', $champs) != false) {
$this->formaterNomsVernaculairesId($resultat);
unset($this->table_retour['nom_vernaculaire']);
} else {//print_r($resultat);
} else {
$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
foreach ($resultat as $taxon) {
foreach ($taxon as $key=>$valeur) {