Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 795 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 795 Rev 1300
1
<?php
1
<?php
2
class CbnmedFormateur implements Formateur {
2
class CbnmedFormateur 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['cbnmed'], Config::get('cache_stockageChemin').$this->dest_map['cbnmed'], $qualite);
10
		imagepng($this->img['cbnmed'], Config::get('cache_stockageChemin').$this->dest_map['cbnmed'], $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
	// green
26
	// green
27
	$couleur['green'] = imagecolorallocate($this->img['cbnmed'], 0, 255, 0);
27
	$couleur['green'] = imagecolorallocate($this->img['cbnmed'], 0, 255, 0);
28
	// red
28
	// red
29
	$couleur['red'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 0);
29
	$couleur['red'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 0);
30
	// blue
30
	// blue
31
	$couleur['blue'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 255);
31
	$couleur['blue'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 255);
32
	// purple
32
	// purple
33
	$couleur['purple'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 255);
33
	$couleur['purple'] = imagecolorallocate($this->img['cbnmed'], 255, 0, 255);
34
	// black
34
	// black
35
	$couleur['black'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 0);
35
	$couleur['black'] = imagecolorallocate($this->img['cbnmed'], 0, 0, 0);
36
	return $couleur;
36
	return $couleur;
37
	}
37
	}
38
	public function initialiserImage() {
38
	public function initialiserImage() {
39
		// Nom du fichier image en sortie
39
		// Nom du fichier image en sortie
40
		$this->cheminCartesBase = Config::get('Cartes.chemin');
40
		$this->cheminCartesBase = Config::get('Cartes.chemin');
41
		$this->dest_map['cbnmed'] = 'cbnmed_nt'.$this->info['nt'].'_'.$this->info['src_map'];
41
		$this->dest_map['cbnmed'] = 'cbnmed_nt'.$this->info['nt'].'_'.$this->info['src_map'];
42
		$this->img['cbnmed'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
42
		$this->img['cbnmed'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
43
	}
43
	}
44
	
44
	
45
	public function testerParametresProjets() {
45
	public function testerParametresProjets() {
46
		$test = true;
46
		$test = true;
47
		if ($this->info['nom'] == '') {
47
		if ($this->info['nom'] == '') {
48
			$test = false;
48
			$test = false;
49
		}
49
		}
50
		return $test;
50
		return $test;
51
	}
51
	}
52
	
52
	
53
	public function chargerDonnees() {
53
	public function chargerDonnees() {
54
		// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
54
		// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
55
		// Collection code = 'FLORE - VAR' (Cbnmed)
55
		// Collection code = 'FLORE - VAR' (Cbnmed)
56
		$queryCbnmed = "SELECT collection_code, locality as id_location, county as location, ".
56
		$queryCbnmed = "SELECT collection_code, locality as id_location, county as location, ".
57
							"	STR_TO_DATE(concat(ifnull(year,0),'/', ifnull(month,0), '/',ifnull(day,0)), '%Y/%m/%d') as date_observation, ".
57
							"	STR_TO_DATE(concat(ifnull(year,0),'/', ifnull(month,0), '/',ifnull(day,0)), '%Y/%m/%d') as date_observation, ".
58
							"	latitude as y_utm , longitude as x_utm , max_altitude as sector, collector_name as identifiant ".
58
							"	latitude as y_utm , longitude as x_utm , max_altitude as sector, collector_name as identifiant ".
59
							"FROM tb_hit_indexation.raw_occurrence_record ".
59
							"FROM tb_hit_indexation.raw_occurrence_record ".
60
							"WHERE scientific_name = ".$this->getBdd()->proteger($this->info['nom']).
60
							"WHERE scientific_name = ".$this->getBdd()->proteger($this->info['nom']).
61
							"	AND collection_code='FLORE - VAR' ".
61
							"	AND collection_code='FLORE - VAR' ".
62
							"	AND  (deleted IS NULL OR deleted = '0000-00-00 00:00:00')";
62
							"	AND  (deleted IS NULL OR deleted = '0000-00-00 00:00:00')";
63
		$inventoriesCbnmed = $this->getBdd()->recupererTous($queryCbnmed);
63
		$inventoriesCbnmed = $this->getBdd()->recupererTous($queryCbnmed);
64
	
64
	
65
		return $inventoriesCbnmed;
65
		return $inventoriesCbnmed;
66
	}
66
	}
67
	
67
	
68
 
68
 
69
	public function dessinerPoint($text, $merge, $couleurs) {
69
	public function dessinerPoint($text, $merge, $couleurs) {
70
		$usemap['cbnmed'] = '';
70
		$usemap['cbnmed'] = '';
71
	
71
	
72
		foreach ($text as $coord => $origines ) {
72
		foreach ($text as $coord => $origines ) {
73
			foreach ($origines as $origine => $maptext ) {
73
			foreach ($origines as $origine => $maptext ) {
74
				$maptext = preg_replace("/\"/", "\'", $maptext);
74
				$maptext = preg_replace("/\"/", "\'", $maptext);
75
					
75
					
76
				list($x,$y) = explode('|', $coord);
76
				list($x,$y) = explode('|', $coord);
77
	
77
	
78
				$tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
78
				$tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
79
				$rayon = 2;
79
				$rayon = 2;
80
				$type = 'circle';
80
				$type = 'circle';
81
				$coords = "$x,$y,5";
81
				$coords = "$x,$y,5";
82
				$on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
82
				$on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
83
	
83
	
84
				imagefilledellipse($this->img['cbnmed'], $x, $y, 7, 7, $couleurs['blue']);
84
				imagefilledellipse($this->img['cbnmed'], $x, $y, 7, 7, $couleurs['blue']);
85
				$usemap['cbnmed'] = $usemap['cbnmed'].sprintf($tpl_area, $type, $coords, $maptext);	
85
				$usemap['cbnmed'] = $usemap['cbnmed'].sprintf($tpl_area, $type, $coords, $maptext);	
86
			}
86
			}
87
		}
87
		}
88
		return $usemap;
88
		return $usemap;
89
	}
89
	}
90
	
90
	
91
	public function formaterCartes($usemap) {
91
	public function formaterCartes($usemap) {
92
		$retour = Config::get('Cartes.cel_dst').$this->dest_map['cbnmed'];
92
		$retour = Config::get('Cartes.cel_dst').$this->dest_map['cbnmed'];
93
		if ($this->info['retour'] == self::MIME_MAP) {
93
		if ($this->info['retour'] == self::MIME_MAP) {
94
			$retour =  "<img src=\"".$retour."\" style=\"border:none; ".
94
			$retour =  "<img src=\"".$retour."\" style=\"border:none; ".
95
					"cursor:crosshair\" alt=\"\" usemap=\"#themap\" /><br />\n".
95
					"cursor:crosshair\" alt=\"\" usemap=\"#themap\" /><br />\n".
96
					"<map name=\"themap\" id=\"themap\">".utf8_encode($usemap['cbnmed'])."</map>";
96
					"<map name=\"themap\" id=\"themap\">".utf8_encode($usemap['cbnmed'])."</map>";
97
		}
97
		}
98
		return $retour;
98
		return $retour;
99
	}
99
	}
100
	
100
	
101
 
101
 
102
	
102
	
103
	
103
	
104
	//+----------------------------------------------------------------------------------------------------------------+
104
	//+----------------------------------------------------------------------------------------------------------------+
105
	// sous fonction de calculer répartition
105
	// sous fonction de calculer répartition
106
	public function chercherVille($inventory, $tab_code_insee = array()) {
106
	public function chercherVille($inventory, $tab_code_insee = array()) {
107
		$location_protege = $this->getBdd()->proteger($inventory['location']);
107
		$location_protege = $this->getBdd()->proteger($inventory['location']);
108
		$id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
108
		$id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
109
		$utm = '';
109
		$utm = '';
110
		
110
		
111
		if (isset($tab_code_insee[$id_location_protege])) {
111
		if (isset($tab_code_insee[$id_location_protege])) {
112
			$utm = array(0 => $tab_code_insee[$id_location_protege]);
112
			$utm = array(0 => $tab_code_insee[$id_location_protege]);
113
		} else {
113
		} else {
114
			$requete = "SELECT * ".
114
			$requete = "SELECT * ".
115
						"FROM tb_cel.locations ".
115
						"FROM tb_new_cel.locations ".
116
						"WHERE insee_code = $id_location_protege ";
116
						"WHERE insee_code = $id_location_protege ";
117
			$utm = $this->getBdd()->recupererTous($requete);
117
			$utm = $this->getBdd()->recupererTous($requete);
118
		}
118
		}
119
		return $utm;
119
		return $utm;
120
	}
120
	}
121
 
121
 
122
	public function formerCommentaire($utm, $inventory) {
122
	public function formerCommentaire($utm, $inventory) {
123
		$comment = '';
123
		$comment = '';
124
			
124
			
125
		if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
125
		if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
126
			$comment .= $this->formerDate($inventory);
126
			$comment .= $this->formerDate($inventory);
127
		}
127
		}
128
			
128
			
129
		$comment .= " par ".utf8_decode($inventory['identifiant']);
129
		$comment .= " par ".utf8_decode($inventory['identifiant']);
130
		return $comment;
130
		return $comment;
131
	}
131
	}
