Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 88 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php
class Recherche extends aControleur {
        
        //+----------------------------------------------------------------------------------------------------------------+
        // Méthodes
        protected $nom = null;
        protected $type_nom = 'nom_scientifique';
        protected $submit = '';
        public function initialiser() {
                $this->capturerParametres();
        }
        /**
         * Fonction d'affichage par défaut
         */
        public function executerActionParDefaut() {
                $this->executerAction('RechercheSimple', 'executerAccueil');
                
        }

        public function executerRechercheSimple() {
                $donnees['type_nom'] = $this->type_nom;
                $donnees['nom'] = $this->nom;
                if (strlen($donnees['nom']) < 3) {
                        $donnees['message']['attention'] = 'info_nb_lettres';
                } else {
                        $presence = $this->rechercherNom();
                        if ($presence == '') { // s'il n'y a pas de nom
                                $donnees['message']['attention'] = 'info_sp_abs';
                        } elseif ($presence != 'ok') { // s'il y a des noms approchés
                                if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
                                        $donnees['message']['attention'] = 'info_sp_abs';
                                }
                                $donnees['message']['nom_approche'] = $presence;
                        }
                }
                Registre::set('donneesMoteur', $donnees);
                $this->executerAction('RechercheSimple', 'executerForm');
                if (Registre::get('resultats')) {
                        $this->executerAction('Resultat', 'executerResultat');
                }
        }
        
        // regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
        // $noms classe métier nom ou nom
        private function rechercherNom() {
                $noms = ($this->type_nom == 'nom_vernaculaire') 
                                ? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
                                : new Noms(Registre::get('parametres.referentiel'));
                $approche = '';
                $res = $noms->getRechercheEtendue($this->nom);
                $form = I18n::get('Recherche-form-nom');
                if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
                        $approche = $this->rechercherNomApproche($noms);
                } elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
                        $ids = array_keys($res['resultat']);
                        $url = $this->obtenirUrlFiche($ids[0]);
                        $this->redirigerVers($url);
                } else { // affiche les résultats
                        $res['type'] = $this->type_nom;
                        Registre::set('resultats', $res);
                        $approche = 'ok';
                        if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
                                $approche = $this->rechercherNomApproche($noms);
                        }
                }
                return $approche;
        }
        
        private function rechercherNomApproche($noms) {
                $approche = '';
                $res = $noms->getRechercheFloue($this->nom);
                if (!($res == false || $res['entete']['total'] == 0)) {
                        for ($i = 0; $i < 3; $i++) {
                                $nom_proche = array_shift($res['resultat']);
                                $approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
                                $approche[$i]['url_nom_approche'] = $this->obtenirUrlRechercheSimple($approche, $this->type_nom);
                        }
                }
                return $approche;
        }
        
        private function capturerParametres() {
                if (isset($_GET['nom'])) {
                        $this->nom = $_GET['nom'];
                }
                if (isset($_GET['type_nom'])) {
                        $this->type_nom = $_GET['type_nom'];
                }
                
                if (isset($_GET['submit'])) {
                        $this->submit = urldecode($_GET['submit']);
                }
        }
        
}
?>