Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 990 | Rev 1064 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Classe mère du module Mobile.
 *
 * @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 Mobile extends aControleur {

        private $theme = 'pyracantha';
        private $parametres = array();
        private $conteneur = null;
        private $num_nom = 0;
        private $nom_courant = null;
        private $nom_retenu = '';
        private $url;

        public function initialiser() {
                $this->capturerParametres();
                $this->conteneur = new Conteneur($this->parametres);
                $this->url = $this->conteneur->getAppUrls();
                $this->nomCourant = $this->conteneur->getNomCourant();
                $this->nom_retenu = $this->conteneur->getNomCourant()->getNomRetenu();
                spl_autoload_register(array($this, 'chargerClassesSources'));
        }
        
        private function chargerClassesSources($classe) {
                $base = dirname(__FILE__).DS;
                $cheminSources = $base.'sources'.DS;
                $dossiers = array($base, $cheminSources);
                foreach ($dossiers as $chemin) {
                        $fichierATester = $chemin.$classe.'.php';
                        if (file_exists($fichierATester)) {
                                include_once $fichierATester;
                                return null;
                        }
                }
        }

        private function capturerParametres() {
                if (isset($_GET['num_nom'])) {
                        $this->parametres['num_nom'] = $_GET['num_nom'];
                }
                if (isset($_GET['nom'])) {
                        $this->parametres['nom'] = $_GET['nom'];
                }
                if (isset($_GET['type_nom'])) {
                        $this->parametres['type_nom'] = $_GET['type_nom'];
                }
                if (isset($_GET['referentiel'])) {
                        $this->parametres['referentiel'] = $_GET['referentiel'];
                        Registre::set('parametres.referentiel', $_GET['referentiel']);
                }
                if (isset($_GET['niveau'])) {
                        Registre::set('parametres.niveau', $_GET['niveau']);
                }
                if (isset($_GET['theme'])) {
                        $this->theme = $_GET['theme'];
                }
        }
        
        public function executerActionParDefaut() {
                $this->executerFiche();
        }

        public function executerFiche(){
                $niveau = isset($_GET['niveau']) ? $_GET['niveau'] : '1';
                
                $squelette = 'theme_'.$this->theme.'_niveau'.$niveau;
                
                $donnees = $this->parametres;
                $donnees['nom_retenu'] = $this->nom_retenu->get('nom_sci_html').' '.$this->nom_retenu->get('auteur');
                $donnees['famille'] = $this->nom_retenu->getTaxonSupRang('180');
                
                $donnees = array_merge($this->obtenirDonnees(), $donnees);
                $donnees['css'] = $this->obtenirLienCss();
                $donnees['contenu_onglet'] = $this->getVue($squelette, $donnees);
                $donnees['lien'] = $this->url->obtenirUrlMobile($this->parametres['num_nom'], $this->parametres['type_nom'], $this->parametres['nom']);
                $this->setSortie(self::RENDU_CORPS, $this->getVue('fiche', $donnees), true);
                //print_r($donnees);
        }
        
        public function obtenirDonnees() {
                $donnees = array();
                $num_nom = $this->nomCourant->getNns();
                $referentiel = $this->conteneur->getParametre('referentiel');
                
                $taxons = new Taxons($this->conteneur);
                $donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $num_nom);
                
                $sources = array('illustrations', 'repartition', 'texte', 'floraison', 'nomsCommuns');
                foreach ($sources as $source) {
                        $nom_classe = ucfirst($source);
                        $classe = new $nom_classe($this->conteneur);
                        $donnees[$source] = $classe->getDonnees();
                }

                return $donnees;
        }
        
        private function obtenirLienCss() {
                $lien = 'modules/mobile/presentations/css/';
                if (strcmp($this->theme, 'pyracantha') >= 0) {
                        $lien .= 'pyracantha_blanc.css';
                } else {
                        $lien .= 'gentiana.css';
                }
                return $lien;
        }
}
?>