132
	
132
	
133
	public function formerDate($inventory) {
133
	public function formerDate($inventory) {
134
		list($year, $month, $day) = explode ('-',$inventory['date_observation']);
134
		list($year, $month, $day) = explode ('-',$inventory['date_observation']);
135
		list($day) = explode (' ',$day);
135
		list($day) = explode (' ',$day);
136
		if ($month == '00') {
136
		if ($month == '00') {
137
			$date = ', en '.$year;
137
			$date = ', en '.$year;
138
		} else {
138
		} else {
139
			$date = ', le '.$day.'/'.$month.'/'.$year;
139
			$date = ', le '.$day.'/'.$month.'/'.$year;
140
		}
140
		}
141
		return $date;
141
		return $date;
142
	}
142
	}
143
	
143
	
144
	public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
144
	public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
145
		$prefix = 'CBN MED : ';
145
		$prefix = 'CBN MED : ';
146
		 
146
		 
147
		// Deja present  pour cette origine ? on ajoute  
147
		// Deja present  pour cette origine ? on ajoute  
148
		if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
148
		if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
149
			$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
149
			$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
150
		} else { // Nouveau commentaire
150
		} else { // Nouveau commentaire
151
			$text[$x.'|'.$y][$origine] = $name.$comment;
151
			$text[$x.'|'.$y][$origine] = $name.$comment;
152
		}
152
		}
153
		
153
		
154
		
154
		
155
		// Detection superposition de donnee 
155
		// Detection superposition de donnee 
156
		if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['cel']) && ($text[$x.'|'.$y]['cel'])) || 
156
		if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['cel']) && ($text[$x.'|'.$y]['cel'])) || 
157
			(isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))) {
157
			(isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))) {
158
				$merge[$x.'|'.$y]=true;
158
				$merge[$x.'|'.$y]=true;
159
		}
159
		}
160
		
160
		
161
		return array($text, $merge);
161
		return array($text, $merge);
162
	}
162
	}
163
	
163
	
164
 
164
 
165
 
165
 
166
}
166
}
167
?>
167
?>