| Line 30... |
Line 30... |
| 30 |
private $convertisseur;
|
30 |
private $convertisseur;
|
| 31 |
private $cheminGraphBase;
|
31 |
private $cheminGraphBase;
|
| 32 |
private $serviceNom = 'Graphiques';
|
32 |
private $serviceNom = 'Graphiques';
|
| 33 |
private $valeurs_en_pourcentage ;
|
33 |
private $valeurs_en_pourcentage ;
|
| 34 |
private $dom;
|
34 |
private $dom;
|
| 35 |
private $largeurSVG;
|
35 |
private $largeurSVG="500";
|
| 36 |
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
|
36 |
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
|
| 37 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
37 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
| 38 |
"dix" => 1 );
|
38 |
"dix" => 1 );
|
| Line 39... |
Line 39... |
| 39 |
|
39 |
|
| 40 |
public function consulter($ressources, $parametres) {
|
40 |
public function consulter($ressources, $parametres) {
|
| 41 |
$this->ressources = $ressources;
|
41 |
$this->ressources = $ressources;
|
| 42 |
$this->parametres = $parametres;
|
42 |
$this->parametres = $parametres;
|
| 43 |
$this->initialiserConfiguration();
|
43 |
$this->initialiserConfiguration();
|
| 44 |
$resultats = '';
|
- |
|
| 45 |
|
44 |
$resultats = '';
|
| 46 |
$this->table = Config::get('bdd_table')."_v".$this->version;
|
45 |
$this->table = Config::get('bdd_table')."_v".$this->version;
|
| 47 |
$this->traiterRessources();
|
46 |
$this->traiterRessources();
|
| 48 |
$requete = $this->assemblerLaRequete();
|
47 |
$requete = $this->assemblerLaRequete();
|
| 49 |
$resultat = $this->Bdd->recupererTous($requete);
|
48 |
$resultat = $this->Bdd->recupererTous($requete);
|
| Line 57... |
Line 56... |
| 57 |
$conteneur = new Conteneur();
|
56 |
$conteneur = new Conteneur();
|
| 58 |
$this->Bdd = $conteneur->getBdd();
|
57 |
$this->Bdd = $conteneur->getBdd();
|
| 59 |
$this->config = $conteneur->getParametre('Graphiques');
|
58 |
$this->config = $conteneur->getParametre('Graphiques');
|
| 60 |
$this->convertisseur = $this->config['convertisseur'];
|
59 |
$this->convertisseur = $this->config['convertisseur'];
|
| 61 |
$this->cheminGraphBase = $this->config['chemin'];
|
60 |
$this->cheminGraphBase = $this->config['chemin'];
|
| - |
|
61 |
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
|
| - |
|
62 |
'stockage_chemin' => $this->config['cache']['stockageChemin'],
|
| - |
|
63 |
'duree_de_vie' => $this->config['cache']['dureeDeVie']);
|
| - |
|
64 |
$this->cache = $conteneur->getCacheSimple($cacheOptions);
|
| 62 |
$this->chargerVersions();
|
65 |
$this->chargerVersions();
|
| 63 |
$this->definirVersion();
|
66 |
$this->definirVersion();
|
| 64 |
$this->definirTailleSVG();
|
67 |
$this->definirFormat();
|
| 65 |
}
|
68 |
}
|
| Line 66... |
Line 69... |
| 66 |
|
69 |
|
| 67 |
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
|
70 |
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
|
| 68 |
private function definirVersion() {
|
71 |
private function definirVersion() {
|
| Line 72... |
Line 75... |
| 72 |
} else {
|
75 |
} else {
|
| 73 |
$this->version = $this->parametres['version.projet'];
|
76 |
$this->version = $this->parametres['version.projet'];
|
| 74 |
}
|
77 |
}
|
| 75 |
}
|
78 |
}
|
| Line 76... |
Line 79... |
| 76 |
|
79 |
|
| 77 |
private function definirTailleSVG() {
|
80 |
private function definirFormat() {
|
| - |
|
81 |
if (isset($this->parametres['retour.format']) ){
|
| 78 |
if (!isset($this->parametres['retour.format']) ){
|
82 |
if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
|
| 79 |
$this->largeurSVG="500";
|
83 |
$this->largeurSVG= $this->parametres['retour.format'];
|
| - |
|
84 |
}else {
|
| - |
|
85 |
$erreur = "Erreur : Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
|
| - |
|
86 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
| - |
|
87 |
throw new Exception($erreur, $code);
|
| - |
|
88 |
}
|
| 80 |
} else {
|
89 |
}
|
| - |
|
90 |
if (!isset($this->parametres['retour']) ){
|
| - |
|
91 |
$this->parametres['retour'] = 'image/svg+xml';
|
| - |
|
92 |
}else {
|
| - |
|
93 |
if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
|
| - |
|
94 |
$erreur = "Erreur : choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
|
| - |
|
95 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
| - |
|
96 |
throw new Exception($erreur, $code);
|
| 81 |
$this->largeurSVG= $this->parametres['retour.format'];
|
97 |
}
|
| 82 |
}
|
98 |
}
|
| Line -... |
Line 99... |
| - |
|
99 |
}
|
| - |
|
100 |
|
| 83 |
}
|
101 |
|
| 84 |
|
102 |
|
| 85 |
private function chargerVersions() {
|
103 |
private function chargerVersions() {
|
| 86 |
$requete = "SELECT version ".
|
104 |
$requete = "SELECT version ".
|
| 87 |
"FROM ".Config::get('bdd_table_meta')." ".
|
105 |
"FROM ".Config::get('bdd_table_meta')." ".
|
| Line 174... |
Line 192... |
| 174 |
if ((count($this->ressources)) != 0) {
|
192 |
if ((count($this->ressources)) != 0) {
|
| 175 |
$this->traiterValeursEcologiques($resultat[0]);
|
193 |
$this->traiterValeursEcologiques($resultat[0]);
|
| 176 |
$i = 0;
|
194 |
$i = 0;
|
| 177 |
$svg = $this->genererSVG();
|
195 |
$svg = $this->genererSVG();
|
| 178 |
$resultat = new ResultatService();
|
196 |
$resultat = new ResultatService();
|
| - |
|
197 |
|
| 179 |
$resultat->corps = $svg;
|
198 |
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
|
| 180 |
$resultat->mime = 'image/svg+xml';
|
199 |
$resultat->mime = $this->parametres['retour'];
|
| 181 |
}
|
200 |
}
|
| 182 |
} else {
|
201 |
} else {
|
| 183 |
$message = 'Les données recherchées sont introuvables.';
|
202 |
$message = 'Les données recherchées sont introuvables.';
|
| 184 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
203 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
| 185 |
throw new Exception($message, $code);
|
204 |
throw new Exception($message, $code);
|
| 186 |
}
|
205 |
}
|
| Line 228... |
Line 247... |
| 228 |
$svg = $this->dom->getElementsByTagName("svg")->item(0);
|
247 |
$svg = $this->dom->getElementsByTagName("svg")->item(0);
|
| 229 |
$svg->setAttribute('width',$this->largeurSVG);
|
248 |
$svg->setAttribute('width',$this->largeurSVG);
|
| 230 |
}
|
249 |
}
|
| 231 |
}
|
250 |
}
|
| Line -... |
Line 251... |
| - |
|
251 |
|
| - |
|
252 |
private function convertirEnPNG($svg) {
|
| - |
|
253 |
$png = null;
|
| - |
|
254 |
|
| - |
|
255 |
if (isset($this->convertisseur)) {
|
| - |
|
256 |
if ($this->convertisseur == 'imagick') {
|
| - |
|
257 |
if (extension_loaded('imagick')) {
|
| - |
|
258 |
$png = $this->convertirEnPNGAvecImageMagick($svg);
|
| - |
|
259 |
} else {
|
| - |
|
260 |
$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
|
| - |
|
261 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| - |
|
262 |
throw new Exception($message, $code);
|
| - |
|
263 |
}
|
| - |
|
264 |
} else if ($this->convertisseur == 'rsvg') {
|
| - |
|
265 |
$png = $this->convertirEnPNGAvecRsvg($svg);
|
| - |
|
266 |
} else {
|
| - |
|
267 |
$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
|
| - |
|
268 |
"des convertisseurs disponibles : imagick, rsvg.";
|
| - |
|
269 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| - |
|
270 |
throw new Exception($message, $code);
|
| - |
|
271 |
}
|
| - |
|
272 |
} else {
|
| - |
|
273 |
$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
|
| - |
|
274 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| - |
|
275 |
throw new Exception($message, $code);
|
| - |
|
276 |
}
|
| - |
|
277 |
return $png;
|
| - |
|
278 |
}
|
| - |
|
279 |
|
| - |
|
280 |
private function convertirEnPNGAvecImageMagick($svg) {
|
| - |
|
281 |
$convertisseur = new Imagick();
|
| - |
|
282 |
$convertisseur->setBackgroundColor(new ImagickPixel('transparent'));
|
| - |
|
283 |
$convertisseur->readImageBlob($svg);
|
| - |
|
284 |
$convertisseur->setImageFormat('png32');
|
| - |
|
285 |
$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
|
| - |
|
286 |
$png = $convertisseur->getImageBlob();
|
| - |
|
287 |
$convertisseur->clear();
|
| - |
|
288 |
$convertisseur->destroy();
|
| - |
|
289 |
return $png;
|
| - |
|
290 |
}
|
| - |
|
291 |
|
| - |
|
292 |
private function convertirEnPNGAvecRsvg($svg) {
|
| - |
|
293 |
$idFichier = $this->getIdFichier();
|
| - |
|
294 |
$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
|
| - |
|
295 |
$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
|
| - |
|
296 |
file_put_contents($fichierSvg, $svg);
|
| - |
|
297 |
$commande = "rsvg-convert $fichierSvg -d 75 -p 75 -o $fichierPng";
|
| - |
|
298 |
$rsvg = exec($commande);
|
| - |
|
299 |
$this->indexerFichierPng($fichierPng);
|
| - |
|
300 |
$png = file_get_contents($fichierPng);
|
| - |
|
301 |
return $png;
|
| - |
|
302 |
}
|
| - |
|
303 |
|
| - |
|
304 |
private function indexerFichierPng($fichierPng) {
|
| - |
|
305 |
$img = imagecreatefrompng($fichierPng);
|
| - |
|
306 |
imagetruecolortopalette($img, false, 32);
|
| - |
|
307 |
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
|
| - |
|
308 |
}
|
| - |
|
309 |
|
| - |
|
310 |
private function getIdFichier(){
|
| - |
|
311 |
$idfichier = str_replace(".","-",$this->ressources[1]);
|
| - |
|
312 |
$idfichier = str_replace(':','-',$idfichier);
|
| - |
|
313 |
return $idfichier;
|
| 232 |
|
314 |
}
|
| Line 233... |
Line 315... |
| 233 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
315 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
| 234 |
|
316 |
|
| 235 |
public function assemblerLaRequete() {
|
317 |
public function assemblerLaRequete() {
|