Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1046 | 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 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 Illustrations extends aControleur {

        private $conteneur = null;
        private $nomCourant = null;
        private $images = null;
        private $appUrls = null;
        private $meta = null;
        private $referentiel = 'bdtfx';
        private $donnees = array();

        public function __construct(Conteneur $conteneur) {
                $this->conteneur = $conteneur;
                $this->nomCourant = $this->conteneur->getNomCourant();
                $this->referentiel = $this->conteneur->getParametre('referentiel');
                $this->images = $this->conteneur->getApiImages();
                $this->appUrls = $this->conteneur->getAppUrls();
                $this->meta = $this->conteneur->getApiMetaDonnees();
        }

        public function getDonnees() {
                $this->donnees = array();
                $this->getPhotos();
                $dessin = $this->addDessin();
                if (!empty($dessin)) {
                        array_push($this->donnees, $dessin);    
                }

                return $this->donnees;
        }
        
        public function getPhotos() {
                $projets[] = Config::get($this->referentiel.'.baseImages');
                $projets[] = Config::get($this->referentiel.'.baseImagesSupp');
                foreach ($projets as $projet) {
                        if ($projet != "") {
                                $images = $this->initialiserPhotos($projet);
                                $this->formaterListePhotos($projet, $images);
                        }
                }
        }
        
        private function initialiserPhotos($projet) {
                $this->images->setProjet($projet);
                $nnr = $this->nomCourant->getNnr();
                return $this->images->getInfosImagesParIdsNoms(array($nnr));
        }
        
        private function formaterListePhotos($projet, $images) {
                $max = Config::get('pictures.number.max');
                foreach ($images as $idImg => $img) {
                        $infosImg['src'] = htmlentities($img['binaire.href']);
                
                        if ($img['auteur.libelle'] != '') {
                                $infosImg['legende']['titre'] = htmlentities($img['auteur.libelle']);
                        } else {
                                $infosImg['legende']['titre'] = "Anonyme";
                        }
                        
                        if ($img['date'] != '') {
                                $infosImg['legende']['titre'] .= ", le ".htmlentities($this->formaterDateImg($img['date']));
                        }
                        
                        if ($img['station.libelle'] != '') {
                                $infosImg['legende']['texte'] = htmlentities($img['station.libelle']);
                        } else {
                                $infosImg['legende']['texte'] = "&nbsp;";
                        }
                        
                        array_push($this->donnees, $infosImg);
                        if (--$max <= 0) {
                                return null;
                        }
                }
        }

        private function formaterDateImg($date) {
                $dateFmt = $date;
                if ($date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
                        $dateFmt = 'inconnue';
                } else {
                        $dateFmt = strftime('%e %B %Y', strtotime($date));
                }
                return $dateFmt;
        }
        
        public function addDessin() {
                $img = array();
                $projet = Config::get($this->referentiel.'.baseDessins');
                if ($projet != "") {
                        $dessin = array();
                        $tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
                        $this->images->setProjet($projet);
                        $this->images->setNnTaxon($tax);
                        $costeImg = $this->images->getInfosImagesTaxons();
                        
                        if (count($costeImg) != 0) {
                                $img['src'] = $costeImg[key($costeImg)]['binaire.href'];
                                $img['legende']['titre'] = "Illustration de Coste";
                                $img['legende']['texte'] = "&nbsp;";
                        }
                }

                return $img;
        }
}
?>