Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 420 → Rev 421

/trunk/services/modules/0.1/baseflor/Graphiques.php
15,27 → 15,33
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
*/
 
class Graphiques {
class Graphiques extends Commun{
 
private $parametres = array();
private $ressources = array();
protected $parametres = array();
protected $ressources = array();
private $metadonnees;
private $version;
private $Bdd;
private $nomGraphique = array();
private $table = "";
protected $table = "";
private $requete_condition = "";
private $requete_champs;
private $config;
private $convertisseur;
private $cheminGraphBase;
private $serviceNom = 'Graphiques';
protected $serviceNom = 'Graphiques';
private $valeurs_en_pourcentage ;
private $dom;
private $largeurSVG="500";
private $valeurs_champs;
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
"dix" => 1 );
private $champs_ontologiques = array ('ve_lumiere' => 'VEL', 've_temperature' => 'VET',
've_continentalite' => 'VEC', 've_humidite_atmos' => 'VEHA',
've_humidite_edaph' => 'VEHE', 've_reaction_sol' => 'VER' ,
've_nutriments_sol' => 'VEN', 've_salinite'=> 'VES' ,
've_texture_sol' => 'VETX', 've_mat_org_sol' => 'VEMO');
public function consulter($ressources, $parametres) {
$this->ressources = $ressources;
45,7 → 51,7
$this->table = Config::get('bdd_table')."_v".$this->version;
$this->traiterRessources();
$requete = $this->assemblerLaRequete();
$resultat = $this->Bdd->recupererTous($requete);
$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
$versionResultat = $this->obtenirResultat($resultat);
return $versionResultat;
}
191,10 → 197,8
}elseif ($resultat) {
if ((count($this->ressources)) != 0) {
$this->traiterValeursEcologiques($resultat[0]);
$i = 0;
$svg = $this->genererSVG();
$resultat = new ResultatService();
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
$resultat->mime = $this->parametres['retour'];
}
207,9 → 211,10
}
 
public function traiterValeursEcologiques($valeurs){
public function traiterValeursEcologiques($valeur){
$this->valeurs_champs = $valeur;
//humidite edaphique sur echelle de 12
foreach($valeurs as $cle => $val){
foreach($this->valeurs_champs as $cle => $val){
if ($cle == 've_humidite_edaph'){
$this->valeurs_en_pourcentage[$cle] = round($val/12,1);
}else{
228,7 → 233,7
//verifie que le xml est bien formé
$this->dom->validateOnParse = true;
$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
$res=$this->dom->load($fichierSvg);
$this->dom->load($fichierSvg);
$this->changerValeursSVG();
$svg = $this->dom->saveXML();
return $svg;
244,12 → 249,25
$pos_x = $element->getAttribute('x1');
$curseur = $Dompath->query("//*[@id='".$cle."']")->item(0);
$curseur->setAttribute('cx', $pos_x);
$this->ajouterInfoAuSurvol($curseur);
$svg = $this->dom->getElementsByTagName("svg")->item(0);
$svg->setAttribute('width',$this->largeurSVG);
}
}
private function convertirEnPNG($svg) {
public function ajouterInfoAuSurvol($curseur){
$champs = $curseur->getAttribute('id');
$valeurTexte = $this->recupererOntologies($this->valeurs_champs[$champs], $champs );
$curseur->setAttribute('title',$this->valeurs_champs[$champs].":".$valeurTexte->nom );
}
public function recupererOntologies($valeur, $champs){
$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
$val = $this->consulterHref($url);
return $val;
}
public function convertirEnPNG($svg) {
$png = null;
if (isset($this->convertisseur)) {
277,7 → 295,7
return $png;
}
private function convertirEnPNGAvecImageMagick($svg) {
public function convertirEnPNGAvecImageMagick($svg) {
$convertisseur = new Imagick();
$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
$convertisseur->readImageBlob($svg);
289,12 → 307,12
return $png;
}
private function convertirEnPNGAvecRsvg($svg) {
public function convertirEnPNGAvecRsvg($svg) {
$idFichier = $this->getIdFichier();
$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
file_put_contents($fichierSvg, $svg);
$commande = "rsvg-convert $fichierSvg --background-color=#f8f8f8 -w $this->largeurSVG -a -o $fichierPng";
$commande = "rsvg-convert $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
$rsvg = exec($commande);
$this->indexerFichierPng($fichierPng);
$png = file_get_contents($fichierPng);
301,13 → 319,13
return $png;
}
private function indexerFichierPng($fichierPng) {
public function indexerFichierPng($fichierPng) {
$img = imagecreatefrompng($fichierPng);
imagetruecolortopalette($img, false, 32);
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
}
private function getIdFichier(){
public function getIdFichier(){
$idfichier = str_replace(".","-",$this->ressources[1]);
$idfichier = str_replace(':','-',$idfichier);
$idfichier .= "-".$this->ressources[0];