Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 237 | Rev 252 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 237 Rev 248
Line 31... Line 31...
31
	private $formats_supportes = array(self::MIME_SVG, self::MIME_PNG);
31
	private $formats_supportes = array(self::MIME_SVG, self::MIME_PNG);
32
	private $UrlNavigation = null;
32
	private $UrlNavigation = null;
33
	private $taxonsDemandes = array();
33
	private $taxonsDemandes = array();
34
	private $imgLargeur = 0;
34
	private $imgLargeur = 0;
35
	private $imgHauteur = 0;
35
	private $imgHauteur = 0;
-
 
36
	private $legende = array();
-
 
37
	private $donnees = array();
Line 36... Line 38...
36
 
38
 
37
	public function __construct(Bdd $bdd = null, Array $config = null, CacheSimple $cache = null) {
39
	public function __construct(Bdd $bdd = null, Array $config = null, CacheSimple $cache = null) {
38
		$this->Bdd = is_null($bdd) ? new Bdd() : $bdd;
40
		$this->Bdd = is_null($bdd) ? new Bdd() : $bdd;
-
 
41
		$this->config = is_null($config) ? Config::get('Cartes') : $config;
-
 
42
 
-
 
43
		$this->chargerLegende();
39
		$this->config = is_null($config) ? Config::get('Cartes') : $config;
44
 
-
 
45
		$this->cheminCartesBase = $this->config['chemin'];
40
		$this->cheminCartesBase = $this->config['chemin'];
46
 
41
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
47
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
42
			'stockage_chemin' => $this->config['cache']['stockageChemin'],
48
			'stockage_chemin' => $this->config['cache']['stockageChemin'],
43
			'duree_de_vie' => $this->config['cache']['dureeDeVie']);
49
			'duree_de_vie' => $this->config['cache']['dureeDeVie']);
44
		//die(print_r($this->config, true));
50
		//die(print_r($this->config, true));
45
		$this->cache = is_null($cache) ? new CacheSimple($cacheOptions) : $cache;
51
		$this->cache = is_null($cache) ? new CacheSimple($cacheOptions) : $cache;
Line -... Line 52...
-
 
52
	}
-
 
53
 
-
 
54
	private function chargerLegende() {
-
 
55
		$requete = 'SELECT * '.
-
 
56
				'FROM chorodep_ontologies '.
-
 
57
				"WHERE classe_id = 1 ";
-
 
58
		$resultats = $this->Bdd->recupererTous($requete);
-
 
59
 
-
 
60
		if (!is_array($resultats) || count($resultats) <= 0) {
-
 
61
			$message = "La légende n'a pu être chargée pour la ressource demandée";
-
 
62
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
63
			throw new Exception($message, $code);
-
 
64
		}
-
 
65
 
-
 
66
		foreach ($resultats as $ontologie) {
-
 
67
			$ontologie = $this->extraireComplementsOntologies($ontologie);
-
 
68
			$this->legende[$ontologie['code']] = $ontologie['legende'];
-
 
69
		}
-
 
70
	}
-
 
71
 
-
 
72
	private function extraireComplementsOntologies($ontologie) {
-
 
73
		$complements = explode(',', trim($ontologie['complements']));
-
 
74
		foreach ($complements as $complement) {
-
 
75
			list($cle, $val) = explode('=', trim($complement));
-
 
76
			$ontologie[trim($cle)] = trim($val);
-
 
77
		}
-
 
78
		return $ontologie;
46
	}
79
	}
47
 
80
 
48
	public function consulter($ressources, $parametres) {
81
	public function consulter($ressources, $parametres) {
49
		//$tpsDebut = microtime(true);
82
		//$tpsDebut = microtime(true);
Line 50... Line 83...
50
		$this->parametres = $parametres;
83
		$this->parametres = $parametres;
51
		$this->ressources = $ressources;
84
		$this->ressources = $ressources;
52
 
85
 
Line 53... Line 86...
53
		$this->definirValeurParDefautDesParametres();
86
		$this->definirValeurParDefautDesParametres();
-
 
87
		$this->verifierParametres();
54
		$this->verifierParametres();
88
		$this->analyserIdentifiant();
55
		$this->analyserIdentifiant();
89
 
56
 
90
		$resultat = new ResultatService();
57
		$resultat = new ResultatService();
91
		$this->chargerDonnees();
58
		if ($this->parametres['retour'] == self::MIME_SVG) {
92
		if ($this->parametres['retour'] == self::MIME_SVG) {
Line 149... Line 183...
149
		} else {
183
		} else {
150
			throw new Exception("A implémenter : carte proportionnelle ensemble des infos");
184
			throw new Exception("A implémenter : carte proportionnelle ensemble des infos");
151
		}
185
		}
152
	}
186
	}
