| Line 13... |
Line 13... |
| 13 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
13 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
| 14 |
* @version 1.0
|
14 |
* @version 1.0
|
| 15 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
15 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
| 16 |
*/
|
16 |
*/
|
| Line 17... |
Line 17... |
| 17 |
|
17 |
|
| Line 18... |
Line 18... |
| 18 |
class Graphiques {
|
18 |
class Graphiques extends Commun{
|
| 19 |
|
19 |
|
| 20 |
private $parametres = array();
|
20 |
protected $parametres = array();
|
| 21 |
private $ressources = array();
|
21 |
protected $ressources = array();
|
| 22 |
private $metadonnees;
|
22 |
private $metadonnees;
|
| 23 |
private $version;
|
23 |
private $version;
|
| 24 |
private $Bdd;
|
24 |
private $Bdd;
|
| 25 |
private $nomGraphique = array();
|
25 |
private $nomGraphique = array();
|
| 26 |
private $table = "";
|
26 |
protected $table = "";
|
| 27 |
private $requete_condition = "";
|
27 |
private $requete_condition = "";
|
| 28 |
private $requete_champs;
|
28 |
private $requete_champs;
|
| 29 |
private $config;
|
29 |
private $config;
|
| 30 |
private $convertisseur;
|
30 |
private $convertisseur;
|
| 31 |
private $cheminGraphBase;
|
31 |
private $cheminGraphBase;
|
| 32 |
private $serviceNom = 'Graphiques';
|
32 |
protected $serviceNom = 'Graphiques';
|
| 33 |
private $valeurs_en_pourcentage ;
|
33 |
private $valeurs_en_pourcentage ;
|
| - |
|
34 |
private $dom;
|
| 34 |
private $dom;
|
35 |
private $largeurSVG="500";
|
| 35 |
private $largeurSVG="500";
|
36 |
private $valeurs_champs;
|
| 36 |
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
|
37 |
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
|
| - |
|
38 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
| - |
|
39 |
"dix" => 1 );
|
| - |
|
40 |
private $champs_ontologiques = array ('ve_lumiere' => 'VEL', 've_temperature' => 'VET',
|
| - |
|
41 |
've_continentalite' => 'VEC', 've_humidite_atmos' => 'VEHA',
|
| - |
|
42 |
've_humidite_edaph' => 'VEHE', 've_reaction_sol' => 'VER' ,
|
| Line 37... |
Line 43... |
| 37 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
43 |
've_nutriments_sol' => 'VEN', 've_salinite'=> 'VES' ,
|
| 38 |
"dix" => 1 );
|
44 |
've_texture_sol' => 'VETX', 've_mat_org_sol' => 'VEMO');
|
| 39 |
|
45 |
|
| 40 |
public function consulter($ressources, $parametres) {
|
46 |
public function consulter($ressources, $parametres) {
|
| 41 |
$this->ressources = $ressources;
|
47 |
$this->ressources = $ressources;
|
| 42 |
$this->parametres = $parametres;
|
48 |
$this->parametres = $parametres;
|
| 43 |
$this->initialiserConfiguration();
|
49 |
$this->initialiserConfiguration();
|
| 44 |
$resultats = '';
|
50 |
$resultats = '';
|
| 45 |
$this->table = Config::get('bdd_table')."_v".$this->version;
|
51 |
$this->table = Config::get('bdd_table')."_v".$this->version;
|
| 46 |
$this->traiterRessources();
|
52 |
$this->traiterRessources();
|
| 47 |
$requete = $this->assemblerLaRequete();
|
53 |
$requete = $this->assemblerLaRequete();
|
| 48 |
$resultat = $this->Bdd->recupererTous($requete);
|
54 |
$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
|
| Line 49... |
Line 55... |
| 49 |
$versionResultat = $this->obtenirResultat($resultat);
|
55 |
$versionResultat = $this->obtenirResultat($resultat);
|
| Line 189... |
Line 195... |
| 189 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
195 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
| 190 |
throw new Exception($message, $code);
|
196 |
throw new Exception($message, $code);
|
| 191 |
}elseif ($resultat) {
|
197 |
}elseif ($resultat) {
|
| 192 |
if ((count($this->ressources)) != 0) {
|
198 |
if ((count($this->ressources)) != 0) {
|
| 193 |
$this->traiterValeursEcologiques($resultat[0]);
|
199 |
$this->traiterValeursEcologiques($resultat[0]);
|
| 194 |
$i = 0;
|
- |
|
| 195 |
$svg = $this->genererSVG();
|
200 |
$svg = $this->genererSVG();
|
| 196 |
$resultat = new ResultatService();
|
201 |
$resultat = new ResultatService();
|
| 197 |
|
- |
|
| 198 |
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
|
202 |
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
|
| 199 |
$resultat->mime = $this->parametres['retour'];
|
203 |
$resultat->mime = $this->parametres['retour'];
|
| 200 |
}
|
204 |
}
|
| 201 |
} else {
|
205 |
} else {
|
| 202 |
$message = 'Les données recherchées sont introuvables.';
|
206 |
$message = 'Les données recherchées sont introuvables.';
|
| Line 205... |
Line 209... |
| 205 |
}
|
209 |
}
|
| 206 |
return $resultat;
|
210 |
return $resultat;
|
| 207 |
}
|
211 |
}
|
| Line 208... |
Line 212... |
| 208 |
|
212 |
|
| - |
|
213 |
|
| 209 |
|
214 |
public function traiterValeursEcologiques($valeur){
|
| 210 |
public function traiterValeursEcologiques($valeurs){
|
215 |
$this->valeurs_champs = $valeur;
|
| 211 |
//humidite edaphique sur echelle de 12
|
216 |
//humidite edaphique sur echelle de 12
|
| 212 |
foreach($valeurs as $cle => $val){
|
217 |
foreach($this->valeurs_champs as $cle => $val){
|
| 213 |
if ($cle == 've_humidite_edaph'){
|
218 |
if ($cle == 've_humidite_edaph'){
|
| 214 |
$this->valeurs_en_pourcentage[$cle] = round($val/12,1);
|
219 |
$this->valeurs_en_pourcentage[$cle] = round($val/12,1);
|
| 215 |
}else{
|
220 |
}else{
|
| Line 226... |
Line 231... |
| 226 |
public function genererSVG(){
|
231 |
public function genererSVG(){
|
| 227 |
$this->dom = new DOMDocument('1.0', 'UTF-8');
|
232 |
$this->dom = new DOMDocument('1.0', 'UTF-8');
|
| 228 |
//verifie que le xml est bien formé
|
233 |
//verifie que le xml est bien formé
|
| 229 |
$this->dom->validateOnParse = true;
|
234 |
$this->dom->validateOnParse = true;
|
| 230 |
$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
|
235 |
$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
|
| 231 |
$res=$this->dom->load($fichierSvg);
|
236 |
$this->dom->load($fichierSvg);
|
| 232 |
$this->changerValeursSVG();
|
237 |
$this->changerValeursSVG();
|
| 233 |
$svg = $this->dom->saveXML();
|
238 |
$svg = $this->dom->saveXML();
|
| 234 |
return $svg;
|
239 |
return $svg;
|
| 235 |
}
|
240 |
}
|
| Line 242... |
Line 247... |
| 242 |
$Dompath = new DOMXPath($this->dom);
|
247 |
$Dompath = new DOMXPath($this->dom);
|
| 243 |
$element = $Dompath->query("//*[@id='".$grad_id."']")->item(0);
|
248 |
$element = $Dompath->query("//*[@id='".$grad_id."']")->item(0);
|
| 244 |
$pos_x = $element->getAttribute('x1');
|
249 |
$pos_x = $element->getAttribute('x1');
|
| 245 |
$curseur = $Dompath->query("//*[@id='".$cle."']")->item(0);
|
250 |
$curseur = $Dompath->query("//*[@id='".$cle."']")->item(0);
|
| 246 |
$curseur->setAttribute('cx', $pos_x);
|
251 |
$curseur->setAttribute('cx', $pos_x);
|
| - |
|
252 |
$this->ajouterInfoAuSurvol($curseur);
|
| 247 |
$svg = $this->dom->getElementsByTagName("svg")->item(0);
|
253 |
$svg = $this->dom->getElementsByTagName("svg")->item(0);
|
| 248 |
$svg->setAttribute('width',$this->largeurSVG);
|
254 |
$svg->setAttribute('width',$this->largeurSVG);
|
| 249 |
}
|
255 |
}
|
| 250 |
}
|
256 |
}
|
| Line -... |
Line 257... |
| - |
|
257 |
|
| - |
|
258 |
public function ajouterInfoAuSurvol($curseur){
|
| - |
|
259 |
$champs = $curseur->getAttribute('id');
|
| - |
|
260 |
$valeurTexte = $this->recupererOntologies($this->valeurs_champs[$champs], $champs );
|
| - |
|
261 |
$curseur->setAttribute('title',$this->valeurs_champs[$champs].":".$valeurTexte->nom );
|
| - |
|
262 |
}
|
| - |
|
263 |
|
| - |
|
264 |
public function recupererOntologies($valeur, $champs){
|
| - |
|
265 |
$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
|
| - |
|
266 |
$val = $this->consulterHref($url);
|
| - |
|
267 |
return $val;
|
| - |
|
268 |
}
|
| 251 |
|
269 |
|
| 252 |
private function convertirEnPNG($svg) {
|
270 |
public function convertirEnPNG($svg) {
|
| Line 253... |
Line 271... |
| 253 |
$png = null;
|
271 |
$png = null;
|
| 254 |
|
272 |
|
| 255 |
if (isset($this->convertisseur)) {
|
273 |
if (isset($this->convertisseur)) {
|
| Line 275... |
Line 293... |
| 275 |
throw new Exception($message, $code);
|
293 |
throw new Exception($message, $code);
|
| 276 |
}
|
294 |
}
|
| 277 |
return $png;
|
295 |
return $png;
|
| 278 |
}
|
296 |
}
|
| Line 279... |
Line 297... |
| 279 |
|
297 |
|
| 280 |
private function convertirEnPNGAvecImageMagick($svg) {
|
298 |
public function convertirEnPNGAvecImageMagick($svg) {
|
| 281 |
$convertisseur = new Imagick();
|
299 |
$convertisseur = new Imagick();
|
| 282 |
$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
|
300 |
$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
|
| 283 |
$convertisseur->readImageBlob($svg);
|
301 |
$convertisseur->readImageBlob($svg);
|
| 284 |
$convertisseur->setImageFormat('png32');
|
302 |
$convertisseur->setImageFormat('png32');
|
| Line 287... |
Line 305... |
| 287 |
$convertisseur->clear();
|
305 |
$convertisseur->clear();
|
| 288 |
$convertisseur->destroy();
|
306 |
$convertisseur->destroy();
|
| 289 |
return $png;
|
307 |
return $png;
|
| 290 |
}
|
308 |
}
|
| Line 291... |
Line 309... |
| 291 |
|
309 |
|
| 292 |
private function convertirEnPNGAvecRsvg($svg) {
|
310 |
public function convertirEnPNGAvecRsvg($svg) {
|
| 293 |
$idFichier = $this->getIdFichier();
|
311 |
$idFichier = $this->getIdFichier();
|
| 294 |
$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
|
312 |
$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
|
| 295 |
$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
|
313 |
$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
|
| 296 |
file_put_contents($fichierSvg, $svg);
|
314 |
file_put_contents($fichierSvg, $svg);
|
| 297 |
$commande = "rsvg-convert $fichierSvg --background-color=#f8f8f8 -w $this->largeurSVG -a -o $fichierPng";
|
315 |
$commande = "rsvg-convert $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
|
| 298 |
$rsvg = exec($commande);
|
316 |
$rsvg = exec($commande);
|
| 299 |
$this->indexerFichierPng($fichierPng);
|
317 |
$this->indexerFichierPng($fichierPng);
|
| 300 |
$png = file_get_contents($fichierPng);
|
318 |
$png = file_get_contents($fichierPng);
|
| 301 |
return $png;
|
319 |
return $png;
|
| Line 302... |
Line 320... |
| 302 |
}
|
320 |
}
|
| 303 |
|
321 |
|
| 304 |
private function indexerFichierPng($fichierPng) {
|
322 |
public function indexerFichierPng($fichierPng) {
|
| 305 |
$img = imagecreatefrompng($fichierPng);
|
323 |
$img = imagecreatefrompng($fichierPng);
|
| 306 |
imagetruecolortopalette($img, false, 32);
|
324 |
imagetruecolortopalette($img, false, 32);
|
| Line 307... |
Line 325... |
| 307 |
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
|
325 |
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
|
| 308 |
}
|
326 |
}
|
| 309 |
|
327 |
|
| 310 |
private function getIdFichier(){
|
328 |
public function getIdFichier(){
|
| 311 |
$idfichier = str_replace(".","-",$this->ressources[1]);
|
329 |
$idfichier = str_replace(".","-",$this->ressources[1]);
|
| 312 |
$idfichier = str_replace(':','-',$idfichier);
|
330 |
$idfichier = str_replace(':','-',$idfichier);
|