Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
class SophyFormateur implements Formateur {
        public $dest_map = array();
        public $img = array();
        public function __construct($info) {
                $this->info = $info;
        }
        public function img() {
                $qualite = 90;
                imagejpeg($this->img['sophy'], Config::get('cache.stockageChemin').$this->dest_map['sophy'], $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() {
                // purple
                $couleur['purple'] = imagecolorallocate($this->img['sophy'], 255, 0, 255);
                return $couleur;
        }
        public function initialiserImage() {
                // Nom du fichier image en sortie
                $this->cheminCartesBase = Config::get('Cartes.chemin');
                $this->dest_map['sophy'] = 'sophy_nt'.$this->info['nt'].'_'.$this->info['src_map'];
                $this->img['sophy'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
        }
        
        public function chargerDonnees() {
                // Collection code = 'sophy'
                $querySophy = "SELECT 'sophy' as collection_code, lieu_station_nom as location, lieu_commune_code_insee as id_location, ".
                                                                "       observation_date as date_observation, lieu_station_utm_est as x_utm , ". 
                                                        "       lieu_station_utm_nord as y_utm , lieu_station_utm_zone as sector,  observateur_nom_complet as identifiant ".
                                                                "FROM sophy_tapir ".
                                                                "WHERE nom_scientifique_complet = ".$this->getBdd()->proteger($this->info['nom_ss_auteur']).
                                                                        " AND lieu_commune_code_insee != '' group by `nom_scientifique_complet`,`lieu_commune_code_insee`, `lieu_station_nom`";
                $inventoriesSophy = $this->getBdd()->recupererTous($querySophy);
                return $inventoriesSophy;
        }
        

        public function dessinerPoint($text, $merge, $couleurs) {
                $usemap['sophy'] = '';
        
                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')";
        
                                
                                                imagefilledrectangle($this->img['sophy'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['purple']);
                                                $coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon);
                                                $usemap['sophy'] = $usemap['sophy'].sprintf($tpl_area, 'rect', $coords, $maptext);
                                                
                        }
                }
                return $usemap;
        }
        
        public function formaterCartes($usemap) {
                $retour = Config::get('Cartes.cel_dst').$this->dest_map['sophy'];
                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['sophy'])."</map>";
                }
                return $retour;
        }
        

        
        
        //+----------------------------------------------------------------------------------------------------------------+
        // sous fonction de calculer répartition
        public function chercherVille($inventory, $tab_code_insee = array()) {
                $utm = '';
                if (strpos($inventory['id_location'], '20') === 0) {
                        $a = str_replace('20', '2A', $inventory['id_location']);
                        if (isset($tab_code_insee[$a])) {
                                $utm = array(0 => $tab_code_insee[$a]);
                        } else {
                                $b = str_replace('20', '2B', $inventory['id_location']);
                                if (isset($tab_code_insee[$b])) {
                                        $utm = array(0 => $tab_code_insee[$b]);
                                }
                        }
                } elseif (isset($tab_code_insee[$inventory['id_location']])) {
                        $utm = array(0 => $tab_code_insee[$inventory['id_location']]);
                } elseif (strpos($inventory['id_location'], '000') === 2) {
                        $code = $this->getBdd()->proteger(str_replace('000', '', $inventory['id_location']));
                        $requete = "SELECT chef_lieu ".
                                                "FROM tb_eflore.insee_d_v2011 ".
                                                "WHERE dep = $code ";
                        $resultat = $this->getBdd()->recupererTous($requete);
                        if ($resultat != array() && isset($tab_code_insee[$resultat[0]['chef_lieu']])) {
                                $utm = $tab_code_insee[$resultat[0]['chef_lieu']];
                        }
                }
                
                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) {
                $date = ', en '.$inventory['date_observation'];
                return $date;
        }
        /*
         * Stockage commentaire associe a un point :
         * 
         * Param : 
         * @text : texte cumule
         * @merge : indicateur de commentaire fusionne
         * @name : commune associee
         * @comment : commentaire
         * @origine : origine de la donnee
         * 
         * 
         * TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
         */
        public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
                $prefix = 'SOPHY : ';
                // 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;
                }
                
                if ((isset ($text[$x.'|'.$y]['cel']) && ($text[$x.'|'.$y]['cel'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore'])|| 
                        (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR'])))) {
                                $merge[$x.'|'.$y] = true;
                }
                return array($text, $merge);
        }
        


}
?>