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