Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
class CbnmedFormateur implements Formateur {
        public $dest_map = array();
        public $img = array();
        public function __construct($parametres, $info) {
                $this->param = $parametres;
                $this->info = $info;
        }
        public function img() {
                $qualite = 90;
                imagejpeg($this->img['cbnmed'], Config::get('cache.stockageChemin').$this->dest_map['cbnmed'], $qualite);
        }
        //+----------------------------------------------------------------------------------------------------------------+
        // Méthodes d'accès aux objets du Framework
        /**
        * Méthode de connection à la base de données sur demande.
        * Tous les services web n'ont pas besoin de s'y connecter.
        */
        protected function getBdd() {
        if (! isset($this->Bdd)) {
        $this->Bdd = new Bdd();
        }
        return $this->Bdd;
        }
        
        public function definirCouleurs() {
        // green
        $couleur['green'] = imagecolorallocate($this->img['cbnmed'], 0, 255, 0);
        // red
        $couleur['red'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 0);
        // blue
        $couleur['blue'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 255);
        // purple
        $couleur['purple'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 255);
        // black
        $couleur['black'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 0);
        return $couleur;
        }
        public function initialiserImage() {
                // Nom du fichier image en sortie
                $this->cheminCartesBase = Config::get('Cartes.chemin');
                $this->dest_map['cbnmed'] = 'cbnmed_nt'.$this->info['nt'].'_'.$this->info['src_map'];
                $this->img['cbnmed'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
        }
        
        public function chargerDonnees() {
                // Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
                // Collection code = 'FLORE - VAR' (Cbnmed)
                $queryCbnmed = "SELECT collection_code, locality as id_location, county as location, ".
                                                        "       STR_TO_DATE(concat(ifnull(year,0),'/', ifnull(month,0), '/',ifnull(day,0)), '%Y/%m/%d') as date_observation, ".
                                                        "       latitude as y_utm , longitude as x_utm , max_altitude as sector, collector_name as identifiant ".
                                                        "FROM tb_hit_indexation.raw_occurrence_record ".
                                                        "WHERE scientific_name = ".$this->getBdd()->proteger($this->info['nom']).
                                                        "       AND collection_code='FLORE - VAR' ".
                                                        "       AND  (deleted IS NULL OR deleted = '0000-00-00 00:00:00')";
                $inventoriesCbnmed = $this->getBdd()->recupererTous($queryCbnmed);
        
                return $inventoriesCbnmed;
        }
        

        public function dessinerPoint($text, $merge, $couleurs) {
                $usemap['cbnmed'] = '';
        
                foreach ($text as $coord => $origines ) {
                        foreach ($origines as $origine => $maptext ) {
                                $maptext = preg_replace("/\"/", "\'", $maptext);
                                        
                                list($x,$y) = explode('|', $coord);
        
                                $tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
                                $rayon = 2;
                                $type = 'circle';
                                $coords = "$x,$y,5";
                                $on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
        
                                imagefilledellipse($this->img['cbnmed'], $x, $y, 7, 7, $couleurs['blue']);
                                $usemap['cbnmed'] = $usemap['cbnmed'].sprintf($tpl_area, $type, $coords, $maptext);     
                        }
                }
                return $usemap;
        }
        
        public function formaterCartes($usemap) {
                $retour=  "<img src=\"".(Config::get('Cartes.cel_dst').$this->dest_map['cbnmed'])."\" style=\"border:none; cursor:crosshair\" alt=\"\" usemap=\"#themapcbnmed\"></img><br />\n";
                $retour.=  "<map name=\"themapcbnmed\" id=\"themapcbnmed\">";
                $retour.=  $usemap['cbnmed'];
                $retour.=  "</map>";

                return $retour;
        }
        

        
        
        //+----------------------------------------------------------------------------------------------------------------+
        // sous fonction de calculer répartition
        public function chercherVille($inventory, $tab_code_insee = array()) {
                $location_protege = $this->getBdd()->proteger($inventory['location']);
                $id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
                $utm = '';
                
                if (isset($tab_code_insee[$id_location_protege])) {
                        $utm = array(0 => $tab_code_insee[$id_location_protege]);
                } else {
                        $requete = "SELECT * ".
                                                "FROM tb_cel.locations ".
                                                "WHERE insee_code = $id_location_protege ";
                        $utm = $this->getBdd()->recupererTous($requete);
                }
                return $utm;
        }

        public function formerCommentaire($utm, $inventory) {
                $comment = '';
                        
                if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
                        $comment .= $this->formerDate($inventory);
                }
                        
                $comment .= " par ".utf8_decode($inventory['identifiant']);
                return $comment;
        }
        
        public function formerDate($inventory) {
                list($year, $month, $day) = explode ('-',$inventory['date_observation']);
                list($day) = explode (' ',$day);
                if ($month == '00') {
                        $date = ', en '.$year;
                } else {
                        $date = ', le '.$day.'/'.$month.'/'.$year;
                }
                return $date;
        }
        
        public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
                $prefix = 'CBN MED : ';
                 
                // Deja present  pour cette origine ? on ajoute  
                if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
                        $text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
                } else { // Nouveau commentaire
                        $text[$x.'|'.$y][$origine] = $name.$comment;
                }
                
                
                // Detection superposition de donnee 
                if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['cel']) && ($text[$x.'|'.$y]['cel'])) || 
                        (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))) {
                                $merge[$x.'|'.$y]=true;
                }
                
                return array($text, $merge);
        }
        


}
?>