314 |
delphine |
1 |
<?php
|
|
|
2 |
class CelFormateur implements Formateur {
|
|
|
3 |
public $dest_map = array();
|
|
|
4 |
public $img = array();
|
315 |
delphine |
5 |
public function __construct($info) {
|
314 |
delphine |
6 |
$this->info = $info;
|
|
|
7 |
}
|
|
|
8 |
public function img() {
|
320 |
aurelien |
9 |
$qualite = 9;
|
795 |
raphael |
10 |
imagepng($this->img['cel'], Config::get('cache_stockageChemin').$this->dest_map['cel'], $qualite);
|
314 |
delphine |
11 |
}
|
|
|
12 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
13 |
// Méthodes d'accès aux objets du Framework
|
|
|
14 |
/**
|
|
|
15 |
* Méthode de connection à la base de données sur demande.
|
|
|
16 |
* Tous les services web n'ont pas besoin de s'y connecter.
|
|
|
17 |
*/
|
|
|
18 |
protected function getBdd() {
|
|
|
19 |
if (! isset($this->Bdd)) {
|
|
|
20 |
$this->Bdd = new Bdd();
|
|
|
21 |
}
|
|
|
22 |
return $this->Bdd;
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function definirCouleurs() {
|
|
|
26 |
// green
|
|
|
27 |
$couleurs['green'] = imagecolorallocate($this->img['cel'], 0, 255, 0);
|
|
|
28 |
return $couleurs;
|
|
|
29 |
}
|
|
|
30 |
public function initialiserImage() {
|
|
|
31 |
// Nom du fichier image en sortie
|
|
|
32 |
$this->cheminCartesBase = Config::get('Cartes.chemin');
|
|
|
33 |
$this->dest_map['cel'] = 'cel_nt'.$this->info['nt'].'_'.$this->info['src_map'];
|
320 |
aurelien |
34 |
$this->img['cel'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
|
314 |
delphine |
35 |
}
|
|
|
36 |
|
362 |
delphine |
37 |
public function testerParametresProjets() {
|
|
|
38 |
$test = true;
|
|
|
39 |
if ($this->info['nt'] == 0) {
|
|
|
40 |
$test = false;
|
|
|
41 |
}
|
|
|
42 |
return $test;
|
|
|
43 |
}
|
|
|
44 |
|
314 |
delphine |
45 |
public function chargerDonnees() {
|
|
|
46 |
// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
|
|
|
47 |
|
|
|
48 |
// R�cuperation donn�e inventaire
|
|
|
49 |
/*
|
|
|
50 |
* Les donnees issues du carnet en ligne sont recuperes directement, sans passer par le mecanisme de moissonage car :
|
|
|
51 |
* - pour l'instant le service de moissonage n'est pas automatise et donc il y a un decalage dans l'affichage des donnees transmises
|
|
|
52 |
* - 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)
|
|
|
53 |
*
|
|
|
54 |
* A terme, utilser vraiment le moissonage, y compris pour les donnees issues du CEL, en utilisant ABCD et en modifiant le programme d'harvesting.
|
|
|
55 |
*/
|
541 |
aurelien |
56 |
$queryCel = "SELECT 'cel' as collection_code, zone_geo as location, REPLACE(ce_zone_geo,'INSEE-C:','') as id_location, date_observation, ".
|
|
|
57 |
" longitude as y_utm, latitude as x_utm, geodatum as sector, courriel_utilisateur as identifiant FROM tb_cel.cel_obs ".
|
|
|
58 |
"WHERE nt = '".$this->info['nt']."' ".
|
314 |
delphine |
59 |
" AND transmission = 1";
|
|
|
60 |
$inventoriesCel = $this->getBdd()->recupererTous($queryCel);
|
|
|
61 |
return $inventoriesCel;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public function dessinerPoint($text, $merge, $couleurs) {
|
|
|
66 |
$usemap['cel'] = '';
|
|
|
67 |
|
|
|
68 |
foreach ($text as $coord => $origines ) {
|
|
|
69 |
foreach ($origines as $origine => $maptext ) {
|
|
|
70 |
$maptext = preg_replace("/\"/", "\'", $maptext);
|
|
|
71 |
|
|
|
72 |
list($x,$y) = explode('|', $coord);
|
|
|
73 |
|
|
|
74 |
$tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
|
|
|
75 |
$rayon = 2;
|
|
|
76 |
$type = 'circle';
|
|
|
77 |
$coords = "$x,$y,5";
|
|
|
78 |
$on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
|
|
|
79 |
|
|
|
80 |
imagefilledrectangle($this->img['cel'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['green']);
|
|
|
81 |
$coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon);
|
|
|
82 |
$usemap['cel'] = $usemap['cel'].sprintf($tpl_area, 'rect', $coords, $maptext);
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
return $usemap;
|
|
|
86 |
}
|
|
|
87 |
|
315 |
delphine |
88 |
public function formaterCartes($usemap) {
|
|
|
89 |
$retour = Config::get('Cartes.cel_dst').$this->dest_map['cel'];
|
|
|
90 |
if ($this->info['retour'] == self::MIME_MAP) {
|
|
|
91 |
$retour = "<img src=\"".$retour."\" style=\"border:none; ".
|
|
|
92 |
"cursor:crosshair\" alt=\"\" usemap=\"#themap\" /><br />\n".
|
|
|
93 |
"<map name=\"themap\" id=\"themap\">".utf8_encode($usemap['cel'])."</map>";
|
|
|
94 |
}
|
314 |
delphine |
95 |
return $retour;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
102 |
// sous fonction de calculer répartition
|
|
|
103 |
public function chercherVille($inventory, $tab_code_insee = array()) {
|
|
|
104 |
$location_protege = $this->getBdd()->proteger($inventory['location']);
|
|
|
105 |
$id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
|
|
|
106 |
$utm = array();
|
|
|
107 |
if ($inventory['id_location'] != 'null') {
|
|
|
108 |
if (isset($tab_code_insee) & in_array($inventory['id_location'], $tab_code_insee)) {
|
|
|
109 |
$utm = array(0 => $this->tab_code_insee[$id_location_protege]);
|
|
|
110 |
} else {
|
542 |
delphine |
111 |
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector ".
|
|
|
112 |
"FROM cel.cel_zones_geo ".
|
541 |
aurelien |
113 |
"WHERE nom LIKE $location_protege ".
|
314 |
delphine |
114 |
" AND code = $id_location_protege ";
|
|
|
115 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
116 |
$utm = $resultat;
|
|
|
117 |
}
|
|
|
118 |
} else {
|
542 |
delphine |
119 |
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector".
|
|
|
120 |
" FROM tb_cel.cel_zones_geo WHERE nom LIKE $location_protege ";
|
314 |
delphine |
121 |
$utm = $this->getBdd()->recupererTous($requete);
|
|
|
122 |
}
|
|
|
123 |
return $utm;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public function formerCommentaire($utm, $inventory) {
|
|
|
127 |
$comment = '';
|
|
|
128 |
|
|
|
129 |
if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
|
|
|
130 |
$comment .= $this->formerDate($inventory);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
list($identifiant) = explode("@", $inventory['identifiant']);
|
|
|
134 |
$comment .= " par ".$identifiant."@...";
|
|
|
135 |
|
|
|
136 |
return $comment;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public function formerDate($inventory) {
|
|
|
140 |
list($year, $month, $day) = explode ('-',$inventory['date_observation']);
|
|
|
141 |
list($day) = explode (' ',$day);
|
|
|
142 |
if ($month == '00') {
|
|
|
143 |
$date = ', en '.$year;
|
|
|
144 |
} else {
|
|
|
145 |
$date = ', le '.$day.'/'.$month.'/'.$year;
|
|
|
146 |
}
|
|
|
147 |
return $date;
|
|
|
148 |
}
|
|
|
149 |
/*
|
|
|
150 |
* Stockage commentaire associe a un point :
|
|
|
151 |
*
|
|
|
152 |
* Param :
|
|
|
153 |
* @text : texte cumule
|
|
|
154 |
* @merge : indicateur de commentaire fusionne
|
|
|
155 |
* @name : commune associee
|
|
|
156 |
* @comment : commentaire
|
|
|
157 |
* @origine : origine de la donnee
|
|
|
158 |
*
|
|
|
159 |
*
|
|
|
160 |
* TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
|
|
|
161 |
*/
|
|
|
162 |
public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
|
|
|
163 |
$prefix = 'CEL : ';
|
|
|
164 |
|
|
|
165 |
// Cumul toute origine :
|
|
|
166 |
if (isset($text[$x.'|'.$y]['tout']) && ($text[$x.'|'.$y])) {
|
|
|
167 |
$text[$x.'|'.$y]['tout'] = $text[$x.'|'.$y]['tout'].'<br>'.$prefix.$name.$comment;
|
|
|
168 |
} else {
|
|
|
169 |
// Nouveau commentaire
|
|
|
170 |
$text[$x.'|'.$y]['tout']=$prefix.$name.$comment;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
// Deja present pour cette origine ? on ajoute
|
|
|
174 |
if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
|
|
|
175 |
$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
|
|
|
176 |
} else { // Nouveau commentaire
|
|
|
177 |
$text[$x.'|'.$y][$origine] = $name.$comment;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
// Detection superposition de donnee
|
|
|
182 |
if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))
|
|
|
183 |
|| (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) {
|
|
|
184 |
$merge[$x.'|'.$y]=true;
|
|
|
185 |
}
|
|
|
186 |
return array($text, $merge);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
}
|
|
|
192 |
?>
|