New file |
0,0 → 1,341 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package jrest |
* @author David Delon <david@tela-botania.org> |
* @author Aurélien Peronnet <aurelien@tela-botania.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/jrest/ |
*/ |
|
/** |
* |
* La classe appelle les web service d'eflore pour éviter que le code client |
* ne soit dépendant de la version d'eflore |
*/ |
class RechercheInfosTaxonBeta extends Cel { |
|
public function RechercheInfosTaxonBeta($config) { |
parent::__construct($config); |
} |
|
public function rechercherGenreEspeceSurPrefixe($genre = null, $espece = null) { |
|
$liste_genre_espece = array(); |
$masque = urlencode(trim(trim($genre).' '.trim($espece,' *'))); |
$requete = @file_get_contents('http://localhost/service:eflore:0.1/bdtfx/noms?masque='.$masque.'&recherche=etendue&retour.format=min&navigation.limite=50&ns.structure=au'); |
|
if($requete != '') { |
$requete = json_decode($requete); |
if(is_object($requete) && isset($requete->resultat)) { |
foreach ($requete->resultat as $id => $res) { |
$retenu = $res->retenu == true ? '3' : ''; |
$liste_genre_espece[] = array($res->nom_sci_complet, $id, $retenu); |
} |
} |
usort($liste_genre_espece, array($this, 'comparerParNom')); |
} |
return $liste_genre_espece; |
} |
|
function comparerParNom($a, $b) { |
return strnatcmp($a[0], $b[0]); |
} |
|
public function effectuerRequeteInfosComplementairesEtFormaterNom($numNom) { |
|
$resultat_infos_complementaires = (array)$this->effectuerRequeteInfosComplementairesSurNumNom($numNom); |
$retour_infos_complementaires = array(); |
if (isset($resultat_infos_complementaires['nom_retenu_complet']) && $resultat_infos_complementaires['nom_retenu_complet'] != '') { |
$retour_infos_complementaires=array(($this->supprimerBiblio($resultat_infos_complementaires['nom_retenu_complet']))); |
} |
|
return $retour_infos_complementaires; |
} |
|
public function rechercherInformationsComplementairesSurNom($nom_saisi) { |
|
$nameparser = new NameParser(); |
$nom_decoupe = $nameparser->parse($nom_saisi); |
|
$masque = ((isset($nom_decoupe['genus']) && $nom_decoupe['genus']!= '') && |
(isset($nom_decoupe['species']) && $nom_decoupe['species']!= '')) |
? $nom_decoupe['genus'].' '.$nom_decoupe['species'] : $nom_saisi; |
|
$liste_genre_espece = array(); |
$url = 'http://www.tela-botanica.org/service:eflore:0.1/bdtfx/noms?masque='.urlencode($nom_decoupe['genus'].' '.$nom_decoupe['species']).'&recherche=etendue&ns.format=txt&retour.champs=nom_retenu,nom_retenu.*,num_taxonomique,auteur&navigation.limite=3000'; |
$resultat = @file_get_contents($url); |
if($resultat != '') { |
$resultat = json_decode($resultat); |
if(is_object($resultat) && isset($resultat->resultat)) { |
foreach ($resultat->resultat as $id => $res) { |
$nom_complet = $res->{'nom_sci'}.' '.$res->auteur; |
$liste_genre_espece[] = array($res->{'nom_retenu.id'},$nom_complet); |
} |
} |
} |
return $liste_genre_espece; |
} |
|
public function rechercherInformationsComplementairesSurNumNom($num_nom) { |
$infos_formatees = array(); |
$infos = $this->effectuerRequeteInfosComplementairesSurNumNom($num_nom); |
if(is_object($infos)) { |
$infos_formatees = $this->formaterInfosComplementairesSurNumNom($infos); |
} |
return $infos_formatees; |
} |
|
public function effectuerRequeteInfosComplementairesSurNumNom($num_nom) { |
$infos = array(); |
//TODO: retourner moins de champs grâce au paramètre retour.champs |
$url = "http://www.tela-botanica.org/service:eflore:0.1/bdtfx/noms/".$num_nom; |
$resultat = @file_get_contents($url); |
if($resultat != '') { |
$infos = json_decode($resultat); |
} |
return $infos; |
} |
|
private function formaterInfosComplementairesSurNumNom($infos) { |
$infos = (array)$infos; |
return $infos_formatees = array( |
'Nom_Retenu' => $this->supprimerBiblio($infos['nom_retenu_complet']), |
'Num_Nom_Retenu' => $infos['nom_retenu.id'], |
'Num_Taxon' => $infos['num_taxonomique'], |
'Famille' => $infos['famille'] |
); |
} |
|
private function supprimerBiblio($nom) { |
return preg_replace('/ \[.*\]/','',$nom); |
} |
|
public function rechercherNumTaxSurNumNom($num_nom) { |
|
$nt = null; |
$url = "http://www.tela-botanica.org/service:eflore:0.1/bdtfx/noms/".$num_nom.'?retour.champs=num_taxonomique'; |
$resultat = @file_get_contents($url); |
if($resultat != '') { |
$infos = json_decode($resultat); |
$nt = $infos->num_taxonomique; |
} |
|
return $nt; |
} |
|
public function taxonEstPresentDansDepartement($num_taxon,$code_departement) { |
$presence_taxon = false; |
$url = 'http://localhost/service:eflore:0.1/chorodep/observations/?masque.departement='.$code_departement.'&masque.determination.nt='.$num_taxon.'&navigation.limite=1'; |
$resultat = @file_get_contents($url); |
if($resultat != '') { |
$resultat = json_decode($resultat); |
if(is_object($resultat) && isset($resultat->resultat) && count($resultat->resultat) > 0) { |
$presence_taxon = true; |
} |
} |
return $presence_taxon; |
} |
|
public function effectuerRequeteInfosComplementairesSurNumTax($numTax) { |
|
$requete_infos_complementaires = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,". |
" auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ". |
" , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ". |
" , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ". |
" , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ". |
" , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" . |
" FROM eflore_nom, eflore_nom_rang," . |
" eflore_naturaliste_intitule_abreviation AS auteur_bex ". |
" , eflore_naturaliste_intitule_abreviation AS auteur_b ". |
" , eflore_naturaliste_intitule_abreviation AS auteur_mex ". |
" , eflore_naturaliste_intitule_abreviation AS auteur_m ". |
" , eflore_selection_nom ". |
" WHERE esn_id_taxon = '".$numTax. "'". |
" AND esn_id_version_projet_taxon = 25 ". |
" AND esn_ce_statut=3 ". |
" AND en_id_nom = esn_id_nom" . |
" AND en_ce_rang = enrg_id_rang" . |
" AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ". |
" AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege ". |
" AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ". |
" AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ". |
" AND esn_id_version_projet_taxon=en_id_version_projet_nom "; |
|
$resultat_infos_complementaires = $this->executerRequete($requete_infos_complementaires); |
|
return $resultat_infos_complementaires; |
} |
|
public function rechercherFamille($taxon) { |
|
$row = array(); |
|
$requete_famille = "SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ". |
" FROM eflore_taxon_relation, ". |
" eflore_selection_nom, ". |
" eflore_nom ". |
" WHERE etr_id_taxon_1 = ".$taxon. |
" AND etr_id_version_projet_taxon_1 = 25 ". |
" AND etr_id_categorie_taxon = 3 ". |
" AND etr_id_valeur_taxon = 3 ". |
" AND esn_id_taxon = etr_id_taxon_2 ". |
" AND esn_ce_statut = 3 ". |
" AND esn_id_version_projet_taxon = etr_id_version_projet_taxon_1 ". |
" AND en_id_nom = esn_id_nom ". |
" AND esn_id_version_projet_taxon=en_id_version_projet_nom "; |
|
$resultat_recherche_famille = $this->executerRequete($requete_famille); |
|
if (!is_array($resultat_recherche_famille) || count($resultat_recherche_famille) == 0) { |
$resultat_recherche_famille = array('en_ce_rang' => 'fin'); |
} else { |
$resultat_recherche_famille = $resultat_recherche_famille[0]; |
} |
|
return $resultat_recherche_famille; |
} |
|
private function decouperNomEtRechercheEspeceOuSousEspece($identifiant_espece) { |
$nameparser=new NameParser(); |
$nom_latin_decoupe=$nameparser->parse($identifiant_espece); |
// requete sous espece (on privilegie les noms retenu cf tri par esn_ce_statut) |
if (isset($nom_latin_decoupe['infra']) && $nom_latin_decoupe['infra']!="") { |
$requete="SELECT DISTINCT en_id_nom, esn_ce_statut" . |
" FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " . |
" WHERE en_id_version_projet_nom = '25' AND en_nom_genre = ".$this->proteger($nom_latin_decoupe['genus'])." " . |
" AND enrg_abreviation_rang = ".$this->proteger($nom_latin_decoupe['infra_type'])." " . |
" AND en_epithete_infra_specifique = ".$this->proteger($nom_latin_decoupe['infra'])." " . |
" AND esn_id_nom= en_id_nom ". |
" AND esn_id_version_projet_taxon=en_id_version_projet_nom " . |
" AND en_epithete_espece = ".$this->proteger($nom_latin_decoupe['species'])." AND en_ce_rang = enrg_id_rang " . |
" ORDER BY esn_ce_statut ". |
" LIMIT 1"; |
} |
else { // espece (on privilegie les noms retenu cf tri par esn_ce_statut) |
$requete="SELECT DISTINCT en_id_nom, esn_ce_statut" . |
" FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " . |
" WHERE en_id_version_projet_nom = '25' AND en_nom_genre = ".$this->proteger($nom_latin_decoupe['genus'])." " . |
" AND enrg_abreviation_rang = 'sp.' " . |
" AND esn_id_nom= en_id_nom ". |
" AND esn_id_version_projet_taxon=en_id_version_projet_nom " . |
" AND en_epithete_espece = ".$this->proteger($nom_latin_decoupe['species'])." AND en_ce_rang = enrg_id_rang " . |
" ORDER BY esn_ce_statut ". |
" LIMIT 1"; |
|
} |
|
$resultat = $this->executerRequete($requete); |
|
$retour = array(); |
if (is_array($resultat) && count($resultat) > 0) { |
$retour = $resultat[0]; |
} |
|
return $retour; |
} |
|
private function formaterNom($rawnom) { |
|
// Constitution du nom: |
$nom = ''; |
|
if (isset($rawnom['en_nom_supra_generique']) && $rawnom['en_nom_supra_generique'] != '') { |
$nom .= $rawnom['en_nom_supra_generique']; |
} else if (isset($rawnom['en_epithete_infra_generique']) && $rawnom['en_epithete_infra_generique'] != '') { |
$nom .= $rawnom['en_epithete_infra_generique']; |
} else { |
if (isset($rawnom['en_nom_genre']) && $rawnom['en_nom_genre'] != '') { |
$nom .= $rawnom['en_nom_genre']; |
} |
if (isset($rawnom['en_epithete_espece']) && $rawnom['en_epithete_espece']!= '') { |
$nom .= ' '.$rawnom['en_epithete_espece']; |
} |
if (isset($rawnom['en_epithete_infra_specifique']) && $rawnom['en_epithete_infra_specifique'] != '') { |
if (!empty($rawnom['enrg_abreviation_rang'])) { |
$nom .= ' '.$rawnom['enrg_abreviation_rang'].''; |
} |
$nom .= ' '.$rawnom['en_epithete_infra_specifique']; |
} |
} |
|
return $nom.$this->retournerAuteur($rawnom) ; |
} |
|
private function retournerAuteur($rawnom) { |
$auteurs = ''; |
$auteur_basio = ''; |
$auteur_modif = ''; |
if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' ) { |
$auteur_basio .= $rawnom['abreviation_auteur_basio_ex']; |
if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') { |
$auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio']; |
} |
} else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') { |
$auteur_basio .= $rawnom['abreviation_auteur_basio']; |
} |
|
if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') { |
$auteur_modif .= $rawnom['abreviation_auteur_modif_ex']; |
if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') { |
$auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif']; |
} |
} else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') { |
$auteur_modif .= $rawnom['abreviation_auteur_modif']; |
} |
|
if (!empty($auteur_modif)) { |
$auteurs = ' ('.$auteur_basio.') '.$auteur_modif; |
} elseif (!empty($auteur_basio)) { |
$auteurs = ' '.$auteur_basio; |
} |
|
return $auteurs ; |
} |
|
function rechercherInfosSurTexteCodeOuNumTax($identifiant_espece) { |
// texte libre, nom scientifique, |
// ou code nomenclatural (format BDNFFnn999999) |
// ou code taxonomique (format BDNFFnt999999) |
$identifiant_espece=trim($identifiant_espece); |
$identifiant_espece=utf8_encode($identifiant_espece); |
|
$retour = array(); |
|
preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece, $elements); |
if (isset($elements[1])) { |
// Numero nomenclatural |
$infos_taxon = $this->rechercherInformationsComplementairesSurNumNom($elements[1]); |
$retour = array("nom_sel" => $this->formaterNom($infos_taxon), "en_id_nom" => $elements[1]); |
} else { |
// Numero taxonomique ou nom scientifique |
preg_match('/BDNFFnt([0-9][0-9]*)/', $identifiant_espece, $elements); |
|
if (isset($elements[1])) { |
// Numero taxonomique |
$infos_taxon = $this->effectuerRequeteInfosComplementairesSurNumTax($elements[1]); |
$infos_taxon = $infos_taxon[0]; |
$retour = array("nom_sel" => $this->formaterNom($infos_taxon), "en_id_nom" => $infos_taxon['en_id_nom']); |
} else { |
// Nom scientifique |
$id_nom = $this->decouperNomEtRechercheEspeceOuSousEspece($identifiant_espece); |
// Recherche du nom associe |
$retour = array("nom_sel" => $identifiant_espece); |
if(is_array($id_nom) && isset($id_nom['en_id_nom'])) { |
$infos_nom = $this->effectuerRequeteInfosComplementairesSurNumNom($id_nom['en_id_nom']); |
if (is_array($infos_nom) && !empty($infos_nom)) { |
$infos_nom = $infos_nom[0]; |
$retour = array("nom_sel" => $this->formaterNom($infos_nom), "en_id_nom" => $id_nom['en_id_nom']); |
} |
} |
} |
} |
|
return $retour; |
} |
} |
?> |