Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

<?php
// declare(encoding='UTF-8');
/**
 * Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée
 * Encodage en entrée : utf8
 * Encodage en sortie : utf8
 *
 * Cas d'utilisation et documentation :
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche
 *
 *
 * @author              Aurélien PERONNET <aurelien@tela-botanica.org>
 * @license     GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 * @license     CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 * @version     $Id$
 * @copyright   Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
 */
class Recherche extends WidgetCommun {
        const DS = DIRECTORY_SEPARATOR;
        /**
        * Méthode appelée par défaut pour charger ce widget.
        */
        public function executer() {
                $retour = null;
                $this->extraireParametres();
                $methode = $this->traiterNomMethodeExecuter("recherche");
                if (method_exists($this, $methode)) {
                        $retour = $this->$methode();
                } else {
                        $this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
                }
                if (is_null($retour)) {
                        $info = 'Un problème est survenu : '.print_r($this->messages, true);
                        $this->envoyer($info);
                } else {
                        $squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
                        $contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
                        if (isset($_GET['callback'])) {
                                $this->envoyerJsonp(array('contenu' => $contenu));
                        } else {
                                $this->envoyer($contenu);
                        }
                }
        }
        
        public function extraireParametres() {
                extract($this->parametres);
        }
        
        public function executerRecherche() {
                $widget['donnees'] = array();
                $widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl'];
                $widget['donnees']['efloreConsultationUrl'] = $this->config['url']['efloreConsultationUrl'];
                $widget['donnees']['efloreRechercheSciUrlTpl'] = $this->config['url']['efloreRechercheSciUrlTpl'];
                $widget['donnees']['efloreRechercheVernaUrlTpl'] = $this->config['url']['efloreRechercheVernaUrlTpl'];
                $widget['donnees']['ficheTaxonUrlTpl'] = $this->config['url']['ficheTaxonUrlTpl'];
                
                $widget['donnees']['referentielsSciDispos'] = $this->traiterReferentielSciDispos();
                $widget['donnees']['referentielsConsultationUrls'] = $this->traiterUrlsConsultationReferentiels($widget['donnees']['referentielsSciDispos']);
                $widget['donnees']['referentielsVernasDispos'] = $this->traiterReferentielsSciVernasDispos();
                $ref_sci_defaut = array_shift(array_keys($widget['donnees']['referentielsSciDispos']));
                $ref_verna_defaut = $widget['donnees']['referentielsVernasDispos'][$ref_sci_defaut];
                $widget['donnees']['efloreRechercheSciUrlDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['efloreRechercheSciUrlTpl']);
                $widget['donnees']['efloreRechercheVernaUrlDefaut'] = str_replace('{referentiel}',$ref_verna_defaut, $this->config['url']['efloreRechercheVernaUrlTpl']);
                $widget['donnees']['ficheTaxonUrlTplDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['ficheTaxonUrlTpl']);
                $widget['squelette'] = 'recherche';
                return $widget;
        }
        
        private function traiterReferentielSciDispos() {
                $refs_sci_fmt = array();
                $refs_sci = $this->config['referentiel']['referentielsSciDispos'];
                $refs_sci = explode(',', $refs_sci);
                foreach($refs_sci as $ref) {
                        $ref_code_desc = explode('#', $ref);
                        $refs_sci_fmt[$ref_code_desc[0]] = $ref_code_desc[1];
                }
                return $refs_sci_fmt;
        }
        
        private function traiterReferentielsSciVernasDispos() {
                $refs_verna = $this->config['referentiel']['referentielsVernaDispos'];
                $refs_verna = explode(',', $refs_verna);
                $tab_refs_verna = array();
                foreach($refs_verna as $ref_verna) {
                        $ref_sci_a_verna = explode(":", $ref_verna);
                        $tab_refs_verna[$ref_sci_a_verna[0]] = $ref_sci_a_verna[1];
                }
                return $tab_refs_verna;
        }
        
        private function traiterUrlsConsultationReferentiels($referentiels) {
                $urls = array();
                foreach($referentiels as $code_ref => $nom) {
                        $config_url_ref = 'efloreConsultation'.ucwords($code_ref).'Url';
                        if(isset($this->config['url'][$config_url_ref])) {
                                $urls[$code_ref] = $this->config['url'][$config_url_ref];
                        } else {
                                $urls[$code_ref] = $this->config['url']['efloreConsultationUrl'];
                        }
                }
                return $urls;
        }
}
?>