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