314 |
delphine |
1 |
<?php
|
|
|
2 |
class SophyFormateur implements Formateur {
|
|
|
3 |
public $dest_map = array();
|
|
|
4 |
public $img = array();
|
|
|
5 |
public function __construct($parametres, $info) {
|
|
|
6 |
$this->param = $parametres;
|
|
|
7 |
$this->info = $info;
|
|
|
8 |
}
|
|
|
9 |
public function img() {
|
|
|
10 |
$qualite = 90;
|
|
|
11 |
imagejpeg($this->img['sophy'], Config::get('cache.stockageChemin').$this->dest_map['sophy'], $qualite);
|
|
|
12 |
}
|
|
|
13 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
14 |
// Méthodes d'accès aux objets du Framework
|
|
|
15 |
/**
|
|
|
16 |
* Méthode de connection à la base de données sur demande.
|
|
|
17 |
* Tous les services web n'ont pas besoin de s'y connecter.
|
|
|
18 |
*/
|
|
|
19 |
protected function getBdd() {
|
|
|
20 |
if (! isset($this->Bdd)) {
|
|
|
21 |
$this->Bdd = new Bdd();
|
|
|
22 |
}
|
|
|
23 |
return $this->Bdd;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function definirCouleurs() {
|
|
|
27 |
// purple
|
|
|
28 |
$couleur['purple'] = imagecolorallocate($this->img['sophy'], 255, 0, 255);
|
|
|
29 |
return $couleur;
|
|
|
30 |
}
|
|
|
31 |
public function initialiserImage() {
|
|
|
32 |
// Nom du fichier image en sortie
|
|
|
33 |
$this->cheminCartesBase = Config::get('Cartes.chemin');
|
|
|
34 |
$this->dest_map['sophy'] = 'sophy_nt'.$this->info['nt'].'_'.$this->info['src_map'];
|
|
|
35 |
$this->img['sophy'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public function chargerDonnees() {
|
|
|
39 |
// Collection code = 'sophy'
|
|
|
40 |
$querySophy = "SELECT 'sophy' as collection_code, lieu_station_nom as location, lieu_commune_code_insee as id_location, ".
|
|
|
41 |
" observation_date as date_observation, lieu_station_utm_est as x_utm , ".
|
|
|
42 |
" lieu_station_utm_nord as y_utm , lieu_station_utm_zone as sector, observateur_nom_complet as identifiant ".
|
|
|
43 |
"FROM sophy_tapir ".
|
|
|
44 |
"WHERE nom_scientifique_complet = ".$this->getBdd()->proteger($this->info['nom_ss_auteur']).
|
|
|
45 |
" AND lieu_commune_code_insee != '' group by `nom_scientifique_complet`,`lieu_commune_code_insee`, `lieu_station_nom`";
|
|
|
46 |
$inventoriesSophy = $this->getBdd()->recupererTous($querySophy);
|
|
|
47 |
return $inventoriesSophy;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
public function dessinerPoint($text, $merge, $couleurs) {
|
|
|
52 |
$usemap['sophy'] = '';
|
|
|
53 |
|
|
|
54 |
foreach ($text as $coord => $origines ) {
|
|
|
55 |
foreach ($origines as $origine => $maptext ) {
|
|
|
56 |
$maptext = preg_replace("/\"/", "\'", $maptext);
|
|
|
57 |
|
|
|
58 |
list($x,$y) = explode('|', $coord);
|
|
|
59 |
|
|
|
60 |
$tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
|
|
|
61 |
$rayon = 2;
|
|
|
62 |
$type = 'circle';
|
|
|
63 |
$coords = "$x,$y,5";
|
|
|
64 |
$on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
imagefilledrectangle($this->img['sophy'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['purple']);
|
|
|
68 |
$coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon);
|
|
|
69 |
$usemap['sophy'] = $usemap['sophy'].sprintf($tpl_area, 'rect', $coords, $maptext);
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
return $usemap;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public function formaterCartes($usemap) {
|
|
|
77 |
$retour= "<img src=\"".(Config::get('Cartes.cel_dst').$this->dest_map['sophy'])."\" style=\"border:none; cursor:crosshair\" alt=\"\" usemap=\"#themapsophy\"></img><br />\n";
|
|
|
78 |
$retour.= "<map name=\"themapsophy\" id=\"themapsophy\">";
|
|
|
79 |
$retour.= $usemap['sophy'];
|
|
|
80 |
$retour.= "</map>";
|
|
|
81 |
return $retour;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
88 |
// sous fonction de calculer répartition
|
|
|
89 |
public function chercherVille($inventory, $tab_code_insee = array()) {
|
|
|
90 |
$utm = '';
|
|
|
91 |
if (strpos($inventory['id_location'], '20') === 0) {
|
|
|
92 |
$a = str_replace('20', '2A', $inventory['id_location']);
|
|
|
93 |
if (isset($tab_code_insee[$a])) {
|
|
|
94 |
$utm = array(0 => $tab_code_insee[$a]);
|
|
|
95 |
} else {
|
|
|
96 |
$b = str_replace('20', '2B', $inventory['id_location']);
|
|
|
97 |
if (isset($tab_code_insee[$b])) {
|
|
|
98 |
$utm = array(0 => $tab_code_insee[$b]);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
} elseif (isset($tab_code_insee[$inventory['id_location']])) {
|
|
|
102 |
$utm = array(0 => $tab_code_insee[$inventory['id_location']]);
|
|
|
103 |
} elseif (strpos($inventory['id_location'], '000') === 2) {
|
|
|
104 |
$code = $this->getBdd()->proteger(str_replace('000', '', $inventory['id_location']));
|
|
|
105 |
$requete = "SELECT chef_lieu ".
|
|
|
106 |
"FROM tb_eflore.insee_d_v2011 ".
|
|
|
107 |
"WHERE dep = $code ";
|
|
|
108 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
109 |
if ($resultat != array() && isset($tab_code_insee[$resultat[0]['chef_lieu']])) {
|
|
|
110 |
$utm = $tab_code_insee[$resultat[0]['chef_lieu']];
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
return $utm;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
public function formerCommentaire($utm, $inventory) {
|
|
|
118 |
$comment = '';
|
|
|
119 |
|
|
|
120 |
if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
|
|
|
121 |
$comment .= $this->formerDate($inventory);
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
$comment .= " par ".utf8_decode($inventory['identifiant']);
|
|
|
125 |
return $comment;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public function formerDate($inventory) {
|
|
|
129 |
$date = ', en '.$inventory['date_observation'];
|
|
|
130 |
return $date;
|
|
|
131 |
}
|
|
|
132 |
/*
|
|
|
133 |
* Stockage commentaire associe a un point :
|
|
|
134 |
*
|
|
|
135 |
* Param :
|
|
|
136 |
* @text : texte cumule
|
|
|
137 |
* @merge : indicateur de commentaire fusionne
|
|
|
138 |
* @name : commune associee
|
|
|
139 |
* @comment : commentaire
|
|
|
140 |
* @origine : origine de la donnee
|
|
|
141 |
*
|
|
|
142 |
*
|
|
|
143 |
* TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
|
|
|
144 |
*/
|
|
|
145 |
public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
|
|
|
146 |
$prefix = 'SOPHY : ';
|
|
|
147 |
// Deja present pour cette origine ? on ajoute
|
|
|
148 |
if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
|
|
|
149 |
$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
|
|
|
150 |
} else { // Nouveau commentaire
|
|
|
151 |
$text[$x.'|'.$y][$origine] = $name.$comment;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
if ((isset ($text[$x.'|'.$y]['cel']) && ($text[$x.'|'.$y]['cel'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore'])||
|
|
|
156 |
(isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR'])))) {
|
|
|
157 |
$merge[$x.'|'.$y]=true;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return array($text, $merge);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
}
|
|
|
166 |
?>
|