Line 153... Line 187...
153
 
187
 
154
	private function genererSVG() {
188
	private function chargerDonnees() {
155
		$fichierCssBase = $this->cheminCartesBase.self::CARTE_DEFAUT.'.css';
189
		$refTax = self::CODE_REFTAX_DEFAUT;
156
		$css = file_get_contents($fichierCssBase);
-
 
Line 157... Line 190...
157
		$css .= ".departement2b{fill:#ff0000;}";
190
		$numNom = $this->Bdd->proteger($this->taxonsDemandes[$refTax]['nn'][0]);
158
 
191
 
159
		$idCss = $this->getIdFichierCss();
192
		$requete = 'SELECT * '.
160
		$fichierCss = $this->config['cache']['stockageChemin'].$idCss.'.css';
193
				'FROM chorodep_v2012_01 '.
Line -... Line 194...
-
 
194
				"WHERE num_nom IN ($numNom) ";
161
		file_put_contents($fichierCss, $css);
195
		$resultat = $this->Bdd->recupererTous($requete);
-
 
196
 
-
 
197
		if (!is_array($resultat) || count($resultat) <= 0) {
-
 
198
			$message = "Aucune donnée ne correspond à la ressource demandée";
-
 
199
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
200
			throw new Exception($message, $code);
Line -... Line 201...
-
 
201
		}
162
		$urlCss = sprintf($this->config['cssUrlTpl'], $idCss);
202
		$this->donnees = $resultat;
-
 
203
	}
-
 
204
 
-
 
205
	private function genererSVG() {
163
 
206
		$dom = new DOMDocument('1.0', 'UTF-8');
-
 
207
		$dom->validateOnParse = true;
164
		$fichierCarteSvg = $this->cheminCartesBase.self::CARTE_DEFAUT.'.svg';
208
 
165
 
209
		$fichierCarteSvg = $this->cheminCartesBase.self::CARTE_DEFAUT.'.svg';
-
 
210
		$dom->load($fichierCarteSvg);
-
 
211
 
-
 
212
		$racineElement = $dom->documentElement;
166
		$dom = new DOMDocument('1.0', 'UTF-8');
213
		$racineElement->setAttribute('width', $this->imgLargeur);
-
 
214
 
-
 
215
		$css = $this->creerCssCarte();
-
 
216
		$txtCss = $dom->createCDATASection($css);
-
 
217
		$dom->getElementsByTagName('style')->item(0)->appendChild($txtCss);
-
 
218
 
-
 
219
		$titre = $this->creerTitre();
-
 
220
		$titreCdata = $dom->createCDATASection($titre);
167
		$dom->load($fichierCarteSvg);
221
		$titreElement = $dom->getElementsByTagName('title')->item(0);
-
 
222
		$titreElement->nodeValue = '';
-
 
223
		$titreElement->appendChild($titreCdata);
-
 
224
 
-
 
225
		$taxonTitre = $this->creerTitreTaxon();
-
 
226
		$taxonCdata = $dom->createCDATASection($taxonTitre);
-
 
227
		$xpath = new DOMXPath($dom);
168
		$racineElement = $dom->documentElement;
228
		$taxonTitreEl = $xpath->query("//*[@id='titre-taxon']")->item(0);
169
		$racineElement->setAttribute('width', $this->imgLargeur);
229
		$taxonTitreEl->nodeValue = '';
170
		$piCss = $dom->createProcessingInstruction('xml-stylesheet', 'type="text/css" href="'.$urlCss.'"');
230
		$taxonTitreEl->appendChild($taxonCdata);
Line 171... Line 231...
171
		$dom->insertBefore($piCss, $racineElement);
231
 
172
		$svg = $dom->saveXML();
-
 
173
		return $svg;
232
		$svg = $dom->saveXML();
174
	}
-
 
175
 
-
 
176
	private function chargerDonnees() {
-
 
177
		$refTax = self::CODE_REFTAX_DEFAUT;
-
 
178
		$numNom = $this->Bdd->proteger($this->taxonsDemandes[$refTax]['nn'][0]);
-
 
179
 
-
 
180
		$requete = 'SELECT   '.
-
 
181
			'FROM cel_obs_images AS coi '.
233
		return $svg;
Line -... Line 234...
-
 
234
	}
182
			'	LEFT JOIN cel_inventory AS ci '.
235
 
183
					'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
236
	private function creerCssCarte() {
184
			'WHERE ci.transmission = 1 '.
237
		$fichierCssBase = $this->cheminCartesBase.self::CARTE_DEFAUT.'.css';
-
 
238
		$css = file_get_contents($fichierCssBase);
-
 
239
 
-
 
240
		$zonesCouleurs = $this->getZonesCouleurs();
-
 
241
		foreach ($zonesCouleurs as $couleur => $zonesClasses) {
-
 
242
			$classes = implode(', ', $zonesClasses);
-
 
243
			$css .= "$classes{\nfill:$couleur;\n}\n";
185
			"	AND ci.num_nom_ret IN ($numNom) ";
244
		}
-
 
245
		return $css;
-
 
246
	}
-
 
247
 
-
 
248
	private function getZonesCouleurs() {
-
 
249
		$zones = array();
-
 
250
		foreach ($this->donnees as $donnee) {
-
 
251
			foreach ($donnee as $champ => $valeur) {
-
 
252
				if (preg_match('/^[0-9][0-9ab]$/i', $champ)) {
186
		$resultat = $this->Bdd->recupererTous($requete);
253
					if (array_key_exists($valeur, $this->legende)) {
-
 
254
						$couleur = $this->legende[$valeur];
-
 
255
						$zones[$couleur][] = strtolower(".departement$champ");
Line -... Line 256...
-
 
256
					}
-
 
257
				}
-
 
258
			}
187
 
259
		}
Line 188... Line 260...
188
		if (!is_array($resultat) || count($resultat) <= 0) {
260
		return $zones;
-
 
261
	}
189
			$message = "Aucune donnée ne correspond à la ressource demandée";
262
 
-
 
263
	private function creerTitre() {
-
 
264
		$titre = "Carte en cours d'élaboration pour ".$this->creerTitreTaxon();
190
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
265
		return $titre;
191
			throw new Exception($message, $code);
266
	}
192
		}
267
 
Line 193... Line 268...
193
 
268
	private function creerTitreTaxon() {
194
	}
269
		$noms = array();
195
 
270
		foreach ($this->donnees as $donnee) {
Line 219... Line 294...
219
		$png = $convertisseur->getImageBlob();
294
		$png = $convertisseur->getImageBlob();
220
		$convertisseur->clear();
295
		$convertisseur->clear();
221
		$convertisseur->destroy();
296
		$convertisseur->destroy();
222
		return $png;
297
		return $png;
223
	}
298
	}
-
 
299
 
-
 
300
	public function getParametreTableau($cle) {
-
 
301
		$tableau = array();
-
 
302
		$parametre = $this->config[$cle];
-
 
303
		if (empty($parametre) === false) {
-
 
304
			$tableauPartiel = explode(',', $parametre);
-
 
305
			$tableauPartiel = array_map('trim', $tableauPartiel);
-
 
306
			foreach ($tableauPartiel as $champ) {
-
 
307
				if (strpos($champ, '=') === false) {
-
 
308
					$tableau[] = trim($champ);
-
 
309
				} else {
-
 
310
					list($cle, $val) = explode('=', $champ);
-
 
311
					$tableau[trim($cle)] = trim($val);
-
 
312
				}
-
 
313
			}
-
 
314
		}
-
 
315
		return $tableau;
-
 
316
	}
224
}
317
}
225
?>
318
?>
226
319