Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 915 → Rev 916

/trunk/services/modules/0.1/baseflor/CommunGraphiques.php
3,8 → 3,8
/**
* Classe CommunGraphiques.php regroupement de fonctions pour les graphiques
* graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
*
*
*
* @package eflore-projets
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
15,10 → 15,10
*/
 
abstract class CommunGraphiques extends Commun{
 
protected $parametres = array();
protected $ressources = array();
 
protected $Bdd;
protected $config;
protected $cache;
25,15 → 25,15
protected $metadonnees;
protected $version;
protected $serviceNom = 'Graphiques';
 
protected $graduations_id = array();
protected $champs_ontologiques = array();
protected $nomGraphique = array();
 
protected $table = '';
protected $requete_condition = "";
protected $requete_champs;
 
protected $convertisseur;
protected $cheminGraphBase;
protected $valeurs_en_pourcentage = array();
41,9 → 41,9
protected $largeurSVG = "500";
protected $hauteurSVG;
protected $valeurs_champs;
 
 
 
public function consulter($ressources, $parametres) {
$this->ressources = $ressources;
$this->parametres = $parametres;
56,10 → 56,10
$versionResultat = $this->obtenirResultat($resultat);
return $versionResultat;
}
 
 
//+--------------------------initialisation de paramètres -------------------------------------------+
 
private function initialiserConfiguration() {
$conteneur = new Conteneur();
$this->Bdd = $conteneur->getBdd();
69,19 → 69,19
$this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques');
$this->cheminGraphBase = $this->config['chemin'];
$cacheOptions = array('mise_en_cache' => $this->config['cache_miseEnCache'],
'stockage_chemin' => $this->config['cache_stockageChemin'],
'duree_de_vie' => $this->config['cache_dureeDeVie']);
'stockage_chemin' => $this->config['cache_stockageChemin'],
'duree_de_vie' => $this->config['cache_dureeDeVie']);
$this->cache = $conteneur->getCacheSimple($cacheOptions);
$this->definirVersion();
$this->definirFormat();
$this->definirTable($this->version);
}
 
 
 
abstract function definirTable($version);
 
 
private function getParametreTableau($cle) {
$tableau = array();
$parametre = Config::get($cle);
101,9 → 101,9
}
 
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
 
//+---- paramètres ----+
 
private function verifierParametres() {
if (isset($this->parametres)) {
$parametres_dispo = array('retour', 'retour.format', 'version.projet');
116,11 → 116,11
}
}
}
 
}
 
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
private function definirVersion() {
private function definirVersion() {
$this->chargerVersions();
if (!isset($this->parametres['version.projet']) ) {
$this->version = $this->metadonnees[0]['version'];
136,7 → 136,7
}
}
}
 
private function verifierVersion($version){
$retour = false;
foreach ($this->metadonnees as $vers) {
164,7 → 164,7
}
if (!isset($this->parametres['retour']) ){
$this->parametres['retour'] = 'image/svg+xml';
 
}else {
if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
$erreur = "Erreur : valeur inconnue. Choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
173,9 → 173,9
}
}
}
 
 
 
private function chargerVersions() {
$requete = "SELECT version ".
"FROM ".Config::get('bdd_table_meta')." ".
186,13 → 186,13
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
 
$this->metadonnees = $resultats;
}
 
//+----- ressources -----+
 
 
public function traiterRessources() {
if(isset($this->ressources)) {
$this->traiterTypeGraphique();
202,17 → 202,17
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
}
 
abstract function traiterReferentielEtNum();
abstract function traiterTypeGraphique();
 
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
 
public function assemblerLaRequete() {
$requete = ' SELECT '.$this->requete_champs.' FROM '.$this->table.' '.$this->retournerRequeteCondition();
return $requete;
}
 
public function retournerRequeteCondition() {
$condition = '';
if ($this->requete_condition !== "") {
220,7 → 220,7
}
return $condition;
}
 
//+-------------------------- formatage du résultat -------------------------------------------+
 
public function obtenirResultat($resultat) {
243,7 → 243,7
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
$resultat->mime = $this->parametres['retour'];
} else {
$resultat = null;
$resultat = null;
}
}
} else {
251,17 → 251,17
}
return $resultat;
}
 
 
 
 
//+----- modification svg -----+
 
 
 
public function traiterValeursEcologiques($valeur){
$this->valeurs_champs = $valeur;
$this->valeurs_champs = $valeur;
 
foreach($this->valeurs_champs as $cle => $val){
if (preg_match("/ve_humidite_edaph/", $cle)) {
$this->valeurs_en_pourcentage[$cle] = round($val/13,1);
272,7 → 272,7
}
}
}
 
public function donnerHauteur($ancienne_largeur, $ancienne_hauteur) {
$nouvelle_largeur = $this->largeurSVG;
$ancienne_largeur = str_replace('px','',$ancienne_largeur);
281,7 → 281,7
$nouvelle_hauteur = $ancienne_hauteur * $rapport;
$this->hauteurSVG = $nouvelle_hauteur;
}
 
public function ajusterFormatSVG(){
$svg = $this->dom->getElementsByTagName("svg")->item(0);
$largeur = $svg->getAttribute('width');
289,9 → 289,9
$this->donnerHauteur($largeur , $hauteur);
$svg->setAttribute('width',round($this->largeurSVG).'px');
$svg->setAttribute('height',round($this->hauteurSVG).'px');
 
}
 
public function genererSVG(){
$svg = null;
$this->dom = new DOMDocument('1.0', 'UTF-8');
302,9 → 302,9
$svg = $this->dom->saveXML();
return $svg;
}
 
abstract function changerValeursSVG();
 
public function recupererOntologies($valeur, $champs){
$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
try {
319,7 → 319,7
}
return $val;
}
 
public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){
if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) {
$prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie );
328,12 → 328,12
}
return $valeurTexte;
}
 
/// +---- convertir png ----+
 
public function convertirEnPNG($svg) {
$png = null;
 
if (isset($this->convertisseur)) {
if ($this->convertisseur == 'imagick') {
if (extension_loaded('imagick')) {
358,7 → 358,7
}
return $png;
}
 
public function convertirEnPNGAvecImageMagick($svg) {
$convertisseur = new Imagick();
$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
370,7 → 370,7
$convertisseur->destroy();
return $png;
}
 
public function convertirGraphiqueEnPNGAvecRsvg($svg) {
$idFichier = $this->getIdFichier();
$fichierPng = $this->config['cache_stockageChemin'].$idFichier.'.png';
383,13 → 383,13
$png = file_get_contents($fichierPng);
return $png;
}
 
public function indexerGraphiqueFichierPng($fichierPng) {
$img = imagecreatefrompng($fichierPng);
imagetruecolortopalette($img, false, 32);
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
}
 
public function getIdFichier(){
$idfichier = str_replace(".","-",$this->ressources[1]);
$idfichier = str_replace(':','-',$idfichier);