Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 916 Rev 951
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
* Gère le sous-service Taxons de Cartes.
4
* Gère le sous-service Taxons de Cartes.
5
*
5
*
6
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Cartes
6
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Cartes
7
*
7
*
8
* @package eFlore/services
8
* @package eFlore/services
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
10
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
11
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
* @version 1.0
12
* @version 1.0
13
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
13
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
14
*/
14
*/
15
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
15
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
16
class TaxonsCartes {
16
class TaxonsCartes {
17
 
17
 
18
	private $parametres = array();
18
	private $parametres = array();
19
	private $ressources = array();
19
	private $ressources = array();
20
 
20
 
21
	const CODE_REFTAX_DEFAUT = 'bdtxa';
21
	const CODE_REFTAX_DEFAUT = 'bdtxa';
22
	const TYPE_ID_DEFAUT = 'nn';
22
	const TYPE_ID_DEFAUT = 'nn';
23
	const CARTE_DEFAUT = 'antilles';
23
	const CARTE_DEFAUT = 'antilles';
24
	const FORMAT_DEFAUT = '587x550';
24
	const FORMAT_DEFAUT = '587x550';
25
	const VERSION_DEFAUT = '+';
25
	const VERSION_DEFAUT = '+';
26
	const MIME_SVG = 'image/svg+xml';
26
	const MIME_SVG = 'image/svg+xml';
27
	const MIME_PNG = 'image/png';
27
	const MIME_PNG = 'image/png';
28
	const PRESENCE_CHOROLOGIE = '15';
28
	const PRESENCE_CHOROLOGIE = '15';
29
 
29
 
30
	private $config = array();
30
	private $config = array();
31
	private $convertisseur = '';
31
	private $convertisseur = '';
32
	private $cheminCartesBase = '';
32
	private $cheminCartesBase = '';
33
	private $formatsSupportes = array(self::MIME_SVG, self::MIME_PNG);
33
	private $formatsSupportes = array(self::MIME_SVG, self::MIME_PNG);
34
	private $reftaxSupportes = array(self::CODE_REFTAX_DEFAUT);
34
	private $reftaxSupportes = array(self::CODE_REFTAX_DEFAUT);
35
	private $UrlNavigation = null;
35
	private $UrlNavigation = null;
36
	private $taxonsDemandes = array();
36
	private $taxonsDemandes = array();
37
	private $imgLargeur = 0;
37
	private $imgLargeur = 0;
38
	private $imgHauteur = 0;
38
	private $imgHauteur = 0;
39
	private $tableMeta = '';
39
	private $tableMeta = '';
40
	private $tableOntologie = '';
40
	private $tableOntologie = '';
41
	private $tableChorodep = '';
41
	private $tableChorodep = '';
42
	private $metadonnees = '';
42
	private $metadonnees = '';
43
	private $ontologies = '';
43
	private $ontologies = '';
44
	private $priorites = '';
44
	private $priorites = '';
45
	private $version = '';
45
	private $version = '';
46
	private $legende = array();
46
	private $legende = array();
47
	private $donnees = array();
47
	private $donnees = array();
48
 
48
 
49
 
49
 
50
	public function __construct(Conteneur $conteneur) {
50
	public function __construct(Conteneur $conteneur) {
51
		$this->Bdd = $conteneur->getBdd();
51
		$this->Bdd = $conteneur->getBdd();
52
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
52
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
53
		$this->config = $conteneur->getParametre('Cartes');
53
		$this->config = $conteneur->getParametre('Cartes');
54
		$this->convertisseur = $this->config['convertisseur'];
54
		$this->convertisseur = $this->config['convertisseur'];
55
		$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
55
		$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
56
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
56
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
57
		$this->cheminCartesBase = $this->config['chemin'];
57
		$this->cheminCartesBase = $this->config['chemin'];
58
		$cacheOptions = array('mise_en_cache' => $this->config['cache_miseEnCache'],
58
		$cacheOptions = array('mise_en_cache' => $this->config['cache_miseEnCache'],
59
			'stockage_chemin' => $this->config['cache_stockageChemin'],
59
			'stockage_chemin' => $this->config['cache_stockageChemin'],
60
			'duree_de_vie' => $this->config['cache_dureeDeVie']);
60
			'duree_de_vie' => $this->config['cache_dureeDeVie']);
61
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
61
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
62
	}
62
	}
63
 
63
 
64
	public function consulter($ressources, $parametres) {
64
	public function consulter($ressources, $parametres) {
65
		$this->parametres = $parametres;
65
		$this->parametres = $parametres;
66
		$this->ressources = $ressources;
66
		$this->ressources = $ressources;
67
 
67
 
68
		$this->definirValeurParDefautDesParametres();
68
		$this->definirValeurParDefautDesParametres();
69
		$this->verifierParametres();
69
		$this->verifierParametres();
70
 
70
 
71
		$resultat = $this->obtenirResultat();
71
		$resultat = $this->obtenirResultat();
72
 
72
 
73
		return $resultat;
73
		return $resultat;
74
	}
74
	}
75
 
75
 
76
	private function definirValeurParDefautDesParametres() {
76
	private function definirValeurParDefautDesParametres() {
77
		if (isset($this->parametres['retour']) == false) {
77
		if (isset($this->parametres['retour']) == false) {
78
			$this->parametres['retour'] = self::MIME_SVG;
78
			$this->parametres['retour'] = self::MIME_SVG;
79
		}
79
		}
80
		if (isset($this->parametres['retour.format']) == false) {
80
		if (isset($this->parametres['retour.format']) == false) {
81
			$this->parametres['retour.format'] = self::FORMAT_DEFAUT;
81
			$this->parametres['retour.format'] = self::FORMAT_DEFAUT;
82
		}
82
		}
83
		if (isset($this->parametres['version.projet']) == false) {
83
		if (isset($this->parametres['version.projet']) == false) {
84
			$this->parametres['version.projet'] = self::VERSION_DEFAUT;
84
			$this->parametres['version.projet'] = self::VERSION_DEFAUT;
85
		}
85
		}
86
	}
86
	}
87
 
87
 
88
	private function verifierParametres() {
88
	private function verifierParametres() {
89
		$erreurs = array();
89
		$erreurs = array();
90
 
90
 
91
		if (isset($this->parametres['retour']) == false) {
91
		if (isset($this->parametres['retour']) == false) {
92
			$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
92
			$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
93
		}
93
		}
94
		if ($this->verifierValeurParametreRetour() == false) {
94
		if ($this->verifierValeurParametreRetour() == false) {
95
			$erreurs[] = "Le type de retour '{$this->parametres['retour']}' n'est pas supporté.";
95
			$erreurs[] = "Le type de retour '{$this->parametres['retour']}' n'est pas supporté.";
96
		}
96
		}
97
		if (isset($this->parametres['retour.format']) == false) {
97
		if (isset($this->parametres['retour.format']) == false) {
98
			$erreurs[] = "Le paramètre de format de retour 'retour.format' est obligatoire.";
98
			$erreurs[] = "Le paramètre de format de retour 'retour.format' est obligatoire.";
99
		}
99
		}
100
		if ($this->verifierValeurParametreFormat() == false) {
100
		if ($this->verifierValeurParametreFormat() == false) {
101
			$erreurs[] = "Le type de format '{$this->parametres['retour.format']}' n'est pas supporté.".
101
			$erreurs[] = "Le type de format '{$this->parametres['retour.format']}' n'est pas supporté.".
102
				"Veuillez indiquer un nombre entier correspondant à la largeur désirée pour la carte.";
102
				"Veuillez indiquer un nombre entier correspondant à la largeur désirée pour la carte.";
103
		}
103
		}
104
		if ($this->verifierValeurParametreVersionProjet() == false) {
104
		if ($this->verifierValeurParametreVersionProjet() == false) {
105
			$erreurs[] = "Le format de version.projet '{$this->parametres['version.projet']}' n'est pas supporté.".
105
			$erreurs[] = "Le format de version.projet '{$this->parametres['version.projet']}' n'est pas supporté.".
106
				"Veuillez indiquer le code '+' (=dernière version) ou une année sur 4 chiffres séparé d'un mois ".
106
				"Veuillez indiquer le code '+' (=dernière version) ou une année sur 4 chiffres séparé d'un mois ".
107
				"sur deux chiffres par un point. Ex. : 2012.01";
107
				"sur deux chiffres par un point. Ex. : 2012.01";
108
		}
108
		}
109
 
109
 
110
		if (count($erreurs) > 0) {
110
		if (count($erreurs) > 0) {
111
			$message = implode('<br />', $erreurs);
111
			$message = implode('<br />', $erreurs);
112
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
112
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
113
			throw new Exception($message, $code);
113
			throw new Exception($message, $code);
114
		}
114
		}
115
	}
115
	}
116
 
116
 
117
	private function verifierValeurParametreRetour() {
117
	private function verifierValeurParametreRetour() {
118
		return in_array($this->parametres['retour'], $this->formatsSupportes);
118
		return in_array($this->parametres['retour'], $this->formatsSupportes);
119
	}
119
	}
120
 
120
 
121
	private function verifierValeurParametreFormat() {
121
	private function verifierValeurParametreFormat() {
122
		if ($ok = preg_match('/^([0-9]+)$/', $this->parametres['retour.format'], $match)) {
122
		if ($ok = preg_match('/^([0-9]+)$/', $this->parametres['retour.format'], $match)) {
123
			$this->imgLargeur = $match[1];
123
			$this->imgLargeur = $match[1];
124
		} else if ($ok = preg_match('/^([0-9]+)x([0-9]+)$/', $this->parametres['retour.format'], $match)) {
124
		} else if ($ok = preg_match('/^([0-9]+)x([0-9]+)$/', $this->parametres['retour.format'], $match)) {
125
			$this->imgLargeur = $match[1];
125
			$this->imgLargeur = $match[1];
126
			$this->imgHauteur = $match[2];
126
			$this->imgHauteur = $match[2];
127
		}
127
		}
128
		return $ok;
128
		return $ok;
129
	}
129
	}
130
	private function verifierValeurParametreVersionProjet() {
130
	private function verifierValeurParametreVersionProjet() {
131
		$ok = (preg_match('/^(?:[+]|[0-9]{4}\.[0-9]{2})$/', $this->parametres['version.projet']) == 0) ? false : true;
131
		$ok = (preg_match('/^(?:[+]|[0-9]{4}\.[0-9]{2})$/', $this->parametres['version.projet']) == 0) ? false : true;
132
		return $ok;
132
		return $ok;
133
	}
133
	}
134
 
134
 
135
	private function obtenirResultat() {
135
	private function obtenirResultat() {
136
		$this->analyserIdentifiants();
136
		$this->analyserIdentifiants();
137
		$this->verifierIdentifiants();
137
		$this->verifierIdentifiants();
138
 
138
 
139
		$this->chargerMetadonnees();
139
		$this->chargerMetadonnees();
140
		$this->definirVersion();
140
		$this->definirVersion();
141
		$this->tableChorodep = 'bdtxa_v'.str_replace('.', '_', $this->version);
141
		$this->tableChorodep = 'bdtxa_v'.str_replace('.', '_', $this->version);
142
		$this->chargerOntologies();
142
		$this->chargerOntologies();
143
		$this->chargerLegende();
143
		$this->chargerLegende();
144
		$this->chargerPrioritesLegende();
144
		$this->chargerPrioritesLegende();
145
		$this->chargerDonnees();
145
		$this->chargerDonnees();
146
		$svg = $this->genererSVG();
146
		$svg = $this->genererSVG();
147
		$img = ($this->parametres['retour'] == self::MIME_PNG) ? $this->convertirEnPNG($svg) : $svg;
147
		$img = ($this->parametres['retour'] == self::MIME_PNG) ? $this->convertirEnPNG($svg) : $svg;
148
 
148
 
149
		$resultat = new ResultatService();
149
		$resultat = new ResultatService();
150
		$resultat->corps = $img;
150
		$resultat->corps = $img;
151
		$resultat->mime = $this->parametres['retour'];
151
		$resultat->mime = $this->parametres['retour'];
152
 
152
 
153
		return $resultat;
153
		return $resultat;
154
	}
154
	}
155
 
155
 
156
	private function analyserIdentifiants() {
156
	private function analyserIdentifiants() {
157
		$ids = $this->ressources[0];
157
		$ids = $this->ressources[0];
158
		if (preg_match('/^[0-9]+$/', $ids)) {
158
		if (preg_match('/^[0-9]+$/', $ids)) {
159
			$this->taxonsDemandes[self::CODE_REFTAX_DEFAUT]['nn'][] = $ids;
159
			$this->taxonsDemandes[self::CODE_REFTAX_DEFAUT]['nn'][] = $ids;
160
		} else {
160
		} else {
161
			// ceci contient potentiellement des formes ref_tax1.nn:1,2;ref_tax2.nt:3,4
161
			// ceci contient potentiellement des formes ref_tax1.nn:1,2;ref_tax2.nt:3,4
162
			$projetsListeEtNumNoms = explode(';', $ids);
162
			$projetsListeEtNumNoms = explode(';', $ids);
163
			if (count($projetsListeEtNumNoms) > 0) {
163
			if (count($projetsListeEtNumNoms) > 0) {
164
				foreach ($projetsListeEtNumNoms as $projetEtNumNoms) {
164
				foreach ($projetsListeEtNumNoms as $projetEtNumNoms) {
165
					$projetEtNumNoms = (strpos($projetEtNumNoms, ':')) ? $projetEtNumNoms : self::CODE_REFTAX_DEFAUT.'.nn:'.$projetEtNumNoms;
165
					$projetEtNumNoms = (strpos($projetEtNumNoms, ':')) ? $projetEtNumNoms : self::CODE_REFTAX_DEFAUT.'.nn:'.$projetEtNumNoms;
166
					list($projetEtType, $numNoms) = explode(':', $projetEtNumNoms);
166
					list($projetEtType, $numNoms) = explode(':', $projetEtNumNoms);
167
 
167
 
168
					$projetEtType = (strpos($projetEtType, '.')) ? $projetEtType : self::CODE_REFTAX_DEFAUT.'.'.$projetEtType;
168
					$projetEtType = (strpos($projetEtType, '.')) ? $projetEtType : self::CODE_REFTAX_DEFAUT.'.'.$projetEtType;
169
					list($projet, $type) = explode('.', $projetEtType);
169
					list($projet, $type) = explode('.', $projetEtType);
170
 
170
 
171
					$this->taxonsDemandes[$projet][$type] = explode(',', $numNoms);
171
					$this->taxonsDemandes[$projet][$type] = explode(',', $numNoms);
172
				}
172
				}
173
			}
173
			}
174
		}
174
		}
175
	}
175
	}
176
 
176
 
177
	private function verifierIdentifiants() {
177
	private function verifierIdentifiants() {
178
		foreach (array_keys($this->taxonsDemandes) as $reftax) {
178
		foreach (array_keys($this->taxonsDemandes) as $reftax) {
179
			$ok = in_array($reftax, $this->reftaxSupportes);
179
			$ok = in_array($reftax, $this->reftaxSupportes);
180
			if ($ok == false) {
180
			if ($ok == false) {
181
				$message = "Le reférentiel taxonomique '$reftax' n'est pas pris en compte par ce projet.";
181
				$message = "Le reférentiel taxonomique '$reftax' n'est pas pris en compte par ce projet.";
182
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
182
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
183
				throw new Exception($message, $code);
183
				throw new Exception($message, $code);
184
			}
184
			}
185
		}
185
		}
186
	}
186
	}
187
 
187
 
188
	private function chargerMetadonnees() {
188
	private function chargerMetadonnees() {
189
		$requete = 'SELECT * '.
189
		$requete = 'SELECT * '.
190
			"FROM {$this->tableMeta} ".
190
			"FROM {$this->tableMeta} ".
191
			"ORDER BY date_creation DESC ";
191
			"ORDER BY date_creation DESC ";
192
		$resultats = $this->Bdd->recupererTous($requete);
192
		$resultats = $this->Bdd->recupererTous($requete);
193
 
193
 
194
		if (!is_array($resultats) || count($resultats) <= 0) {
194
		if (!is_array($resultats) || count($resultats) <= 0) {
195
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
195
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
196
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
196
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
197
			throw new Exception($message, $code);
197
			throw new Exception($message, $code);
198
		}
198
		}
199
 
199
 
200
		$this->metadonnees = $resultats;
200
		$this->metadonnees = $resultats;
201
	}
201
	}
202
 
202
 
203
	private function definirVersion() {
203
	private function definirVersion() {
204
		if ($this->parametres['version.projet'] == '+') {
204
		if ($this->parametres['version.projet'] == '+') {
205
			$this->version = $this->metadonnees[0]['version'];
205
			$this->version = $this->metadonnees[0]['version'];
206
		} else {
206
		} else {
207
			$this->version = $this->parametres['version.projet'];
207
			$this->version = $this->parametres['version.projet'];
208
		}
208
		}
209
	}
209
	}
210
 
210
 
211
	private function chargerOntologies() {
211
	private function chargerOntologies() {
212
		$requete = 'SELECT * '.
212
		$requete = 'SELECT * '.
213
			"FROM {$this->tableOntologie} WHERE classe_id = (SELECT id FROM eflore_ontologies WHERE code ='presenceChorologie')";
213
			"FROM {$this->tableOntologie} WHERE classe_id = (SELECT id FROM eflore_ontologies WHERE code ='presenceChorologie')";
214
		$resultats = $this->Bdd->recupererTous($requete);
214
		$resultats = $this->Bdd->recupererTous($requete);
215
 
215
 
216
		if (!is_array($resultats) || count($resultats) <= 0) {
216
		if (!is_array($resultats) || count($resultats) <= 0) {
217
			$message = "Les données de légende n'ont pu être chargées pour la ressource demandée";
217
			$message = "Les données de légende n'ont pu être chargées pour la ressource demandée";
218
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
218
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
219
			throw new Exception($message, $code);
219
			throw new Exception($message, $code);
220
		}
220
		}
221
 
221
 
222
		foreach ($resultats as $ontologie) {
222
		foreach ($resultats as $ontologie) {
223
			$this->ontologies[$ontologie['id']] = $this->extraireComplementsOntologies($ontologie);
223
			$this->ontologies[$ontologie['id']] = Commun::extraireComplementsOntologies($ontologie);
224
		}
224
		}
225
	}
225
	}
226
 
-
 
227
 
-
 
228
	private function extraireComplementsOntologies($ontologie) {
-
 
229
		if ($ontologie['complements'] != '') {
-
 
230
			$complements = explode(',', trim($ontologie['complements']));
-
 
231
			foreach ($complements as $complement) {
-
 
232
				list($cle, $val) = explode('=', trim($complement));
-
 
233
				$ontologie[trim($cle)] = trim($val);
-
 
234
			}
-
 
235
		}
-
 
236
		return $ontologie;
-
 
237
	}
-
 
238
 
226
 
239
	private function chargerLegende() {
227
	private function chargerLegende() {
240
		foreach ($this->ontologies as $ontologie) {
228
		foreach ($this->ontologies as $ontologie) {
241
			if ($ontologie['classe_id'] == self::PRESENCE_CHOROLOGIE) {
229
			if ($ontologie['classe_id'] == self::PRESENCE_CHOROLOGIE) {
242
				$this->legende[$ontologie['code']] = $ontologie['legende'];
230
				$this->legende[$ontologie['code']] = $ontologie['legende'];
243
			}
231
			}
244
		}
232
		}
245
	}
233
	}
246
 
234
 
247
	private function chargerPrioritesLegende() {
235
	private function chargerPrioritesLegende() {
248
		foreach ($this->ontologies as $ontologie) {
236
		foreach ($this->ontologies as $ontologie) {
249
			if ($ontologie['classe_id'] == self::PRESENCE_CHOROLOGIE && isset($ontologie['priorite'])) {
237
			if ($ontologie['classe_id'] == self::PRESENCE_CHOROLOGIE && isset($ontologie['priorite'])) {
250
				$this->priorites[$ontologie['code']] = $ontologie['priorite'];
238
				$this->priorites[$ontologie['code']] = $ontologie['priorite'];
251
			}
239
			}
252
		}
240
		}
253
	}
241
	}
254
 
242
 
255
	private function chargerDonnees() {
243
	private function chargerDonnees() {
256
		$conditions = $this->getConditions();
244
		$conditions = $this->getConditions();
257
		$requete = 'SELECT nom_sci, `presence_Guadeloupe`, `presence_Martinique`, `presence_Saint_Martin`, '.
245
		$requete = 'SELECT nom_sci, `presence_Guadeloupe`, `presence_Martinique`, `presence_Saint_Martin`, '.
258
		            "`presence_La_Desirade`, `presence_Saint_Barthelemy`, `presence_Marie_Galante`, ".
246
		            "`presence_La_Desirade`, `presence_Saint_Barthelemy`, `presence_Marie_Galante`, ".
259
		            "`presence_Les-Saintes` ".
247
		            "`presence_Les-Saintes` ".
260
					"FROM {$this->tableChorodep} ".
248
					"FROM {$this->tableChorodep} ".
261
		(isset($conditions) ? 'WHERE '.implode(' AND ', $conditions) : '');
249
		(isset($conditions) ? 'WHERE '.implode(' AND ', $conditions) : '');
262
		$resultat = $this->Bdd->recupererTous($requete);
250
		$resultat = $this->Bdd->recupererTous($requete);
263
		$this->donnees = $resultat;
251
		$this->donnees = $resultat;
264
	}
252
	}
265
 
253
 
266
	private function getConditions() {
254
	private function getConditions() {
267
		$conditions = null;
255
		$conditions = null;
268
		if ($nnListe = $this->getListeNumNom()) {
256
		if ($nnListe = $this->getListeNumNom()) {
269
			$conditions[] = "num_nom IN ($nnListe) ";
257
			$conditions[] = "num_nom IN ($nnListe) ";
270
		}
258
		}
271
		if ($ntListe = $this->getListeNumTax()) {
259
		if ($ntListe = $this->getListeNumTax()) {
272
			$conditions[] = "num_tax IN ($ntListe) ";
260
			$conditions[] = "num_tax IN ($ntListe) ";
273
		}
261
		}
274
		return $conditions;
262
		return $conditions;
275
	}
263
	}
276
 
264
 
277
	private function getListeNumNom() {
265
	private function getListeNumNom() {
278
		$nnListe = null;
266
		$nnListe = null;
279
		$refTax = self::CODE_REFTAX_DEFAUT;
267
		$refTax = self::CODE_REFTAX_DEFAUT;
280
		if (isset($this->taxonsDemandes[$refTax])) {
268
		if (isset($this->taxonsDemandes[$refTax])) {
281
			$nnProteges = array();
269
			$nnProteges = array();
282
			if (isset($this->taxonsDemandes[$refTax]['nn'])) {
270
			if (isset($this->taxonsDemandes[$refTax]['nn'])) {
283
				foreach ($this->taxonsDemandes[$refTax]['nn'] as $nn) {
271
				foreach ($this->taxonsDemandes[$refTax]['nn'] as $nn) {
284
					$nnProteges[] = $this->Bdd->proteger($nn);
272
					$nnProteges[] = $this->Bdd->proteger($nn);
285
				}
273
				}
286
				$nnListe = implode(',', $nnProteges);
274
				$nnListe = implode(',', $nnProteges);
287
			}
275
			}
288
		}
276
		}
289
		return $nnListe;
277
		return $nnListe;
290
	}
278
	}
291
 
279
 
292
	private function getListeNumTax() {
280
	private function getListeNumTax() {
293
		$ntListe = null;
281
		$ntListe = null;
294
		$refTax = self::CODE_REFTAX_DEFAUT;
282
		$refTax = self::CODE_REFTAX_DEFAUT;
295
		if (isset($this->taxonsDemandes[$refTax])) {
283
		if (isset($this->taxonsDemandes[$refTax])) {
296
			$ntProteges = array();
284
			$ntProteges = array();
297
			if (isset($this->taxonsDemandes[$refTax]['nt'])) {
285
			if (isset($this->taxonsDemandes[$refTax]['nt'])) {
298
				foreach ($this->taxonsDemandes[$refTax]['nt'] as $nt) {
286
				foreach ($this->taxonsDemandes[$refTax]['nt'] as $nt) {
299
					$ntProteges[] = $this->Bdd->proteger($nt);
287
					$ntProteges[] = $this->Bdd->proteger($nt);
300
				}
288
				}
301
				$ntListe = implode(',', $ntProteges);
289
				$ntListe = implode(',', $ntProteges);
302
			}
290
			}
303
		}
291
		}
304
		return $ntListe;
292
		return $ntListe;
305
	}
293
	}
306
 
294
 
307
	private function genererSVG() {
295
	private function genererSVG() {
308
		$dom = new DOMDocument('1.0', 'UTF-8');
296
		$dom = new DOMDocument('1.0', 'UTF-8');
309
		$dom->validateOnParse = true;
297
		$dom->validateOnParse = true;
310
 
298
 
311
		$fichierCarteSvg = $this->cheminCartesBase.self::CARTE_DEFAUT.'.svg';
299
		$fichierCarteSvg = $this->cheminCartesBase.self::CARTE_DEFAUT.'.svg';
312
		$dom->load($fichierCarteSvg);
300
		$dom->load($fichierCarteSvg);
313
 
301
 
314
		$racineElement = $dom->documentElement;
302
		$racineElement = $dom->documentElement;
315
		$racineElement->setAttribute('width', $this->imgLargeur);
303
		$racineElement->setAttribute('width', $this->imgLargeur);
316
		if ($this->imgHauteur != 0) {
304
		if ($this->imgHauteur != 0) {
317
			$racineElement->setAttribute('height', $this->imgHauteur);
305
			$racineElement->setAttribute('height', $this->imgHauteur);
318
		}
306
		}
319
 
307
 
320
		$css = $this->creerCssCarte();
308
		$css = $this->creerCssCarte();
321
		$styleElement = $dom->getElementsByTagName('style')->item(0);
309
		$styleElement = $dom->getElementsByTagName('style')->item(0);
322
		$css = $styleElement->nodeValue.$css;
310
		$css = $styleElement->nodeValue.$css;
323
		$txtCss = $dom->createCDATASection($css);
311
		$txtCss = $dom->createCDATASection($css);
324
		$styleElement->nodeValue = '';
312
		$styleElement->nodeValue = '';
325
		$styleElement->appendChild($txtCss);
313
		$styleElement->appendChild($txtCss);
326
 
314
 
327
		$titre = $this->creerTitre();
315
		$titre = $this->creerTitre();
328
		$titreCdata = $dom->createCDATASection($titre);
316
		$titreCdata = $dom->createCDATASection($titre);
329
		$titreElement = $dom->getElementsByTagName('title')->item(0);
317
		$titreElement = $dom->getElementsByTagName('title')->item(0);
330
		$titreElement->nodeValue = '';
318
		$titreElement->nodeValue = '';
331
		$titreElement->appendChild($titreCdata);
319
		$titreElement->appendChild($titreCdata);
332
 
320
 
333
		$taxonTitre = $this->creerTitreTaxon();
321
		$taxonTitre = $this->creerTitreTaxon();
334
		$taxonCdata = $dom->createCDATASection($taxonTitre);
322
		$taxonCdata = $dom->createCDATASection($taxonTitre);
335
		$xpath = new DOMXPath($dom);
323
		$xpath = new DOMXPath($dom);
336
		$taxonTitreEl = $xpath->query("//*[@id='titre-taxon']")->item(0);
324
		$taxonTitreEl = $xpath->query("//*[@id='titre-taxon']")->item(0);
337
		$taxonTitreEl->nodeValue = '';
325
		$taxonTitreEl->nodeValue = '';
338
		$taxonTitreEl->setAttribute('title', $taxonTitre);
326
		$taxonTitreEl->setAttribute('title', $taxonTitre);
339
		$taxonTitreEl->appendChild($taxonCdata);
327
		$taxonTitreEl->appendChild($taxonCdata);
340
 
328
 
341
		$svg = $dom->saveXML();
329
		$svg = $dom->saveXML();
342
		return $svg;
330
		return $svg;
343
	}
331
	}
344
 
332
 
345
	private function creerCssCarte() {
333
	private function creerCssCarte() {
346
		$css = '';
334
		$css = '';
347
		$this->getZonesPriorites();
335
		$this->getZonesPriorites();
348
		$zonesCouleurs = $this->getZonesCouleurs();
336
		$zonesCouleurs = $this->getZonesCouleurs();
349
		foreach ($zonesCouleurs as $couleur => $zonesClasses) {
337
		foreach ($zonesCouleurs as $couleur => $zonesClasses) {
350
			$classes = implode(', ', $zonesClasses);
338
			$classes = implode(', ', $zonesClasses);
351
			$css .= "$classes {"."\n"."fill:$couleur;"."\n"."}"."\n";
339
			$css .= "$classes {"."\n"."fill:$couleur;"."\n"."}"."\n";
352
		}
340
		}
353
		return $css;
341
		return $css;
354
	}
342
	}
355
 
343
 
356
	private function getZonesPriorites() {
344
	private function getZonesPriorites() {
357
		$this->zones = array();
345
		$this->zones = array();
358
		$zonesPrioritaires = array();
346
		$zonesPrioritaires = array();
359
		foreach ($this->donnees as $donnee) {
347
		foreach ($this->donnees as $donnee) {
360
			foreach ($donnee as $zoneId => $codeLegende) {
348
			foreach ($donnee as $zoneId => $codeLegende) {
361
				if (preg_match('/^presence_(.)*$/i', $zoneId)) {
349
				if (preg_match('/^presence_(.)*$/i', $zoneId)) {
362
					$zoneId = $this->formaterZoneId($zoneId);
350
					$zoneId = $this->formaterZoneId($zoneId);
363
					if (array_key_exists($codeLegende, $this->priorites)) {
351
					if (array_key_exists($codeLegende, $this->priorites)) {
364
						$priorite = $this->priorites[$codeLegende];
352
						$priorite = $this->priorites[$codeLegende];
365
						if (array_key_exists($zoneId, $zonesPrioritaires) == false) {
353
						if (array_key_exists($zoneId, $zonesPrioritaires) == false) {
366
							$zonesPrioritaires[$zoneId] = 0;
354
							$zonesPrioritaires[$zoneId] = 0;
367
						}
355
						}
368
						if ($priorite > $zonesPrioritaires[$zoneId]) {
356
						if ($priorite > $zonesPrioritaires[$zoneId]) {
369
							$zonesPrioritaires[$zoneId] = $priorite;
357
							$zonesPrioritaires[$zoneId] = $priorite;
370
							$this->zones[$zoneId] = $codeLegende;
358
							$this->zones[$zoneId] = $codeLegende;
371
						}
359
						}
372
					}
360
					}
373
				}
361
				}
374
			}
362
			}
375
		}
363
		}
376
	}
364
	}
377
 
365
 
378
	private function formaterZoneId($zoneId) {
366
	private function formaterZoneId($zoneId) {
379
		$zoneId = strtolower(str_replace('presence_', '', $zoneId));
367
		$zoneId = strtolower(str_replace('presence_', '', $zoneId));
380
		$zoneId = str_replace('-', '_', $zoneId);
368
		$zoneId = str_replace('-', '_', $zoneId);
381
		return $zoneId;
369
		return $zoneId;
382
	}
370
	}
383
 
371
 
384
	private function getZonesCouleurs() {
372
	private function getZonesCouleurs() {
385
		$zones = array();
373
		$zones = array();
386
		ksort($this->zones);
374
		ksort($this->zones);
387
		foreach ($this->zones as $zoneId => $codeLegende) {
375
		foreach ($this->zones as $zoneId => $codeLegende) {
388
			if (array_key_exists($codeLegende, $this->legende)) {
376
			if (array_key_exists($codeLegende, $this->legende)) {
389
				$couleur = $this->legende[$codeLegende];
377
				$couleur = $this->legende[$codeLegende];
390
				$zones[$couleur][] = strtolower('.'.sprintf('%02s', $zoneId));
378
				$zones[$couleur][] = strtolower('.'.sprintf('%02s', $zoneId));
391
			}
379
			}
392
		}
380
		}
393
		return $zones;
381
		return $zones;
394
	}
382
	}
395
 
383
 
396
	private function creerTitre() {
384
	private function creerTitre() {
397
		$titre = "Carte en cours d'élaboration";
385
		$titre = "Carte en cours d'élaboration";
398
		if ($this->donnees != array()) {
386
		if ($this->donnees != array()) {
399
			$titre .= ' pour '.$this->creerTitreTaxon();
387
			$titre .= ' pour '.$this->creerTitreTaxon();
400
		}
388
		}
401
		return $titre;
389
		return $titre;
402
	}
390
	}
403
 
391
 
404
	private function creerTitreTaxon() {
392
	private function creerTitreTaxon() {
405
		$titre = '';
393
		$titre = '';
406
		$noms = array();
394
		$noms = array();
407
		foreach ($this->donnees as $donnee) {
395
		foreach ($this->donnees as $donnee) {
408
			$noms[] = $donnee['nom_sci'];
396
			$noms[] = $donnee['nom_sci'];
409
		}
397
		}
410
		$titre = implode(', ', $noms);
398
		$titre = implode(', ', $noms);
411
		return $titre;
399
		return $titre;
412
	}
400
	}
413
 
401
 
414
	private function convertirEnPNG($svg) {
402
	private function convertirEnPNG($svg) {
415
		$png = null;
403
		$png = null;
416
		if (isset($this->convertisseur)) {
404
		if (isset($this->convertisseur)) {
417
			if ($this->convertisseur == 'imagick') {
405
			if ($this->convertisseur == 'imagick') {
418
				if (extension_loaded('imagick')) {
406
				if (extension_loaded('imagick')) {
419
					$png = $this->convertirEnPNGAvecImageMagick($svg);
407
					$png = $this->convertirEnPNGAvecImageMagick($svg);
420
				} else {
408
				} else {
421
					$message = "Impossible de générer l'image sur le serveur. Extenssion ImageMagick abscente.";
409
					$message = "Impossible de générer l'image sur le serveur. Extenssion ImageMagick abscente.";
422
					$code = RestServeur::HTTP_CODE_ERREUR;
410
					$code = RestServeur::HTTP_CODE_ERREUR;
423
					throw new Exception($message, $code);
411
					throw new Exception($message, $code);
424
				}
412
				}
425
			} else if ($this->convertisseur == 'rsvg') {
413
			} else if ($this->convertisseur == 'rsvg') {
426
				$png = Commun::convertirEnPNGAvecRsvg($this->getIdFichier(), $this->config['cache_stockageChemin'], $svg);
414
				$png = Commun::convertirEnPNGAvecRsvg($this->getIdFichier(), $this->config['cache_stockageChemin'], $svg);
427
			} else {
415
			} else {
428
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas parti de la liste ".
416
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas parti de la liste ".
429
					"des convertisseurs disponibles : imagick, rsvg.";
417
					"des convertisseurs disponibles : imagick, rsvg.";
430
				$code = RestServeur::HTTP_CODE_ERREUR;
418
				$code = RestServeur::HTTP_CODE_ERREUR;
431
				throw new Exception($message, $code);
419
				throw new Exception($message, $code);
432
			}
420
			}
433
		} else {
421
		} else {
434
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
422
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
435
			$code = RestServeur::HTTP_CODE_ERREUR;
423
			$code = RestServeur::HTTP_CODE_ERREUR;
436
			throw new Exception($message, $code);
424
			throw new Exception($message, $code);
437
		}
425
		}
438
		return $png;
426
		return $png;
439
	}
427
	}
440
 
428
 
441
	private function convertirEnPNGAvecImageMagick($svg) {
429
	private function convertirEnPNGAvecImageMagick($svg) {
442
		$convertisseur = new Imagick();
430
		$convertisseur = new Imagick();
443
		$convertisseur->setBackgroundColor(new ImagickPixel('transparent'));
431
		$convertisseur->setBackgroundColor(new ImagickPixel('transparent'));
444
		$convertisseur->readImageBlob($svg);
432
		$convertisseur->readImageBlob($svg);
445
		$convertisseur->setImageFormat('png32');
433
		$convertisseur->setImageFormat('png32');
446
		$convertisseur->resizeImage($this->imgLargeur, $this->imgHauteur, imagick::FILTER_LANCZOS, 0, true);
434
		$convertisseur->resizeImage($this->imgLargeur, $this->imgHauteur, imagick::FILTER_LANCZOS, 0, true);
447
		$png = $convertisseur->getImageBlob();
435
		$png = $convertisseur->getImageBlob();
448
		$convertisseur->clear();
436
		$convertisseur->clear();
449
		$convertisseur->destroy();
437
		$convertisseur->destroy();
450
		return $png;
438
		return $png;
451
	}
439
	}
452
 
440
 
453
	private function getIdFichier() {
441
	private function getIdFichier() {
454
		$id = '';
442
		$id = '';
455
		foreach ($this->taxonsDemandes as $reftax => $ids) {
443
		foreach ($this->taxonsDemandes as $reftax => $ids) {
456
			$id[] = $reftax;
444
			$id[] = $reftax;
457
			foreach ($ids as $type => $vals) {
445
			foreach ($ids as $type => $vals) {
458
				$id[] = $type;
446
				$id[] = $type;
459
				$id[] = implode('-', $vals);
447
				$id[] = implode('-', $vals);
460
			}
448
			}
461
		}
449
		}
462
		$id = implode('-', $id);
450
		$id = implode('-', $id);
463
		return $id;
451
		return $id;
464
	}
452
	}
465
 
453
 
466
	public function getParametreTableau($cle) {
454
	public function getParametreTableau($cle) {
467
		$tableau = array();
455
		$tableau = array();
468
		$parametre = $this->config[$cle];
456
		$parametre = $this->config[$cle];
469
		if (empty($parametre) === false) {
457
		if (empty($parametre) === false) {
470
			$tableauPartiel = explode(',', $parametre);
458
			$tableauPartiel = explode(',', $parametre);
471
			$tableauPartiel = array_map('trim', $tableauPartiel);
459
			$tableauPartiel = array_map('trim', $tableauPartiel);
472
			foreach ($tableauPartiel as $champ) {
460
			foreach ($tableauPartiel as $champ) {
473
				if (strpos($champ, '=') === false) {
461
				if (strpos($champ, '=') === false) {
474
					$tableau[] = trim($champ);
462
					$tableau[] = trim($champ);
475
				} else {
463
				} else {
476
					list($cle, $val) = explode('=', $champ);
464
					list($cle, $val) = explode('=', $champ);
477
					$tableau[trim($cle)] = trim($val);
465
					$tableau[trim($cle)] = trim($val);
478
				}
466
				}
479
			}
467
			}
480
		}
468
		}
481
		return $tableau;
469
		return $tableau;
482
	}
470
	}
483
}
471
}
484
?>
472
?>