Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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