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;
|
|
|
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 |
*/
|
|
|
56 |
$queryCel = "SELECT 'cel' as collection_code, location, id_location, date_observation, ".
|
|
|
57 |
" coord_y as y_utm, coord_x as x_utm, ref_geo as sector, identifiant FROM tb_cel.cel_inventory ".
|
|
|
58 |
"WHERE num_taxon = '".$this->info['nt']."' ".
|
|
|
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 {
|
|
|
111 |
$requete = "SELECT * ".
|
|
|
112 |
"FROM tb_cel.locations ".
|
|
|
113 |
"WHERE name LIKE $location_protege ".
|
|
|
114 |
" AND code = $id_location_protege ";
|
|
|
115 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
116 |
$utm = $resultat;
|
|
|
117 |
}
|
|
|
118 |
} else {
|
|
|
119 |
$requete = "SELECT * FROM tb_cel.locations WHERE name LIKE $location_protege ";
|
|
|
120 |
$utm = $this->getBdd()->recupererTous($requete);
|
|
|
121 |
}
|
|
|
122 |
return $utm;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public function formerCommentaire($utm, $inventory) {
|
|
|
126 |
$comment = '';
|
|
|
127 |
|
|
|
128 |
if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
|
|
|
129 |
$comment .= $this->formerDate($inventory);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
list($identifiant) = explode("@", $inventory['identifiant']);
|
|
|
133 |
$comment .= " par ".$identifiant."@...";
|
|
|
134 |
|
|
|
135 |
return $comment;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public function formerDate($inventory) {
|
|
|
139 |
list($year, $month, $day) = explode ('-',$inventory['date_observation']);
|
|
|
140 |
list($day) = explode (' ',$day);
|
|
|
141 |
if ($month == '00') {
|
|
|
142 |
$date = ', en '.$year;
|
|
|
143 |
} else {
|
|
|
144 |
$date = ', le '.$day.'/'.$month.'/'.$year;
|
|
|
145 |
}
|
|
|
146 |
return $date;
|
|
|
147 |
}
|
|
|
148 |
/*
|
|
|
149 |
* Stockage commentaire associe a un point :
|
|
|
150 |
*
|
|
|
151 |
* Param :
|
|
|
152 |
* @text : texte cumule
|
|
|
153 |
* @merge : indicateur de commentaire fusionne
|
|
|
154 |
* @name : commune associee
|
|
|
155 |
* @comment : commentaire
|
|
|
156 |
* @origine : origine de la donnee
|
|
|
157 |
*
|
|
|
158 |
*
|
|
|
159 |
* TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
|
|
|
160 |
*/
|
|
|
161 |
public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
|
|
|
162 |
$prefix = 'CEL : ';
|
|
|
163 |
|
|
|
164 |
// Cumul toute origine :
|
|
|
165 |
if (isset($text[$x.'|'.$y]['tout']) && ($text[$x.'|'.$y])) {
|
|
|
166 |
$text[$x.'|'.$y]['tout'] = $text[$x.'|'.$y]['tout'].'<br>'.$prefix.$name.$comment;
|
|
|
167 |
} else {
|
|
|
168 |
// Nouveau commentaire
|
|
|
169 |
$text[$x.'|'.$y]['tout']=$prefix.$name.$comment;
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
// Deja present pour cette origine ? on ajoute
|
|
|
173 |
if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
|
|
|
174 |
$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
|
|
|
175 |
} else { // Nouveau commentaire
|
|
|
176 |
$text[$x.'|'.$y][$origine] = $name.$comment;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
// Detection superposition de donnee
|
|
|
181 |
if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))
|
|
|
182 |
|| (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) {
|
|
|
183 |
$merge[$x.'|'.$y]=true;
|
|
|
184 |
}
|
|
|
185 |
return array($text, $merge);
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
}
|
|
|
191 |
?>
|