| Line 174... |
Line 174... |
| 174 |
if ($this->ressources[1] == 'relations') {
|
174 |
if ($this->ressources[1] == 'relations') {
|
| 175 |
$this->traiterRessourceIdRelations();
|
175 |
$this->traiterRessourceIdRelations();
|
| 176 |
} else {
|
176 |
} else {
|
| 177 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
177 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
| 178 |
<li> noms/#id/relations </li> <li> noms/#id/#champ+#champ </li>
|
178 |
<li> noms/#id/relations </li> <li> noms/#id/#champ+#champ </li>
|
| 179 |
<li> noms/#id/relations/synonymie </li> <li> noms/#id/relations/flores </li>
|
179 |
<li> noms/#id/relations/synonymie </li>
|
| 180 |
<li> noms/#id/relations/homonymie </li>';
|
180 |
<li> noms/#id/relations/homonymie </li>';
|
| 181 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
181 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
| 182 |
}
|
182 |
}
|
| 183 |
} else { // requete de type noms/#id : rajout du nom_sci pour récupérer le format html par la fct mettreAuFormat()
|
183 |
} else { // requete de type noms/#id : rajout du nom_sci pour récupérer le format html par la fct mettreAuFormat()
|
| 184 |
$this->requete_champ = ' *, nom_sci ';
|
184 |
$this->requete_champ = ' *, nom_sci ';
|
| Line 194... |
Line 194... |
| 194 |
$num_nom = $nn;
|
194 |
$num_nom = $nn;
|
| 195 |
}
|
195 |
}
|
| 196 |
$champ = "flore_$projet"."_num";
|
196 |
$champ = "flore_$projet"."_num";
|
| 197 |
if (isset($this->ressources[3])) {
|
197 |
if (isset($this->ressources[3])) {
|
| 198 |
$type = $this->ressources[3];
|
198 |
$type = $this->ressources[3];
|
| 199 |
if (!in_array($type, array('homonymie', 'synonymie', 'flores'))) {
|
199 |
if (!in_array($type, array('homonymie', 'synonymie'))) {
|
| 200 |
$e = "Les types disponibles pour les noms sont homonymie, synonymie et flores";
|
200 |
$e = "Les types disponibles pour les noms sont homonymie, synonymie";
|
| 201 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
201 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
| 202 |
}
|
202 |
}
|
| 203 |
}
|
203 |
}
|
| 204 |
$this->requete_champ = ' num_nom ';
|
204 |
$this->requete_champ = ' num_nom ';
|
| 205 |
$this->requete_condition = array();
|
205 |
$this->requete_condition = array();
|
| Line 212... |
Line 212... |
| 212 |
// requete de type noms/#id/relations/#relation
|
212 |
// requete de type noms/#id/relations/#relation
|
| 213 |
switch ($this->ressources[2]) {
|
213 |
switch ($this->ressources[2]) {
|
| 214 |
case 'synonymie' :
|
214 |
case 'synonymie' :
|
| 215 |
$this->traiterRessourceIdSynonymie();
|
215 |
$this->traiterRessourceIdSynonymie();
|
| 216 |
break;
|
216 |
break;
|
| 217 |
case 'flores' :
|
- |
|
| 218 |
$this->traiterRessourceIdFlores();
|
- |
|
| 219 |
break;
|
- |
|
| 220 |
case 'homonymie' :
|
217 |
case 'homonymie' :
|
| 221 |
$this->traiterRessourceIdHomonymie();
|
218 |
$this->traiterRessourceIdHomonymie();
|
| 222 |
break;
|
219 |
break;
|
| 223 |
default :
|
220 |
default :
|
| 224 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
221 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
| 225 |
<li> noms/#id/relations </li> <li> noms/#id/relations/synonymie </li>
|
222 |
<li> noms/#id/relations </li> <li> noms/#id/relations/synonymie </li>
|
| 226 |
<li> noms/#id/relations/flores </li> <li> noms/#id/relations/homonymie </li>';
|
223 |
<li> noms/#id/relations/homonymie </li>';
|
| 227 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
224 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
| 228 |
break;
|
225 |
break;
|
| 229 |
}
|
226 |
}
|
| 230 |
}
|
227 |
}
|
| 231 |
}
|
228 |
}
|
| Line 245... |
Line 242... |
| 245 |
$this->format_reponse .= '/homonymie';
|
242 |
$this->format_reponse .= '/homonymie';
|
| 246 |
$this->requete_condition[0] = 'nom_sci = (SELECT nom_sci FROM '.$this->table
|
243 |
$this->requete_condition[0] = 'nom_sci = (SELECT nom_sci FROM '.$this->table
|
| 247 |
.' WHERE '.$this->requete_condition[0].')';
|
244 |
.' WHERE '.$this->requete_condition[0].')';
|
| 248 |
}
|
245 |
}
|
| Line 249... |
Line -... |
| 249 |
|
- |
|
| 250 |
public function traiterRessourceIdFlores() {
|
- |
|
| 251 |
$champ_flores = '';
|
- |
|
| 252 |
foreach ($this->champs_table as $champ) {
|
- |
|
| 253 |
if (preg_match('/^flore_.*$/', $champ)) {
|
- |
|
| 254 |
$champ_flores .= ', '.$champ;
|
- |
|
| 255 |
}
|
- |
|
| 256 |
}
|
- |
|
| 257 |
$this->format_reponse .= '/flores';
|
- |
|
| 258 |
$this->requete_champ = 'num_nom'.$champ_flores;
|
- |
|
| 259 |
}
|
- |
|
| 260 |
|
246 |
|
| 261 |
public function traiterRessourceStatsRangs() {
|
247 |
public function traiterRessourceStatsRangs() {
|
| 262 |
// SELECT count(*) as nombre, rang FROM bdtfx_v2_00 [WHERE rang = 290] GROUP BY rang ORDER BY rang;
|
248 |
// SELECT count(*) as nombre, rang FROM bdtfx_v2_00 [WHERE rang = 290] GROUP BY rang ORDER BY rang;
|
| 263 |
$this->format_reponse .= '/rangs';
|
249 |
$this->format_reponse .= '/rangs';
|
| 264 |
$this->requete_champ = 'count(*) as nombre, rang ';
|
250 |
$this->requete_champ = 'count(*) as nombre, rang ';
|
| Line 401... |
Line 387... |
| 401 |
$reponse = $this->formaterIdSynonymie($resultat);
|
387 |
$reponse = $this->formaterIdSynonymie($resultat);
|
| 402 |
break;
|
388 |
break;
|
| 403 |
case 'noms/id/relations/homonymie' :
|
389 |
case 'noms/id/relations/homonymie' :
|
| 404 |
$reponse = $this->formaterIdHomonymie($resultat);
|
390 |
$reponse = $this->formaterIdHomonymie($resultat);
|
| 405 |
break;
|
391 |
break;
|
| 406 |
case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
|
- |
|
| 407 |
$reponse = $this->formaterIdFlores($resultat[0]);
|
- |
|
| 408 |
break;
|
- |
|
| 409 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
392 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
| 410 |
$reponse = $this->formaterStatsAnnee($resultat);
|
393 |
$reponse = $this->formaterStatsAnnee($resultat);
|
| 411 |
break;
|
394 |
break;
|
| 412 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
395 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
| 413 |
$reponse = $this->formaterStatsRang($resultat);
|
396 |
$reponse = $this->formaterStatsRang($resultat);
|
| Line 440... |
Line 423... |
| 440 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
423 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
| 441 |
$this->resultat_req = $resultat;
|
424 |
$this->resultat_req = $resultat;
|
| 442 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
425 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
| Line 443... |
Line 426... |
| 443 |
|
426 |
|
| 444 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
- |
|
| 445 |
$flores = $this->ajouterRelations('flores');
|
- |
|
| 446 |
if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
|
427 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
| 447 |
$homonymes = $this->ajouterRelations('homonymie');
|
428 |
$homonymes = $this->ajouterRelations('homonymie');
|
| 448 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
429 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
| 449 |
$synonymes = $this->ajouterRelations('synonymie');
|
430 |
$synonymes = $this->ajouterRelations('synonymie');
|
| Line 460... |
Line 441... |
| 460 |
return $retour_id_rel;
|
441 |
return $retour_id_rel;
|
| 461 |
}
|
442 |
}
|
| Line 462... |
Line 443... |
| 462 |
|
443 |
|
| 463 |
/**
|
444 |
/**
|
| 464 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
445 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
| 465 |
* flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
446 |
* ) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
| 466 |
*/
|
447 |
*/
|
| 467 |
public function ajouterRelations($relation) {
|
448 |
public function ajouterRelations($relation) {
|
| 468 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
449 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
| 469 |
$res = null;
|
450 |
$res = null;
|
| Line 551... |
Line 532... |
| 551 |
')';
|
532 |
')';
|
| Line 552... |
Line 533... |
| 552 |
|
533 |
|
| 553 |
return $this->getBdd()->recupererTous($requete);
|
534 |
return $this->getBdd()->recupererTous($requete);
|
| Line 554... |
Line -... |
| 554 |
}
|
- |
|
| 555 |
|
- |
|
| 556 |
public function formaterIdFlores($resultat) {
|
- |
|
| 557 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
|
- |
|
| 558 |
$this->resultat_req = $resultat;
|
- |
|
| 559 |
$id = array_shift($resultat);
|
- |
|
| 560 |
$reponse['entete']['id'] = $id;
|
- |
|
| 561 |
$synonymes_flores = $this->obtenirSynonymesParNumNomAvecInfosFlore($this->ressources[0]);
|
- |
|
| 562 |
if(is_array($synonymes_flores)) {
|
- |
|
| 563 |
foreach ($synonymes_flores as $synonyme) {
|
- |
|
| 564 |
$nom_sci = $synonyme['nom_sci'];
|
- |
|
| 565 |
$num_nom = $synonyme['num_nom'];
|
- |
|
| 566 |
unset($synonyme['nom_sci']);
|
- |
|
| 567 |
unset($synonyme['num_nom']);
|
- |
|
| 568 |
foreach ($synonyme as $flores => $valeur) {
|
- |
|
| 569 |
if ($valeur != '' && $valeur != '0') {
|
- |
|
| 570 |
$this->afficherInfosFlore($synonyme, $flores, $valeur, $nom_sci, $num_nom);
|
- |
|
| 571 |
}
|
- |
|
| 572 |
}
|
- |
|
| 573 |
}
|
- |
|
| 574 |
}
|
- |
|
| 575 |
|
- |
|
| 576 |
if ($this->table_retour != array()) {
|
- |
|
| 577 |
$reponse['resultat'] = $this->table_retour;
|
- |
|
| 578 |
$this->table_retour = array();
|
- |
|
| 579 |
} else {
|
- |
|
| 580 |
$reponse = null;
|
- |
|
| 581 |
}
|
- |
|
| 582 |
return $reponse;
|
- |
|
| 583 |
}
|
- |
|
| 584 |
|
- |
|
| 585 |
public function getNomCompletFlore($flore) {
|
- |
|
| 586 |
return Config::get($flore.'_texte');
|
- |
|
| 587 |
}
|
- |
|
| 588 |
|
- |
|
| 589 |
public function afficherInfosFlore(&$resultat, $flores, $valeur, $nom_sci, $num_nom) {
|
- |
|
| 590 |
$flore = substr($flores,0,strrpos($flores, '_'));
|
- |
|
| 591 |
$projet = $this->noms_projets[$flore];
|
- |
|
| 592 |
|
- |
|
| 593 |
//TODO voir si l'on peut factoriser les affectations à la table retour
|
- |
|
| 594 |
// et simplifier ce gros pavé
|
- |
|
| 595 |
if (strrpos($flores, 'num') !== false) {
|
- |
|
| 596 |
if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
|
- |
|
| 597 |
$this->table_retour[$num_nom][$flore]['id'] = $match[1];
|
- |
|
| 598 |
if ($projet == 'coste') {
|
- |
|
| 599 |
$this->table_retour[$num_nom][$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
|
- |
|
| 600 |
}
|
- |
|
| 601 |
if (isset($match[2]) && $match[2] != '') $this->table_retour[$num_nom][$flore]['cle'] = $match[2];
|
- |
|
| 602 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
- |
|
| 603 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
- |
|
| 604 |
}
|
- |
|
| 605 |
if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
|
- |
|
| 606 |
$this->table_retour[$num_nom][$flore]['remarque'] = $resultat[$flore.'_rem'];
|
- |
|
| 607 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
- |
|
| 608 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
- |
|
| 609 |
unset($resultat[$flore.'_rem']);
|
- |
|
| 610 |
}
|
- |
|
| 611 |
} elseif (strrpos($flores,'belge') !== false) {
|
- |
|
| 612 |
if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
|
- |
|
| 613 |
if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
|
- |
|
| 614 |
$this->table_retour[$num_nom][$flore]['page'] = $match[1];
|
- |
|
| 615 |
$this->table_retour[$num_nom][$flore]['type'] = $type;
|
- |
|
| 616 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
- |
|
| 617 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
- |
|
| 618 |
}
|
- |
|
| 619 |
}
|
- |
|
| 620 |
}
|
535 |
}
|
| Line 621... |
Line 536... |
| 621 |
|
536 |
|
| 622 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
537 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
| 623 |
|
538 |
|