Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 1036 Rev 1134
Line 46... Line 46...
46
	private $sources = array();
46
	private $sources = array();
47
	private $format  = 0;
47
	private $format  = 0;
48
	private $retour  = self::MIME_MAP;
48
	private $retour  = self::MIME_MAP;
49
	private $methode_livraison = self::METHODE_AFFICHAGE;
49
	private $methode_livraison = self::METHODE_AFFICHAGE;
50
	private $erreurs = array();
50
	private $erreurs = array();
51
	
51
 
Line 52... Line 52...
52
	
52
	
53
	public function consulter($ressources, $parametres) {
53
	public function consulter($ressources, $parametres) {
54
		$this->parametres = $parametres;
54
		$this->parametres = $parametres;
55
		$this->ressources = $ressources;
55
		$this->ressources = $ressources;
56
		$resultat = null;
56
		$resultat = null;
57
		$this->chargerClassesSousDossier();
57
		$this->chargerClassesSousDossier();
58
		if ($this->analyserRessources() == true) {
58
		if ($this->analyserRessources() == true) {
59
			$resultat = $this->formerLegende();
59
			$resultat = $this->formerLegende();
60
		} else {
60
		} else {
61
			$this->traiterParametres();
61
			$this->traiterParametres();
62
			$resultat = $this->formerCarte();
62
			$resultat = $this->obtenirCarte();
63
			if($this->methode_livraison == self::METHODE_TELECHARGEMENT) {
63
			if($this->methode_livraison == self::METHODE_TELECHARGEMENT) {
64
				$this->telechargerCarte($resultat->corps);
64
				$this->telechargerCarte($resultat->corps);
65
			}
65
			}
66
		}
66
		}
Line 226... Line 226...
226
				$nomTable = $table;
226
				$nomTable = $table;
227
			}
227
			}
228
		}
228
		}
229
		return $nomTable;
229
		return $nomTable;
230
	}
230
	}
-
 
231
 
-
 
232
	/**
-
 
233
	 * Va chercher la carte dans le cache si elle existe et n'a pas dépassé la durée
-
 
234
	 * de vie $this->dureeCache; sinon, crée la carte et la met en cache
-
 
235
	 */
-
 
236
	protected function obtenirCarte() {
-
 
237
		$carte = null;
-
 
238
		$cacheActif = Config::get('cache_miseEnCache');
-
 
239
		$cheminCache = Config::get('cache_stockageChemin');
-
 
240
		$cheminCarteEnCache = $cheminCache . $this->referentiel . "-nn-" . $this->taxon['num_nom'] . ".svg";
-
 
241
 
-
 
242
		// le cache est-il actif ?
-
 
243
		if ($cacheActif) {
-
 
244
			// le fichier existe-t-il en cache ?
-
 
245
			//echo "Chemin fichier: $cheminCarteEnCache<br/>";
-
 
246
			if (file_exists($cheminCarteEnCache)) {
-
 
247
				$limiteDuree = Config::get('cache_dureeDeVie'); // pour ne pas trop faire pipi
-
 
248
				$dateFichier = filectime($cheminCarteEnCache);
-
 
249
				$age = time() - $dateFichier;
-
 
250
				// est-il suffisamment récent ?
-
 
251
				if ($age < $limiteDuree) {
-
 
252
					// récupérer le fichier en cache
-
 
253
					$carte = file_get_contents($cheminCarteEnCache);
-
 
254
				} else {
-
 
255
					// détruire le fichier obsolète
-
 
256
					unlink($cheminCarteEnCache);
-
 
257
				}
-
 
258
			}
-
 
259
		}
-
 
260
		// si la carte n'a pas été trouvée en cache
-
 
261
		if ($carte === null) {
-
 
262
			// calculer la nouvelle carte
-
 
263
			$carte = $this->formerCarte();
-
 
264
			// mettre la nouvelle carte en cache
-
 
265
			if ($cacheActif) {
-
 
266
				file_put_contents($cheminCarteEnCache, $carte);
-
 
267
			}
-
 
268
		}
-
 
269
 
-
 
270
		// retour du service
-
 
271
		$resultat = new ResultatService();
-
 
272
		$resultat->mime = $this->retour;
-
 
273
		$resultat->corps = $carte;
-
 
274
 
-
 
275
		return $resultat;
-
 
276
	}
231
	
277
 
-
 
278
	/**
-
 
279
	 * Crée la carte - prend beaucoup de temps
-
 
280
	 * @return ResultatService
-
 
281
	 */
232
	private function formerCarte() {
282
	protected function formerCarte() {
233
		$suffixe = 'france_moissonnage';
283
		$suffixe = 'france_moissonnage';
Line 234... Line 284...
234
		
284
		
235
		// le fichier png avec les départements est illisible en petit format
285
		// le fichier png avec les départements est illisible en petit format
236
		// dans ce cas là un template plus simple est utilisé (sans les départements)
286
		// dans ce cas là un template plus simple est utilisé (sans les départements)
Line 241... Line 291...
241
		$nomFichierSVG = Config::get('chemin')."{$suffixe}.svg";
291
		$nomFichierSVG = Config::get('chemin')."{$suffixe}.svg";
242
		$this->verifierExistenceFichier($nomFichierSVG);
292
		$this->verifierExistenceFichier($nomFichierSVG);
Line 243... Line 293...
243
		
293
		
244
		$formateur = new FormateurSVG($nomFichierSVG, $this->sources, $this->retour, $this->format);
294
		$formateur = new FormateurSVG($nomFichierSVG, $this->sources, $this->retour, $this->format);
245
		$formateur->formaterCarte($this->taxon);
-
 
246
		$resultat = new ResultatService();
-
 
247
		$resultat->corps = $formateur->renvoyerCarte();
-
 
Line -... Line 295...
-
 
295
		$formateur->formaterCarte($this->taxon);
248
		$resultat->mime = $this->retour;
296
 
249
 
297
		$resultat = $formateur->renvoyerCarte();
Line 250... Line 298...
250
		return $resultat;
298
		return $resultat;
251
	}
299
	}