New file |
0,0 → 1,192 |
<?php |
class CelFormateur implements Formateur { |
public $dest_map = array(); |
public $img = array(); |
public function __construct($info) { |
$this->info = $info; |
} |
public function img() { |
$qualite = 9; |
imagepng($this->img['cel'], Config::get('cache_stockageChemin').$this->dest_map['cel'], $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 |
$couleurs['green'] = imagecolorallocate($this->img['cel'], 0, 255, 0); |
return $couleurs; |
} |
public function initialiserImage() { |
// Nom du fichier image en sortie |
$this->cheminCartesBase = Config::get('Cartes.chemin'); |
$this->dest_map['cel'] = 'cel_nt'.$this->info['nt'].'_'.$this->info['src_map']; |
$this->img['cel'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']); |
} |
|
public function testerParametresProjets() { |
$test = true; |
if ($this->info['nt'] == 0) { |
$test = false; |
} |
return $test; |
} |
|
public function chargerDonnees() { |
// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes). |
|
// R�cuperation donn�e inventaire |
/* |
* Les donnees issues du carnet en ligne sont recuperes directement, sans passer par le mecanisme de moissonage car : |
* - pour l'instant le service de moissonage n'est pas automatise et donc il y a un decalage dans l'affichage des donnees transmises |
* - la table contenant les donnees moissonees ne reprend pas tous les champs necessaires a l'exploitation par eflore (notamment pas de code localite, pas d'identifiant libre) |
* |
* A terme, utilser vraiment le moissonage, y compris pour les donnees issues du CEL, en utilisant ABCD et en modifiant le programme d'harvesting. |
*/ |
$queryCel = "SELECT 'cel' as collection_code, zone_geo as location, REPLACE(ce_zone_geo,'INSEE-C:','') as id_location, date_observation, ". |
" longitude as y_utm, latitude as x_utm, geodatum as sector, courriel_utilisateur as identifiant FROM tb_cel.cel_obs ". |
"WHERE nt = '".$this->info['nt']."' ". |
" AND transmission = 1"; |
$inventoriesCel = $this->getBdd()->recupererTous($queryCel); |
return $inventoriesCel; |
} |
|
|
public function dessinerPoint($text, $merge, $couleurs) { |
$usemap['cel'] = ''; |
|
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['cel'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['green']); |
$coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon); |
$usemap['cel'] = $usemap['cel'].sprintf($tpl_area, 'rect', $coords, $maptext); |
} |
} |
return $usemap; |
} |
|
public function formaterCartes($usemap) { |
$retour = Config::get('Cartes.cel_dst').$this->dest_map['cel']; |
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['cel'])."</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 = array(); |
if ($inventory['id_location'] != 'null') { |
if (isset($tab_code_insee) & in_array($inventory['id_location'], $tab_code_insee)) { |
$utm = array(0 => $this->tab_code_insee[$id_location_protege]); |
} else { |
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector ". |
"FROM cel.cel_zones_geo ". |
"WHERE nom LIKE $location_protege ". |
" AND code = $id_location_protege "; |
$resultat = $this->getBdd()->recupererTous($requete); |
$utm = $resultat; |
} |
} else { |
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector". |
" FROM tb_cel.cel_zones_geo WHERE nom LIKE $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); |
} |
|
list($identifiant) = explode("@", $inventory['identifiant']); |
$comment .= " par ".$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; |
} |
/* |
* 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 = 'CEL : '; |
|
// Cumul toute origine : |
if (isset($text[$x.'|'.$y]['tout']) && ($text[$x.'|'.$y])) { |
$text[$x.'|'.$y]['tout'] = $text[$x.'|'.$y]['tout'].'<br>'.$prefix.$name.$comment; |
} else { |
// Nouveau commentaire |
$text[$x.'|'.$y]['tout']=$prefix.$name.$comment; |
} |
|
// 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]['flore']) && ($text[$x.'|'.$y]['flore'])) |
|| (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) { |
$merge[$x.'|'.$y]=true; |
} |
return array($text, $merge); |
} |
|
|
|
} |
?> |