Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 990 | Rev 1103 | 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() {
                $url_picto = $this->obtenirUrlPicto();
                $obj =  json_decode(file_get_contents($url_picto), true);
                
                $arr = $obj['resultats'];
                //echo '<pre>'.print_r($obj, true).'</pre>';
                foreach($arr as $index) {
                        $this->formaterListePhotos($index);
                }
        }

        
        public function obtenirUrlPicto() {
                $url_picto = "http://www.tela-botanica.org/eflore/del/services/0.1/images?navigation.depart=0"
                                        ."&navigation.limite=4&masque.nn=".$this->nomCourant->getNnr()
                                        ."&tri=votes&ordre=desc&protocole=1";
        
                return ($url_picto);
        }
        
        private function formaterListePhotos($images) {
                $infosImg['src'] = $images['binaire.href'];
        
                $obs = $images['observation'];
                if ($obs['auteur.nom'] != '') {
                        $infosImg['legende']['titre'] = $obs['auteur.nom'];
                        if ($obs['auteur.prenom'] != '') {
                                $infosImg['legende']['titre'] .= ' '.$obs['auteur.prenom'];
                        }
                } else {
                        $infosImg['legende']['titre'] = "Anonyme";
                }
                
                if ($obs['date_observation'] != '') {
                        $infosImg['legende']['titre'] .= ", le ".$this->formaterDateImg($obs['date_observation']);
                }
                
                if ($obs['zone_geo'] != '') {
                        $infosImg['legende']['texte'] = $obs['zone_geo'];
                        if ($obs['lieudit'] != '') {
                                $infosImg['legende']['texte'] .= ' ('.$obs['lieudit'].')';
                        }
                } else {
                        $infosImg['legende']['texte'] = "&nbsp;";
                }
                
                array_push($this->donnees, $infosImg);
        }

        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;
        }
}
?>