Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
314 delphine 1
<?php
2
class CelFormateur 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['cel'], Config::get('cache.stockageChemin').$this->dest_map['cel'], $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
		// green
28
		$couleurs['green'] = imagecolorallocate($this->img['cel'], 0, 255, 0);
29
		return $couleurs;
30
	}
31
	public function initialiserImage() {
32
		// Nom du fichier image en sortie
33
		$this->cheminCartesBase = Config::get('Cartes.chemin');
34
		$this->dest_map['cel'] = 'cel_nt'.$this->info['nt'].'_'.$this->info['src_map'];
35
		$this->img['cel'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
36
	}
37
 
38
	public function chargerDonnees() {
39
		// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
40
 
41
		// R�cuperation donn�e inventaire
42
		/*
43
		* Les donnees issues du carnet en ligne sont recuperes directement, sans passer par le mecanisme de moissonage car :
44
		*   - pour l'instant le service de moissonage n'est pas automatise et donc il y a un decalage dans l'affichage des donnees transmises
45
		*   - la table contenant les donnees moissonees ne reprend pas tous les champs necessaires a l'exploitation par eflore (notamment pas de code localite, pas d'identifiant libre)
46
		*
47
		* A terme, utilser vraiment le moissonage, y compris pour les donnees issues du CEL, en utilisant ABCD et en modifiant le programme d'harvesting.
48
		*/
49
		$queryCel = "SELECT 'cel' as collection_code,  location, id_location, date_observation,  ".
50
		"	coord_y as y_utm, coord_x as x_utm, ref_geo as sector, identifiant FROM tb_cel.cel_inventory ".
51
							"WHERE num_taxon = '".$this->info['nt']."' ".
52
							"	AND transmission = 1";
53
		$inventoriesCel = $this->getBdd()->recupererTous($queryCel);
54
		return $inventoriesCel;
55
	}
56
 
57
 
58
	public function dessinerPoint($text, $merge, $couleurs) {
59
		$usemap['cel'] = '';
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
				imagefilledrectangle($this->img['cel'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['green']);
74
				$coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon);
75
				$usemap['cel'] = $usemap['cel'].sprintf($tpl_area, 'rect', $coords, $maptext);
76
			}
77
		}
78
		return $usemap;
79
	}
80
 
81
	public function formaterCartes($usemap) {
82
		$retour=  "<img src=\"".(Config::get('Cartes.cel_dst').$this->dest_map['cel'])."\" style=\"border:none; cursor:crosshair\" alt=\"\" usemap=\"#themapcel\"></img><br />\n";
83
		$retour.=  "<map name=\"themapcel\" id=\"themapcel\">";
84
		$retour.=  $usemap['cel'];
85
		$retour.=  "</map>";
86
 
87
		return $retour;
88
	}
89
 
90
 
91
 
92
 
93
	//+----------------------------------------------------------------------------------------------------------------+
94
	// sous fonction de calculer répartition
95
	public function chercherVille($inventory, $tab_code_insee = array()) {
96
		$location_protege = $this->getBdd()->proteger($inventory['location']);
97
		$id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
98
		$utm = array();
99
			if ($inventory['id_location'] != 'null') {
100
				if (isset($tab_code_insee) & in_array($inventory['id_location'], $tab_code_insee)) {
101
					$utm = array(0 => $this->tab_code_insee[$id_location_protege]);
102
				} else {
103
					$requete = "SELECT * ".
104
										"FROM tb_cel.locations ".
105
										"WHERE name LIKE $location_protege ".
106
										"	AND code = $id_location_protege ";
107
					$resultat = $this->getBdd()->recupererTous($requete);
108
					$utm = $resultat;
109
				}
110
			} else {
111
				$requete = "SELECT * FROM tb_cel.locations WHERE name LIKE $location_protege ";
112
				$utm = $this->getBdd()->recupererTous($requete);
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
		list($identifiant) = explode("@", $inventory['identifiant']);
125
		$comment .= " par ".$identifiant."@...";
126
 
127
		return $comment;
128
	}
129
 
130
	public function formerDate($inventory) {
131
			list($year, $month, $day) = explode ('-',$inventory['date_observation']);
132
			list($day) = explode (' ',$day);
133
			if ($month == '00') {
134
				$date = ', en '.$year;
135
			} else {
136
				$date = ', le '.$day.'/'.$month.'/'.$year;
137
			}
138
		return $date;
139
	}
140
	/*
141
	 * Stockage commentaire associe a un point :
142
	 *
143
	 * Param :
144
	 * @text : texte cumule
145
	 * @merge : indicateur de commentaire fusionne
146
	 * @name : commune associee
147
	 * @comment : commentaire
148
	 * @origine : origine de la donnee
149
	 *
150
	 *
151
	 * TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
152
	 */
153
	public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
154
		$prefix = 'CEL : ';
155
 
156
		// Cumul toute origine :
157
		if (isset($text[$x.'|'.$y]['tout']) && ($text[$x.'|'.$y])) {
158
			$text[$x.'|'.$y]['tout'] = $text[$x.'|'.$y]['tout'].'<br>'.$prefix.$name.$comment;
159
		} else {
160
			// Nouveau commentaire
161
			$text[$x.'|'.$y]['tout']=$prefix.$name.$comment;
162
		}
163
 
164
		// Deja present  pour cette origine ? on ajoute
165
		if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
166
			$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
167
		} else { // Nouveau commentaire
168
			$text[$x.'|'.$y][$origine] = $name.$comment;
169
		}
170
 
171
 
172
		// Detection superposition de donnee
173
		if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))
174
			|| (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) {
175
				$merge[$x.'|'.$y]=true;
176
		}
177
		return array($text, $merge);
178
	}
179
 
180
 
181
 
182
}
183
?>