* @author Delphine CAUQUIL * @copyright 2011 Tela-Botanica * @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3 * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 * @version $Id$ */ class Description extends aControleur { private $conteneur = null; private $nomCourant = null; private $textes = null; private $meta = null; private $wikini = null; private $informations = null; static $mois = array ( 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre' ); private $CosteFormate; private $CosteTexte; private $referentiel = 'bdtfx'; private $donnees = array (); public function __construct(Conteneur $conteneur) { $this->conteneur = $conteneur; $this->nomCourant = $this->conteneur->getNomCourant (); $this->referentiel = $this->conteneur->getParametre ( 'referentiel' ); $this->textes = $this->conteneur->getApiTextes (); $this->wikini = $this->conteneur->getApiWikini (); $this->meta = $this->conteneur->getApiMetaDonnees (); $this->informations = $this->conteneur->getApiInformations (); $this->appUrls = $this->conteneur->getAppUrls (); } public function obtenirDonnees() { $donnees = array (); $this->getWikipedia (); $this->getWikini (); $this->getDescriptionsDependantesReferentiel ( $this->referentiel ); if ($this->referentiel == 'bdtfx') { $this->getCoste (); } return $this->donnees; } public function obtenirDonneesExport() { $donnees = array (); $this->getWikini (); $this->getDescriptionsDependantesReferentiel ( $this->referentiel ); return $this->donnees; } private function getDescriptionsDependantesReferentiel($ref) { if (trim ( Config::get ( $ref . '.baseDescription' ) ) != "") { // eg: [bdtfx]baseDescription = coste,baseflor dans bdtfx.ini $bases_descriptions = explode ( ',', Config::get ( $ref . '.baseDescription' ) ); foreach ( $bases_descriptions as $base ) { $fonction = 'get' . ucfirst ( $base ); $this->$fonction (); } } } public function getBloc() { // prend la première description disponible dans l'ordre indiqué dans le fichier // de config, et prend la description wiki sinon if (Config::get ( $this->referentiel . '.baseDescription' ) != "") { $bases_descriptions = explode ( ',', Config::get ( $this->referentiel . '.baseDescription' ) ); foreach ( $bases_descriptions as $base ) { $fonction = 'get' . ucfirst ( $base ); $this->$fonction (); if (empty ( $this->donnees [$base] ['description'] )) { unset ( $this->donnees [$base] ); continue; } $this->donnees ['type'] = $base; $this->donnees ['titre'] = "Description de " . ucfirst ( $base ); $this->donnees ['description'] = $this->donnees [$base] ['description']; unset ( $this->donnees [$base] ); return $this->donnees; } } if (empty ( $this->donnees ['description'] )) { $this->getWikini (); $this->donnees ['description'] = $this->donnees ['wikini'] ['description']; $this->donnees ['titre'] = "Description collaborative"; $this->donnees ['type'] = 'wikini'; unset ( $this->donnees ['wikini'] ); } return $this->donnees; } private function getBaseflor() { $baseflor = array (); $this->informations->setProjet ( 'baseflor' ); $this->informations->setBdnt ( $this->conteneur->getParametre ( 'referentiel' ) ); $this->informations->setNum_nom ( $this->nomCourant->getNnr () ); $informations = $this->informations->getInformationsDescription (); if ($informations) { $baseflor ['chorologie'] = isset ( $informations ['chorologie'] ) ? $informations ['chorologie'] : ''; $baseflor ['inflorescence'] = isset ( $informations ['inflorescence'] ) ? $informations ['inflorescence'] : ''; $baseflor ['sexualite'] = isset ( $informations ['sexualite'] ) ? $informations ['sexualite'] : ''; $baseflor ['ordre_maturation'] = isset ( $informations ['ordre_maturation'] ) ? $informations ['ordre_maturation'] : ''; $baseflor ['pollinisation'] = isset ( $informations ['pollinisation'] ) ? $informations ['pollinisation'] : ''; $baseflor ['dissemination'] = isset ( $informations ['dissemination'] ) ? $informations ['dissemination'] : ''; $baseflor ['fruit'] = isset ( $informations ['fruit'] ) ? $informations ['fruit'] : ''; $baseflor ['couleur_fleur'] = isset ( $informations ['couleur_fleur'] ) ? $informations ['couleur_fleur'] : ''; $baseflor ['macule'] = isset ( $informations ['macule'] ) ? $informations ['macule'] : ''; $baseflor ['floraison'] = isset ( $informations ['floraison'] ) ? self::changerFloraisonEnChaine ( $informations ['floraison'] ) : ''; // récupérer dans ontologies $baseflor ['type_bio'] = isset ( $informations ['type_bio.libelle'] ) ? $informations ['type_bio.libelle'] : ''; $baseflor ['form_vegetale'] = isset ( $informations ['form_vegetale'] ) ? $informations ['form_vegetale'] : ''; $baseflor ['description'] = $baseflor; $this->meta->setProjet ( 'baseflor' ); $meta = $this->meta->getMetaDonnees (); $baseflor ['meta'] = $meta [0]; $baseflor ['meta'] ['url'] = $this->appUrls->obtenirUrlMetaDonnees ( 'baseflor' ); } $this->donnees ['baseflor'] = $baseflor; } static function changerFloraisonEnChaine($floraison) { $chaine = ""; if ($floraison != "") { $mois_fleurs = preg_match ( '/-/', $floraison ) ? preg_split ( '/-/', $floraison ) : $floraison; if (is_array ( $mois_fleurs )) { $chaine = "de " . self::$mois [( int ) $mois_fleurs [0] - 1] . " à " . self::$mois [( int ) $mois_fleurs [1] - 1]; } else { $chaine = "en " . self::$mois [( int ) $mois_fleurs - 1]; } } return $chaine; } public function getUrlWikipedia() { if (! isset ( $this->donnees ['wp'] )) { $this->getWikipedia (); } return $this->donnees ['wp']; } public function getWikipedia() { $wp = array (); $this->textes->setProjet ( 'wikipedia' ); $this->textes->setId ( self::getIdWp ( $this->nomCourant->getNomRetenu ()->get ( 'nom_sci' ) ) ); $wp ['titre'] = $donnees ['titre'] = "Description de wikipedia"; $wp ['lien'] = $this->textes->getPageUrl (); $wp ['meta'] ['url'] = $this->appUrls->obtenirUrlMetaDonnees ( 'wikipedia' ); $this->donnees ['wp'] = $wp; } private static function getIdWp($nomSci) { return urlencode ( str_replace ( ' ', '_', $nomSci ) ); } private function getWikini() { $wikini = array (); $wikini ['titre'] = 'Wikini'; $referentiel = $this->conteneur->getParametre ( 'referentiel' ); $num_tax = $this->nomCourant->getNomSelectionne ()->get ( 'num_taxonomique' ); $page_wiki = $this->wikini->getPageWikiPourRefEtNumTax ( $referentiel, $num_tax ); $wikini ['description'] = $this->wikini->getTexteFormate ( $page_wiki, 'description' ); $this->donnees ['wikini'] = $wikini; } public function getLienWikini() { $referentiel = $this->conteneur->getParametre ( 'referentiel' ); $num_tax = $this->nomCourant->getNomSelectionne ()->get ( 'num_taxonomique' ); return $this->wikini->getUrlPageWiki ( $referentiel, $num_tax ); } private function getCoste() { $coste = array (); $this->textes->setProjet ( 'coste' ); $this->textes->setId ( 'bdtfx.nt:' . $this->nomCourant->getNt () ); $texte = $this->textes->getTexte (); if (! empty ( $texte ['resultats'] )) { $texte = array_pop ( $texte ['resultats'] ); } if ($texte) { $coste ['titre'] = $texte ['titre']; $coste ['description'] = self::mettreEnFormeCoste ( $texte ['texte'] ); } $this->meta->setProjet ( 'coste' ); $meta = $this->meta->getMetaDonnees (); $coste ['meta'] = $meta [0]; $coste ['meta'] ['url'] = $this->appUrls->obtenirUrlMetaDonnees ( 'coste' ); $this->donnees ['coste'] = $coste; } static function mettreEnFormeCoste($texte) { $txt_fmt = array (); // decouper elements remarquables avant le texte self::separerNomScientifique_a_NomCommun ( $texte, $txt_fmt ); $texte = preg_replace ( '/\//', '', $texte ); // decouper elements remarquables après le texte self::separerEcologie_a_Usages ( $texte, $txt_fmt ); // le morceau qui reste est le gros de la description $texte = str_replace ( ';', '
-', '- ' . $texte ); $texte = str_replace ( '–', '', $texte ); $txt_fmt ['texte'] = $texte; return $txt_fmt; } static function separerNomScientifique_a_NomCommun(&$txt, &$txt_fmt) { if (preg_match ( '/\*\*(.+)\*\*([^–]*)–/', $txt, $retour )) { /* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */ $a_enlever = array ( '/–/', '/\./' ); $txt_fmt ['nom_scientifique'] = preg_replace ( $a_enlever, '', $retour [1] ); if (preg_match ( '/\((.+)\)/', $retour [2], $synonymes )) { $txt_fmt ['synonymes'] = $synonymes [1]; } else { $txt_fmt ['nom_scientifique'] .= $retour [2]; } $txt = str_replace ( $retour [0], '', $txt ); } /* !! attention il y a un espace avant les // du début !! */ if (preg_match ( '/^ \/\/([^\/\/]+)\/\//', $txt, $retour )) { $a_enlever = array ( '/–/', '/\./' ); $txt_fmt ['nom_commun'] = preg_replace ( $a_enlever, '', $retour [1] ); $txt = str_replace ( $retour [0], '', $txt ); } } static function separerEcologie_a_Usages(&$txt, &$txt_fmt) { if (preg_match ( '/\.\s*([A-ZÉÀÈ].+)$/', $txt, $retour )) { $txt_fmt ['ecologie'] = $retour [1]; $txt = str_replace ( $retour [0], '.', $txt ); if (isset ( $txt_fmt ['ecologie'] ) && preg_match ( '/–(.+)/', $txt_fmt ['ecologie'], $retour )) { $txt_fmt ['repartition'] = $retour [1]; $txt_fmt ['ecologie'] = str_replace ( $retour [0], '', $txt_fmt ['ecologie'] ); } if (isset ( $txt_fmt ['repartition'] ) && preg_match ( '/=(.+)$/', $txt_fmt ['repartition'], $retour )) { $txt_fmt ['floraison'] = $retour [1]; $txt_fmt ['repartition'] = str_replace ( $retour [0], '', $txt_fmt ['repartition'] ); } if (isset ( $txt_fmt ['floraison'] ) && preg_match ( '/–(.+)$|\n(.+)$/', $txt_fmt ['floraison'], $retour )) { $txt_fmt ['usages'] = isset ( $retour [1] ) ? $retour [1] : $retour [2]; $txt_fmt ['floraison'] = str_replace ( $retour [0], '.', $txt_fmt ['floraison'] ); } if (isset ( $txt_fmt ['floraison'] ) && preg_match ( '/([Ff]l\.) (.+)/', $txt_fmt ['floraison'], $retour )) { $txt_fmt ['floraison'] = $retour [2]; $txt_fmt ['floraison'] = str_replace ( $retour [1], '', $txt_fmt ['floraison'] ); } if (isset ( $txt_fmt ['floraison'] ) && preg_match ( '/([Ff]r\.) (.+)/', $txt_fmt ['floraison'], $retour )) { $txt_fmt ['fructification'] = $retour [2]; $txt_fmt ['floraison'] = str_replace ( $retour [0], '', $txt_fmt ['floraison'] ); $txt_fmt ['floraison'] = str_replace ( ',', '', $txt_fmt ['floraison'] ); $txt_fmt ['fructification'] = str_replace ( $retour [1], '', $txt_fmt ['fructification'] ); $txt_fmt ['fructification'] = str_replace ( '.', '', $txt_fmt ['fructification'] ); } } } } ?>