Subversion Repositories Applications.referentiel

Rev

Rev 295 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Classe Controleur du module Fiche Taxon.
 *
 * @category    Php 5.2
 * @package             Taxon
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @copyright   2010 Tela-Botanica
 * @license             http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
 * @license             http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
 * @version             SVN: $Id: Fiche.php 96 2010-06-21 16:46:31Z jpm $
 */
class FicheTaxon extends AppliControleur {
        
        private $donnees = array();
        protected $taxonDao = null;
        private $tableau_manuel = null;
        private $num_taxon = array(0=>0,1=>0,2=>0);
        
        //+----------------------------------------------------------------------------------------------------------------+
        // Méthodes
        /**
         * Fonction d'affichage par défaut
         */
        public function executerActionParDefaut() {
                return $this->afficherTaxon();
        }
        
        // +---------------------------------------------------------------------------------------------------------------+
        // FICHE CONSULTATION TAXON
        public function afficherTaxon() {
                // Récupération du référentiel
                if (isset($_GET['ref'])) { 
                        $this->referentiel = strtolower($_GET['ref']);
                }
                // Gestion des actions par défaut
                $this->taxonDao = new TaxonDao();
                $this->definirCommeModulePrincipal(get_class($this));
                $this->construireMenu($this->referentiel);
                $this->construireFilAriane($this->referentiel);
                $this->executerActionReferentiel('Recherche', 'chargerMoteurRecherche', $this->referentiel, 10);
                
                // Gestion des données de la requête
                if (!isset($_GET['num_nom'])) {
                        
                } else {
                        // Récupération des données
                        $this->donnees['referentiel'] = $this->referentiel;
                        $this->donnees['num_nom'] = $_GET['num_nom'];
                        $this->donnees['info'] = $this->taxonDao->getTaxon($this->referentiel, $this->donnees['num_nom']);
                        $this->donnees['num_nom_retenu'] = $this->donnees['info']['num_nom_retenu'];
                        $this->donnees['nom'] = $this->donnees['info']['nom_sci'];
                        $this->donnees['exclu_taxref'] = $this->donnees['info']['exclure_taxref'];
                        
                        if ($this->donnees['info'] != '') {
                                // Chargement des données des onglets
                                $this->chargerNomenclature();
                                $this->chargerSynonymie();
                                $this->chargerClassification();
                                $this->chargerChorologie();
                                $this->chargerComplements();
                        }
                        $this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_taxon', $this->donnees));
                }
        }
        
        private function chargerNomenclature() {
                $this->donnees['selectionne'] = $this->taxonDao->getNomenclature($this->referentiel, $this->donnees['num_nom']);
                if ($this->donnees['num_nom'] != $this->donnees['num_nom_retenu'] && $this->donnees['num_nom_retenu'] != '') {
                        $this->donnees['retenu'] = $this->taxonDao->getNomenclature($this->referentiel, $this->donnees['num_nom_retenu']);
                } 
                if ($this->donnees['info']['hybride_parent_01'] != '' && $this->donnees['info']['hybride_parent_02'] != '') {
                        $this->donnees['parents'] = $this->taxonDao->getParentsHybride($this->referentiel, $this->donnees['num_nom']);
                } elseif ($this->donnees['info']['hybride_parent_01'] != '' || $this->donnees['info']['hybride_parent_02'] != ''){
                        $this->donnees['parents'] = $this->taxonDao->getParentsHybride($this->referentiel, $this->donnees['num_nom']);
                }
        }
        
        // recherche les synonymes (à compléter)
        private function chargerSynonymie() {
                $rechercheDao = new RechercheDao();
                // recherche des synonymes nomenclaturaux et taxonomiques
                $parametres = $this->parserChaineDeRecherche('nn:'.$this->donnees['num_nom'].' tax:1');
                $parametres['ref']= $this->referentiel;
                $synonymes = $rechercheDao->chercher('ParTaxon', $parametres); 
                if ($synonymes != '') {
                        $this->donnees['syn'] = $synonymes;
                }
                // synonyme proparte
                if ($this->donnees['info']['synonyme_proparte'] != ''){
                        $propartes = explode(',', $this->donnees['info']['synonyme_proparte']);
                        foreach ($propartes as $proparte) {
                                $this->donnees['pp'][] = $this->taxonDao->getTaxonAffichage($this->referentiel, trim($proparte));
                        }
                }
                // homonymie
                $nom = $this->encodeChaine($this->donnees['info']['nom_sci']);
                $homonymes = $this->taxonDao->getHomonyme($this->referentiel, $nom);
                if (count($homonymes) > 1) {
                        foreach ($homonymes as $id => &$homonyme) {
                                $homonyme['statut'] = $homonyme['homonyme'];
                        }
                        
                        $this->donnees['h'] = $homonymes;
                }
        }
        
