48,8 → 48,8 |
private $retour = self::MIME_MAP; |
private $methode_livraison = self::METHODE_AFFICHAGE; |
private $erreurs = array(); |
|
|
|
public function consulter($ressources, $parametres) { |
$this->parametres = $parametres; |
$this->ressources = $ressources; |
59,7 → 59,7 |
$resultat = $this->formerLegende(); |
} else { |
$this->traiterParametres(); |
$resultat = $this->formerCarte(); |
$resultat = $this->obtenirCarte(); |
if($this->methode_livraison == self::METHODE_TELECHARGEMENT) { |
$this->telechargerCarte($resultat->corps); |
} |
228,8 → 228,58 |
} |
return $nomTable; |
} |
|
private function formerCarte() { |
|
/** |
* Va chercher la carte dans le cache si elle existe et n'a pas dépassé la durée |
* de vie $this->dureeCache; sinon, crée la carte et la met en cache |
*/ |
protected function obtenirCarte() { |
$carte = null; |
$cacheActif = Config::get('cache_miseEnCache'); |
$cheminCache = Config::get('cache_stockageChemin'); |
$cheminCarteEnCache = $cheminCache . $this->referentiel . "-nn-" . $this->taxon['num_nom'] . ".svg"; |
|
// le cache est-il actif ? |
if ($cacheActif) { |
// le fichier existe-t-il en cache ? |
//echo "Chemin fichier: $cheminCarteEnCache<br/>"; |
if (file_exists($cheminCarteEnCache)) { |
$limiteDuree = Config::get('cache_dureeDeVie'); // pour ne pas trop faire pipi |
$dateFichier = filectime($cheminCarteEnCache); |
$age = time() - $dateFichier; |
// est-il suffisamment récent ? |
if ($age < $limiteDuree) { |
// récupérer le fichier en cache |
$carte = file_get_contents($cheminCarteEnCache); |
} else { |
// détruire le fichier obsolète |
unlink($cheminCarteEnCache); |
} |
} |
} |
// si la carte n'a pas été trouvée en cache |
if ($carte === null) { |
// calculer la nouvelle carte |
$carte = $this->formerCarte(); |
// mettre la nouvelle carte en cache |
if ($cacheActif) { |
file_put_contents($cheminCarteEnCache, $carte); |
} |
} |
|
// retour du service |
$resultat = new ResultatService(); |
$resultat->mime = $this->retour; |
$resultat->corps = $carte; |
|
return $resultat; |
} |
|
/** |
* Crée la carte - prend beaucoup de temps |
* @return ResultatService |
*/ |
protected function formerCarte() { |
$suffixe = 'france_moissonnage'; |
|
// le fichier png avec les départements est illisible en petit format |
243,10 → 293,8 |
|
$formateur = new FormateurSVG($nomFichierSVG, $this->sources, $this->retour, $this->format); |
$formateur->formaterCarte($this->taxon); |
$resultat = new ResultatService(); |
$resultat->corps = $formateur->renvoyerCarte(); |
$resultat->mime = $this->retour; |
|
$resultat = $formateur->renvoyerCarte(); |
return $resultat; |
} |
|