Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 314 | Rev 320 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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