        private function chargerChorologie() {
                $this->chargerTableauManuel('presence');
                $this->chargerTableauManuel('statuts_origine');
                $this->chargerTableauManuel('statuts_introduction');
                $this->chargerTableauManuel('statuts_culture');
                foreach ($this->donnees['info'] as $param => $valeur) {
                        if ($param == 'presence') {
                                $this->donnees['chorologie']['Présence']['France']['code'] = $valeur;
                                $this->donnees['chorologie']['Présence']['France']['valeur'] = $this->tableau_manuel['presence'][$valeur];
                        } elseif (preg_match('/presence_(.*)/', $param, $lieu)) {
                                $this->donnees['chorologie']['Présence'][$lieu['1']]['code'] = $valeur;
                                $this->donnees['chorologie']['Présence'][$lieu['1']]['valeur'] = $this->tableau_manuel['presence'][$valeur];
                        } elseif ($param == 'statut_origine') {
                                $this->donnees['chorologie']['Statut d\'origine']['France']['code'] = $valeur;
                                $this->donnees['chorologie']['Statut d\'origine']['France']['valeur'] = 
                                        $this->tableau_manuel['statuts_origine'][$valeur];
                        } elseif (preg_match('/statut_origine_(.*)/', $param, $lieu)) {
                                $this->donnees['chorologie']['Statut d\'origine'][$lieu['1']]['code'] = $valeur;
                                $this->donnees['chorologie']['Statut d\'origine'][$lieu['1']]['valeur'] = 
                                        $this->tableau_manuel['statuts_origine'][$valeur];
                        } elseif ($param == 'statut_introduction') {
                                $this->donnees['chorologie']['Statut d\'introduction']['France']['code'] = $valeur;
                                $this->donnees['chorologie']['Statut d\'introduction']['France']['valeur'] = 
                                        $this->tableau_manuel['statuts_introduction'][$valeur];
                        } elseif (preg_match('/statut_introduction_(.*)/', $param, $lieu)) {
                                $this->donnees['chorologie']['Statut d\'introduction'][$lieu['1']]['code'] = $valeur;
                                $this->donnees['chorologie']['Statut d\'introduction'][$lieu['1']]['valeur'] = 
                                        $this->tableau_manuel['statuts_introduction'][$valeur];
                        } elseif ($param == 'statut_culture') {
                                $this->donnees['chorologie']['Statut de culture']['France']['code'] = $valeur;
                                $this->donnees['chorologie']['Statut de culture']['France']['valeur'] = 
                                        $this->tableau_manuel['statuts_culture'][$valeur];
                        } elseif (preg_match('/statut_culture_(.*)/', $param, $lieu)) {
                                $this->donnees['chorologie']['Statut de culture'][$lieu['1']]['code'] = $valeur;
                                $this->donnees['chorologie']['Statut de culture'][$lieu['1']]['valeur'] = 
                                        $this->tableau_manuel['statuts_culture'][$valeur];
                        }
                }
                foreach ($this->donnees['chorologie']['Présence'] as $lieu => $valeur) {
                        if (!isset($this->donnees['chorologie']['Statut d\'origine'][$lieu])) {
                                $this->donnees['chorologie']['Statut d\'origine'][$lieu]['code'] = '';
                        }
                        if (!isset($this->donnees['chorologie']['Statut d\'introduction'][$lieu])) {
                                $this->donnees['chorologie']['Statut d\'introduction'][$lieu]['code'] = '';
                        }
                        if (!isset($this->donnees['chorologie']['Statut de culture'][$lieu])) {
                                $this->donnees['chorologie']['Statut de culture'][$lieu]['code'] = '';
                        }
                }
        }
        
