Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
class CenlrFormateur implements Formateur {
        public $dest_map = array();
        public $img = array();
        public function __construct($info) {
                $this->info = $info;
        }
        public function img() {
                $qualite = 9;
                imagepng($this->img['cenlr'], Config::get('cache.stockageChemin').$this->dest_map['cenlr'], $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['cenlr'], 0, 255, 0);
        // red
        $couleur['red'] = imagecolorallocate($this->img['cenlr'], 255, 0, 0);
        // blue
        $couleur['blue'] = imagecolorallocate($this->img['cenlr'], 0, 0, 255);
        // purple
        $couleur['purple'] = imagecolorallocate($this->img['cenlr'], 255, 0, 255);
        // black
        $couleur['black'] = imagecolorallocate($this->img['cenlr'], 0, 0, 0);
        return $couleur;
        }
        public function initialiserImage() {
                // Nom du fichier image en sortie
                $this->cheminCartesBase = Config::get('Cartes.chemin');
                $this->dest_map['cenlr'] = 'cenlr_nt'.$this->info['nt'].'_'.$this->info['src_map'];
                $this->img['cenlr'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
        }
        
        public function testerParametresProjets() {
                $test = true;
                if ($this->info['nom'] == '') {
                        $test = false;
                }
                return $test;
        }
        
        public function chargerDonnees() {
                // Collection code = 'flore' (Cenlr)
                $queryCenlr = "SELECT collection_code, locality as location, county as id_location, ".
                                                        "       STR_TO_DATE(concat(year, '/',month, '/',day), '%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' ".
                                                        "       AND (deleted IS NULL OR deleted = '0000-00-00 00:00:00')";
                $inventoriesCenlr = $this->getBdd()->recupererTous($queryCenlr);
                return $inventoriesCenlr;
        }
        

        public function dessinerPoint($text, $merge, $couleurs) {
                $usemap['cenlr'] = '';
        
                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['cenlr'], $x, $y, 7, 7, $couleurs['red']);
                                $usemap['cenlr'] = $usemap['cenlr'].sprintf($tpl_area, $type, $coords, $maptext);
                        }
                }
                return $usemap;
        }
        
        public function formaterCartes($usemap) {
                $retour = Config::get('Cartes.cel_dst').$this->dest_map['cenlr'];
                if ($this->info['retour'] == self::MIME_MAP) {
                        $retour =  "<img src=\"".$retour."\" style=\"border:none; ".
                                        "cursor:crosshair\" alt=\"\" usemap=\"#themap\" /><br />\n".
                                        "<map name=\"themap\" id=\"themap\">".utf8_encode($usemap['cenlr'])."</map>";
                }
                return $retour;
        }
        
        //+----------------------------------------------------------------------------------------------------------------+
        // sous fonction de calculer répartition
        public function chercherVille($inventory, $tab_code_insee = array()) {
                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 = 'CEN LR : ';
                
                // 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 - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) {
                                $merge[$x.'|'.$y]=true;
                }
                
                return array($text, $merge);
        }
        


}
?>