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