Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

<?php
// declare(encoding='UTF-8');
/**
 * Classe mère du module Liste.
 *
 * @category    PHP 5.2
 * @package             eflore-consultation
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @author              Delphine CAUQUIL <delphine@tela-botanica.org>
 * @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 Resultat extends aControleur {

        private $parametres = null;
        private $resultats = null;
        private $donneesTpl = array();
        private $i18n =  array();
        
        private $parametresAvancesGeneriques = array('gen','fam','nn','nt','sp','ssp','type','sto','sti','stc');

        public function initialiser() {
                spl_autoload_register(array($this, 'chargerClassesResultat'));
                $this->parametres = new ParametresResultats();
                $this->capturerParametres();
                $this->capturerParametresAvances();
                $this->parametres->referentielCourant = Registre::get('parametres.referentiel');
                $this->parametres->projetImg = Config::get($this->parametres->referentielCourant.'.baseImages');
                $this->resultats = Registre::get('resultats');
                $this->i18n = I18n::get('Recherche-form-avancee');
        }

        private function chargerClassesResultat($classe) {
                $base = dirname(__FILE__).DS;
                $cheminFormateurs = $base.'formateurs'.DS;
                $cheminFormateursNs = $cheminFormateurs.'nom_scientifique'.DS;
                $cheminFormateursNv = $cheminFormateurs.'nom_vernaculaire'.DS;
                $dossiers = array($base, $cheminFormateurs, $cheminFormateursNs, $cheminFormateursNv);
                foreach ($dossiers as $chemin) {
                        $fichierATester = $chemin.$classe.'.php';
                        if (file_exists($fichierATester)) {
                                include_once $fichierATester;
                                return null;
                        }
                }
        }

        private function capturerParametres() {
                $this->parametres->masqueRecherche = "";
                if (isset($_GET['resultat'])) {
                        $this->parametres->typeResultat = $_GET['resultat'];
                }
                if (isset($_GET['nom'])) {
                        $this->parametres->masqueRecherche = trim($_GET['nom']);
                }
                //recherche avancee type
                if (isset($_GET['fam'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['fam']);
                }
                if (isset($_GET['gen'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['gen']);
                }
                if (isset($_GET['sp'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['sp']);
                }
                if (isset($_GET['ssp'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['ssp']);
                }
                if (isset($_GET['and'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['and']);
                }
                if (isset($_GET['anf'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['anf']);
                }
                if (isset($_GET['au'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['au']);
                }
                if (isset($_GET['bib'])) {
                        $this->parametres->masqueRecherche .= trim($_GET['bib']);
                }
                
                
                if (isset($_GET['type_nom'])) {
                        $this->parametres->typeNom = $_GET['type_nom'];
                }
                
                if (isset($_GET['niveau'])) {
                        Registre::set('parametres.niveau', $_GET['niveau']);
                }
        }
        
        private function capturerParametresAvances() {
                $this->capturerParametresAvancesGeneriques();
                $this->capturerParametresAvancesDependantsLangage();
                $this->capturerParametresAvancesPresenceSpecifiques();
        }
        
        private function capturerParametresAvancesGeneriques() {
                foreach($this->parametresAvancesGeneriques as $param) {
                        if (isset($_GET[$param]) && $_GET[$param] != '') {
                                $this->param[$param] = urldecode($_GET[$param]);
                        }
                }
        }
        
        private function capturerParametresAvancesDependantsLangage() {
                if (isset($_GET['au']) && $_GET['au'] != ''
                && $_GET['au'] != urlencode($this->i18n['valeur-form-auteur'])) {
                        $this->param['au'] = urldecode($_GET['au']);
                }
                if (isset($_GET['bib']) && $_GET['bib'] != ''
                && $_GET['bib'] != urlencode($this->i18n['valeur-form-bib'])) {
                        $this->param['bib'] = urldecode($_GET['bib']);
                }
                if (isset($_GET['and']) && $_GET['and'] != ''
                && $_GET['and'] != urlencode($this->i18n['valeur-form-date'])) {
                        $this->param['and'] = urldecode($_GET['and']);
                }
                if (isset($_GET['anf']) && $_GET['anf'] != ''
                && $_GET['anf'] != urlencode($this->i18n['valeur-form-date'])) {
                        $this->param['anf'] = urldecode($_GET['anf']);
                }
        }
        
        private function capturerParametresAvancesPresenceSpecifiques()  {
                $champs_presence = $this->obtenirChampsPresence();
                foreach($champs_presence as $champ) {
                        $param = $champ['param'];
                        if (isset($_GET[$param]) && $_GET[$param] != '') {
                                $this->param[$param] = urldecode($_GET[$param]);
                        }
                }
        }
        
        private function obtenirChampsPresence() {
                $tableau_champs_presence = array();
                $referentiel = Registre::get('parametres.referentiel');
                $champs_presence = Config::get($referentiel.'.champsPresence');
                $champs_presence_spl = explode('|', $champs_presence);
                foreach($champs_presence_spl as $champ) {
                        $label_param_champ = explode(':', $champ);
                        $tableau_champs_presence[] = array('param' => $label_param_champ[1],
                                                                                                        'label' => $label_param_champ[0]);
                }
                return $tableau_champs_presence;
        }
        

        public function executerActionParDefaut() {
                $this->executerResultat();
        }

        public function executerResultat() {
                $this->chargerOnglets();
                $this->chargerNbreDeTaxons();
                $this->chargerNomsFormates();
                $this->setSortie(self::RENDU_CORPS, $this->getVue('resultat', $this->donneesTpl));
        }
        

        private function chargerOnglets() {
                $donnees = array();
                $donnees['typeResultat'] = $this->parametres->typeResultat;
                $donnees['typeNom'] = $this->parametres->typeNom;
                $donnees['ongletsNs'] = array('determination', 'retenu', 'decompo');
                $donnees['ongletsNv'] = array('determination', 'alphab');
                if (($_GET['action']) == 'rechercheAvancee') {
                        $donnees['urls']['alphab'] = $this->urls->obtenirUrlResultatAvanceOnglets('alphab', $this->param);
                        $donnees['urls']['retenu'] = $this->urls->obtenirUrlResultatAvanceOnglets('retenu', $this->param);
                        $donnees['urls']['determination'] = $this->urls->obtenirUrlResultatAvanceOnglets('determination',$this->param);
                        $donnees['urls']['decompo'] = $this->urls->obtenirUrlResultatAvanceOnglets('decompo',$this->param);
                } else {
                        
                        $donnees['urls']['alphab'] = $this->urls->obtenirUrlResultatAlphab();
                        $donnees['urls']['retenu'] = $this->urls->obtenirUrlResultatRetenu();
                        $donnees['urls']['determination'] = $this->urls->obtenirUrlResultatDetermination();
                        $donnees['urls']['decompo'] = $this->urls->obtenirUrlResultatDecompo();
                }
                $donnees['i18n']['nv'] = I18n::get('Resultat-onglets-nv');
                $donnees['i18n']['ns'] = I18n::get('Resultat-onglets-ns');
                $this->donneesTpl['ongletsHtml'] = $this->getVue('onglets', $donnees);
        }

        private function chargerNbreDeTaxons() {
                $this->donneesTpl['nbreTaxons'] = $this->resultats['entete']['total'];
        }

        private function chargerNomsFormates() {
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt mise en forme des noms");
                $formateur = ResultatFormateurFabrique::creer($this->parametres, $this->resultats);
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt formatage des noms");
                $formateur->formater();
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt triage des noms");
                $formateur->trier();
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt surlignage des noms");
                $formateur->surligner();
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt création de la vue");
                $this->donneesTpl['nomsHtml'] = $this->getVue($formateur->getTplNom(), $formateur->getTplInfos());
                if (Config::get('benchmark_chrono')) Chronometre::chrono("Après mise en forme des noms");
        }
}
?>