        private function chargerClassification() {
                $this->chargerTableauManuel('signification_rang');
                $this->chargerTableauManuel('presence');
                $this->donnees['valeur_rang'] = $this->tableau_manuel['signification_rang'];
                $this->donnees['valeur_presence'] = $this->tableau_manuel['presence'];
                if ($this->donnees['info']['num_tax_sup'] != '' && $this->donnees['info']['num_tax_sup'] !== "0") {
                        $this->donnees['classification']['supérieurs'] = array_reverse($this->taxonDao->getClassification
                                ('Superieur', $this->referentiel, $this->donnees['info']['num_tax_sup']));
                } elseif (isset($this->donnees['retenu']['num_tax_sup']) && ($this->donnees['retenu']['num_tax_sup'] != '')) {
                        $this->donnees['classification']['supérieurs'] = array_reverse($this->taxonDao->getClassification
                                ('Superieur', $this->referentiel, $this->donnees['retenu']['num_tax_sup']));
                }       
                if ($this->donnees['num_nom_retenu'] != '') {
                        $class_inf = $this->taxonDao->getClassification
                                ('Inferieur', $this->referentiel, $this->donnees['num_nom_retenu']);
                        if ($class_inf != '') {
                                $this->donnees['classification']['inférieurs'] = $class_inf['inf'];    
                                $this->donnees['niveau'] = $class_inf['niveau'];
                                arsort($class_inf['nb_par_rang']);
                                $this->donnees['noms_rang'] = $class_inf['nb_par_rang'];
                        }
                }       
        }
        
        private function chargerComplements() {
                $champs_manuel_technique = explode(',', $this->manuel['champs']);
                $champs_base_donnees = key($this->donnees['info']);
                $champs_supp_base = array_diff_key($this->donnees['info'], array_flip($champs_manuel_technique));
                foreach ($champs_supp_base as $champ=>$valeur) {
                        if (!(preg_match('/presence_(.*)/',$champ) || preg_match('/statut_origine_(.*)/', $champ) || 
                                 preg_match('/statut_introduction_(.*)/', $champ) || preg_match('/statut_culture_(.*)/', $champ))) {
                                $this->donnees['complement'][$champ] = $valeur;
                        }
                }
        }
        
        private function parserChaineDeRecherche($chaine) {             
                $mots = preg_split('/ /i', $chaine, -1, PREG_SPLIT_NO_EMPTY);
                $parametres = array('mots' => '');
                $cle_precedente = null;
                foreach ($mots as $mot) {
                        if (preg_match('/^(sg|gen|sp|ssp|au|an|nn|bib|nr|tax):(.*)$/', $mot, $match)) {
                                $cle = $match[1];
                                $cle_precedente = $cle;
                                $valeur = $match[2];
                                $parametres[$cle] = $valeur;
                        } else if (!is_null($cle_precedente)) {
                                $parametres[$cle_precedente] .= ' '.$mot;
                        } else if (is_null($cle_precedente)) {
                                if (empty($parametres['mots'])) {
                                        $parametres['mots'] = $mot;
                                } else {
                                        $parametres['mots'] .= ' '.$mot;
                                }
                        }
                }               
                return $parametres;
        }
        
        public function encodeChaine($chaine) {
                if (Config::get('sortie_encodage') != Config::get('appli_encodage')) {
                        $chaine = mb_convert_encoding($chaine, Config::get('sortie_encodage'), Config::get('appli_encodage'));
                }
                $chaine = urlencode($chaine);
                return $chaine;
        }
        
        // retourne l'url de la fiche taxon pour les liens 
        public static function getUrlFicheTaxon($params, $type = '') {
                $taxon = null;
                switch ($type) {
                        case 'bas' : 
                                $taxon['num_nom'] = $params['bas_num'];
                                break;
                        case 'p1' :
                                $taxon['num_nom'] = $params['p1_num'];
                                break;
                        case 'p2' : 
                                $taxon['num_nom'] = $params['p2_num'];
                                break;
                        default : $taxon['num_nom'] = $params;
                                break;
                }
                return Recherche::getUrlFicheTaxon($taxon);
        }
        
        // charger tableau de $this->manuel
        private function chargerTableauManuel($titreTableau) {
                $champs = explode(',', $this->manuel[$titreTableau]);
                foreach ($champs as $champ) {
                        list($champ_nom, $type) = explode('=', trim($champ));
                        $this->tableau_manuel[$titreTableau][$champ_nom] = $type;
                }
        }
        

}