1 |
<?php
|
1 |
<?php
|
2 |
/**
|
2 |
/**
|
3 |
* Classe Graphiques.php permet d'afficher des graphiques en svg remplis avec des données écologiques
|
3 |
* Classe Graphiques.php permet d'afficher des graphiques en svg remplis avec des données écologiques
|
4 |
* fin d'url possibles :
|
4 |
* fin d'url possibles :
|
5 |
* graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie une graphique avec les données connues
|
5 |
* graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie une graphique avec les données connues
|
6 |
*
|
6 |
*
|
7 |
* Encodage en entrée : utf8
|
7 |
* Encodage en entrée : utf8
|
8 |
* Encodage en sortie : utf8
|
8 |
* Encodage en sortie : utf8
|
9 |
* @package eflore-projets
|
9 |
* @package eflore-projets
|
10 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
10 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
11 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
11 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
12 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
12 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
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 |
*/
|
17 |
|
17 |
|
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,
|
37 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
38 |
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
|
38 |
"dix" => 1 );
|
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' ,
|
- |
|
43 |
've_nutriments_sol' => 'VEN', 've_salinite'=> 'VES' ,
|
- |
|
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);
|
49 |
$versionResultat = $this->obtenirResultat($resultat);
|
55 |
$versionResultat = $this->obtenirResultat($resultat);
|
50 |
return $versionResultat;
|
56 |
return $versionResultat;
|
51 |
}
|
57 |
}
|
52 |
|
58 |
|
53 |
//+--------------------------initialisation de paramètres -------------------------------------------+
|
59 |
//+--------------------------initialisation de paramètres -------------------------------------------+
|
54 |
|
60 |
|
55 |
public function initialiserConfiguration() {
|
61 |
public function initialiserConfiguration() {
|
56 |
$conteneur = new Conteneur();
|
62 |
$conteneur = new Conteneur();
|
57 |
$this->Bdd = $conteneur->getBdd();
|
63 |
$this->Bdd = $conteneur->getBdd();
|
58 |
$this->config = $conteneur->getParametre('Graphiques');
|
64 |
$this->config = $conteneur->getParametre('Graphiques');
|
59 |
$this->convertisseur = $this->config['convertisseur'];
|
65 |
$this->convertisseur = $this->config['convertisseur'];
|
60 |
$this->cheminGraphBase = $this->config['chemin'];
|
66 |
$this->cheminGraphBase = $this->config['chemin'];
|
61 |
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
|
67 |
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
|
62 |
'stockage_chemin' => $this->config['cache']['stockageChemin'],
|
68 |
'stockage_chemin' => $this->config['cache']['stockageChemin'],
|
63 |
'duree_de_vie' => $this->config['cache']['dureeDeVie']);
|
69 |
'duree_de_vie' => $this->config['cache']['dureeDeVie']);
|
64 |
$this->cache = $conteneur->getCacheSimple($cacheOptions);
|
70 |
$this->cache = $conteneur->getCacheSimple($cacheOptions);
|
65 |
$this->chargerVersions();
|
71 |
$this->chargerVersions();
|
66 |
$this->definirVersion();
|
72 |
$this->definirVersion();
|
67 |
$this->definirFormat();
|
73 |
$this->definirFormat();
|
68 |
}
|
74 |
}
|
69 |
|
75 |
|
70 |
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
|
76 |
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
|
71 |
private function definirVersion() {
|
77 |
private function definirVersion() {
|
72 |
if( (!isset($this->parametres['version.projet']) ) || ((isset($this->parametres['version.projet']) )&&
|
78 |
if( (!isset($this->parametres['version.projet']) ) || ((isset($this->parametres['version.projet']) )&&
|
73 |
(($this->parametres['version.projet'] == '+') || ($this->parametres['version.projet'] == '')))){
|
79 |
(($this->parametres['version.projet'] == '+') || ($this->parametres['version.projet'] == '')))){
|
74 |
$this->version = $this->metadonnees[0]['version'];
|
80 |
$this->version = $this->metadonnees[0]['version'];
|
75 |
} else {
|
81 |
} else {
|
76 |
$this->version = $this->parametres['version.projet'];
|
82 |
$this->version = $this->parametres['version.projet'];
|
77 |
}
|
83 |
}
|
78 |
}
|
84 |
}
|
79 |
|
85 |
|
80 |
private function definirFormat() {
|
86 |
private function definirFormat() {
|
81 |
if (isset($this->parametres['retour.format']) ){
|
87 |
if (isset($this->parametres['retour.format']) ){
|
82 |
if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
|
88 |
if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
|
83 |
$this->largeurSVG= $this->parametres['retour.format'];
|
89 |
$this->largeurSVG= $this->parametres['retour.format'];
|
84 |
}else {
|
90 |
}else {
|
85 |
$erreur = "Erreur : Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
|
91 |
$erreur = "Erreur : Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
|
86 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
92 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
87 |
throw new Exception($erreur, $code);
|
93 |
throw new Exception($erreur, $code);
|
88 |
}
|
94 |
}
|
89 |
}
|
95 |
}
|
90 |
if (!isset($this->parametres['retour']) ){
|
96 |
if (!isset($this->parametres['retour']) ){
|
91 |
$this->parametres['retour'] = 'image/svg+xml';
|
97 |
$this->parametres['retour'] = 'image/svg+xml';
|
92 |
}else {
|
98 |
}else {
|
93 |
if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
|
99 |
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.";
|
100 |
$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;
|
101 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
96 |
throw new Exception($erreur, $code);
|
102 |
throw new Exception($erreur, $code);
|
97 |
}
|
103 |
}
|
98 |
}
|
104 |
}
|
99 |
}
|
105 |
}
|
100 |
|
106 |
|
101 |
|
107 |
|
102 |
|
108 |
|
103 |
private function chargerVersions() {
|
109 |
private function chargerVersions() {
|
104 |
$requete = "SELECT version ".
|
110 |
$requete = "SELECT version ".
|
105 |
"FROM ".Config::get('bdd_table_meta')." ".
|
111 |
"FROM ".Config::get('bdd_table_meta')." ".
|
106 |
"ORDER BY date_creation DESC ";
|
112 |
"ORDER BY date_creation DESC ";
|
107 |
$resultats = $this->Bdd->recupererTous($requete);
|
113 |
$resultats = $this->Bdd->recupererTous($requete);
|
108 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
114 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
109 |
$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
|
115 |
$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
|
110 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
116 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
111 |
throw new Exception($message, $code);
|
117 |
throw new Exception($message, $code);
|
112 |
}
|
118 |
}
|
113 |
|
119 |
|
114 |
$this->metadonnees = $resultats;
|
120 |
$this->metadonnees = $resultats;
|
115 |
}
|
121 |
}
|
116 |
|
122 |
|
117 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
123 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
118 |
|
124 |
|
119 |
public function traiterRessources() {
|
125 |
public function traiterRessources() {
|
120 |
$this->traiterRessources_NomService();
|
126 |
$this->traiterRessources_NomService();
|
121 |
$this->traiterRessources_TypeGraphique();
|
127 |
$this->traiterRessources_TypeGraphique();
|
122 |
}
|
128 |
}
|
123 |
|
129 |
|
124 |
public function traiterRessources_TypeGraphique(){
|
130 |
public function traiterRessources_TypeGraphique(){
|
125 |
if (isset($this->ressources) && !empty($this->ressources[1])) {
|
131 |
if (isset($this->ressources) && !empty($this->ressources[1])) {
|
126 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour)==1){
|
132 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour)==1){
|
127 |
switch ($retour[1]) {
|
133 |
switch ($retour[1]) {
|
128 |
case 'bdtfx' :
|
134 |
case 'bdtfx' :
|
129 |
$this->requete_condition[]= "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
|
135 |
$this->requete_condition[]= "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
|
130 |
break;
|
136 |
break;
|
131 |
case 'bdafx' :
|
137 |
case 'bdafx' :
|
132 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
|
138 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
|
133 |
break;
|
139 |
break;
|
134 |
case 'bdbfx' :
|
140 |
case 'bdbfx' :
|
135 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
|
141 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
|
136 |
break;
|
142 |
break;
|
137 |
default :
|
143 |
default :
|
138 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
|
144 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
|
139 |
.$retour[1].' " n\'existe pas.';
|
145 |
.$retour[1].' " n\'existe pas.';
|
140 |
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
146 |
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
141 |
break;
|
147 |
break;
|
142 |
}
|
148 |
}
|
143 |
|
149 |
|
144 |
}else {
|
150 |
}else {
|
145 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource n\'existe pas.';
|
151 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource n\'existe pas.';
|
146 |
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
152 |
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
147 |
}
|
153 |
}
|
148 |
} else {
|
154 |
} else {
|
149 |
throw new Exception( "Erreur dans l\'url de votre requête :".
|
155 |
throw new Exception( "Erreur dans l\'url de votre requête :".
|
150 |
"preciser le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
|
156 |
"preciser le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
|
151 |
RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
157 |
RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
152 |
}
|
158 |
}
|
153 |
|
159 |
|
154 |
}
|
160 |
}
|
155 |
|
161 |
|
156 |
public function traiterRessources_NomService(){
|
162 |
public function traiterRessources_NomService(){
|
157 |
if (isset($this->ressources) && !empty($this->ressources[0])) {
|
163 |
if (isset($this->ressources) && !empty($this->ressources[0])) {
|
158 |
switch ($this->ressources[0]) {
|
164 |
switch ($this->ressources[0]) {
|
159 |
case 'climat' :
|
165 |
case 'climat' :
|
160 |
$this->requete_champs = ' ve_lumiere , ve_temperature, ve_continentalite, ve_humidite_atmos' ;
|
166 |
$this->requete_champs = ' ve_lumiere , ve_temperature, ve_continentalite, ve_humidite_atmos' ;
|
161 |
$this->nomGraphique= 'climat';
|
167 |
$this->nomGraphique= 'climat';
|
162 |
break;
|
168 |
break;
|
163 |
case 'sol' :
|
169 |
case 'sol' :
|
164 |
$this->requete_champs = ' ve_humidite_edaph , ve_reaction_sol, ve_nutriments_sol, ve_salinite,'
|
170 |
$this->requete_champs = ' ve_humidite_edaph , ve_reaction_sol, ve_nutriments_sol, ve_salinite,'
|
165 |
.'ve_texture_sol, ve_mat_org_sol' ;
|
171 |
.'ve_texture_sol, ve_mat_org_sol' ;
|
166 |
$this->nomGraphique = 'sol';
|
172 |
$this->nomGraphique = 'sol';
|
167 |
break;
|
173 |
break;
|
168 |
default :
|
174 |
default :
|
169 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
|
175 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
|
170 |
.$retour[1].' " n\'existe pas.';
|
176 |
.$retour[1].' " n\'existe pas.';
|
171 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
177 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
172 |
break;
|
178 |
break;
|
173 |
}
|
179 |
}
|
174 |
}else {
|
180 |
}else {
|
175 |
throw new Exception("Erreur dans l\'url de votre requête :".
|
181 |
throw new Exception("Erreur dans l\'url de votre requête :".
|
176 |
"</br> precisez le graphique -> \"sol\" ou \"climat\".", RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
182 |
"</br> precisez le graphique -> \"sol\" ou \"climat\".", RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
177 |
}
|
183 |
}
|
178 |
}
|
184 |
}
|
179 |
|
185 |
|
180 |
|
186 |
|
181 |
|
187 |
|
182 |
|
188 |
|
183 |
//+-------------------------- formatage du résultat -------------------------------------------+
|
189 |
//+-------------------------- formatage du résultat -------------------------------------------+
|
184 |
|
190 |
|
185 |
|
191 |
|
186 |
public function obtenirResultat($resultat) {
|
192 |
public function obtenirResultat($resultat) {
|
187 |
if ($resultat == ""){
|
193 |
if ($resultat == ""){
|
188 |
$message = 'La requête SQL formée comporte une erreur!';
|
194 |
$message = 'La requête SQL formée comporte une erreur!';
|
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.';
|
203 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
207 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
204 |
throw new Exception($message, $code);
|
208 |
throw new Exception($message, $code);
|
205 |
}
|
209 |
}
|
206 |
return $resultat;
|
210 |
return $resultat;
|
207 |
}
|
211 |
}
|
208 |
|
212 |
|
209 |
|
213 |
|
- |
|
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{
|
216 |
//salinite commence à 0
|
221 |
//salinite commence à 0
|
217 |
if($val == 0){
|
222 |
if($val == 0){
|
218 |
$this->valeurs_en_pourcentage[$cle] = 0;
|
223 |
$this->valeurs_en_pourcentage[$cle] = 0;
|
219 |
}else{
|
224 |
}else{
|
220 |
$this->valeurs_en_pourcentage[$cle] = round($val/9,1);
|
225 |
$this->valeurs_en_pourcentage[$cle] = round($val/9,1);
|
221 |
}
|
226 |
}
|
222 |
}
|
227 |
}
|
223 |
}
|
228 |
}
|
224 |
}
|
229 |
}
|
225 |
|
230 |
|
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 |
}
|
236 |
|
241 |
|
237 |
|
242 |
|
238 |
|
243 |
|
239 |
public function changerValeursSVG(){
|
244 |
public function changerValeursSVG(){
|
240 |
foreach ($this->valeurs_en_pourcentage as $cle => $val){
|
245 |
foreach ($this->valeurs_en_pourcentage as $cle => $val){
|
241 |
$grad_id = array_search($val,$this->graduations_id);
|
246 |
$grad_id = array_search($val,$this->graduations_id);
|
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 |
}
|
- |
|
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) {
|
253 |
$png = null;
|
271 |
$png = null;
|
254 |
|
272 |
|
255 |
if (isset($this->convertisseur)) {
|
273 |
if (isset($this->convertisseur)) {
|
256 |
if ($this->convertisseur == 'imagick') {
|
274 |
if ($this->convertisseur == 'imagick') {
|
257 |
if (extension_loaded('imagick')) {
|
275 |
if (extension_loaded('imagick')) {
|
258 |
$png = $this->convertirEnPNGAvecImageMagick($svg);
|
276 |
$png = $this->convertirEnPNGAvecImageMagick($svg);
|
259 |
} else {
|
277 |
} else {
|
260 |
$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
|
278 |
$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
|
261 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
279 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
262 |
throw new Exception($message, $code);
|
280 |
throw new Exception($message, $code);
|
263 |
}
|
281 |
}
|
264 |
} else if ($this->convertisseur == 'rsvg') {
|
282 |
} else if ($this->convertisseur == 'rsvg') {
|
265 |
$png = $this->convertirEnPNGAvecRsvg($svg);
|
283 |
$png = $this->convertirEnPNGAvecRsvg($svg);
|
266 |
} else {
|
284 |
} else {
|
267 |
$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
|
285 |
$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
|
268 |
"des convertisseurs disponibles : imagick, rsvg.";
|
286 |
"des convertisseurs disponibles : imagick, rsvg.";
|
269 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
287 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
270 |
throw new Exception($message, $code);
|
288 |
throw new Exception($message, $code);
|
271 |
}
|
289 |
}
|
272 |
} else {
|
290 |
} else {
|
273 |
$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
|
291 |
$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
|
274 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
292 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
275 |
throw new Exception($message, $code);
|
293 |
throw new Exception($message, $code);
|
276 |
}
|
294 |
}
|
277 |
return $png;
|
295 |
return $png;
|
278 |
}
|
296 |
}
|
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');
|
285 |
$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
|
303 |
$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
|
286 |
$png = $convertisseur->getImageBlob();
|
304 |
$png = $convertisseur->getImageBlob();
|
287 |
$convertisseur->clear();
|
305 |
$convertisseur->clear();
|
288 |
$convertisseur->destroy();
|
306 |
$convertisseur->destroy();
|
289 |
return $png;
|
307 |
return $png;
|
290 |
}
|
308 |
}
|
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;
|
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);
|
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);
|
313 |
$idfichier .= "-".$this->ressources[0];
|
331 |
$idfichier .= "-".$this->ressources[0];
|
314 |
return $idfichier;
|
332 |
return $idfichier;
|
315 |
}
|
333 |
}
|
316 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
334 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
317 |
|
335 |
|
318 |
public function assemblerLaRequete() {
|
336 |
public function assemblerLaRequete() {
|
319 |
$requete = ' SELECT '.$this->requete_champs.' FROM '.$this->table.' '.$this->retournerRequeteCondition();
|
337 |
$requete = ' SELECT '.$this->requete_champs.' FROM '.$this->table.' '.$this->retournerRequeteCondition();
|
320 |
return $requete;
|
338 |
return $requete;
|
321 |
}
|
339 |
}
|
322 |
|
340 |
|
323 |
public function retournerRequeteCondition() {
|
341 |
public function retournerRequeteCondition() {
|
324 |
$condition = '';
|
342 |
$condition = '';
|
325 |
if ($this->requete_condition !== "") {
|
343 |
if ($this->requete_condition !== "") {
|
326 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
344 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
327 |
}
|
345 |
}
|
328 |
return $condition;
|
346 |
return $condition;
|
329 |
}
|
347 |
}
|
330 |
|
348 |
|
331 |
|
349 |
|
332 |
|
350 |
|
333 |
}
|
351 |
}
|
334 |
?>
|
352 |
?>
|