Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 506 | Rev 560 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 506 Rev 512
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
* Classe CommunGraphiques.php regroupement de fonctions pour les graphiques
4
* Classe CommunGraphiques.php regroupement de fonctions pour les graphiques
5
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
5
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
6
*   
6
*   
7
*
7
*
8
* @package eflore-projets
8
* @package eflore-projets
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
10
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
11
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
12
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
* @version 1.0
13
* @version 1.0
14
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
15
*/
15
*/
16
 
16
 
17
abstract class CommunGraphiques extends Commun{
17
abstract class CommunGraphiques extends Commun{
18
	
18
	
19
	protected $parametres = array();
19
	protected $parametres = array();
20
	protected $ressources = array();
20
	protected $ressources = array();
21
	
21
	
22
	protected $Bdd;
22
	protected $Bdd;
23
	protected $config;
23
	protected $config;
24
	protected $cache;
24
	protected $cache;
25
	protected $metadonnees;
25
	protected $metadonnees;
26
	protected $version;
26
	protected $version;
27
	protected $serviceNom = 'Graphiques';
27
	protected $serviceNom = 'Graphiques';
28
	
28
	
29
	protected $graduations_id = array();
29
	protected $graduations_id = array();
30
	protected  $champs_ontologiques =  array();
30
	protected  $champs_ontologiques =  array();
31
	protected $nomGraphique = array();
31
	protected $nomGraphique = array();
32
	
32
	
33
	protected $table = '';
33
	protected $table = '';
34
	protected $requete_condition = "";
34
	protected $requete_condition = "";
35
	protected $requete_champs;
35
	protected $requete_champs;
36
	
36
	
37
	protected $convertisseur;
37
	protected $convertisseur;
38
	protected $cheminGraphBase;
38
	protected $cheminGraphBase;
39
	protected $valeurs_en_pourcentage = array();
39
	protected $valeurs_en_pourcentage = array();
40
	protected $dom;
40
	protected $dom;
41
	protected $largeurSVG = "500";
41
	protected $largeurSVG = "500";
-
 
42
	protected $hauteurSVG;
42
	protected $valeurs_champs;
43
	protected $valeurs_champs;
43
	
44
	
-
 
45
	
44
	
46
	
45
	public function consulter($ressources, $parametres) {
47
	public function consulter($ressources, $parametres) {
46
		$this->ressources = $ressources;
48
		$this->ressources = $ressources;
47
		$this->parametres = $parametres;
49
		$this->parametres = $parametres;
48
		$this->verifierParametres();
50
		$this->verifierParametres();
49
		$this->initialiserConfiguration();
51
		$this->initialiserConfiguration();
50
		$resultats = '';
52
		$resultats = '';
51
		$this->traiterRessources();
53
		$this->traiterRessources();
52
		$requete = $this->assemblerLaRequete();
54
		$requete = $this->assemblerLaRequete();
53
		$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
55
		$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
54
		$versionResultat = $this->obtenirResultat($resultat);
56
		$versionResultat = $this->obtenirResultat($resultat);
55
		return $versionResultat;
57
		return $versionResultat;
56
	}
58
	}
57
	
59
	
58
 
60
 
59
	//+--------------------------initialisation de paramètres  -------------------------------------------+
61
	//+--------------------------initialisation de paramètres  -------------------------------------------+
60
	
62
	
61
	private function initialiserConfiguration() {
63
	private function initialiserConfiguration() {
62
		$conteneur = new Conteneur();
64
		$conteneur = new Conteneur();
63
		$this->Bdd = $conteneur->getBdd();
65
		$this->Bdd = $conteneur->getBdd();
64
		$this->config = $conteneur->getParametre('Graphiques');
66
		$this->config = $conteneur->getParametre('Graphiques');
65
		$this->convertisseur = $this->config['convertisseur'];
67
		$this->convertisseur = $this->config['convertisseur'];
66
		$this->graduations_id = $this->getParametreTableau('graduations_id');
68
		$this->graduations_id = $this->getParametreTableau('graduations_id');
67
		$this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques');
69
		$this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques');
68
		$this->cheminGraphBase = $this->config['chemin'];
70
		$this->cheminGraphBase = $this->config['chemin'];
69
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
71
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
70
								'stockage_chemin' => $this->config['cache']['stockageChemin'],
72
								'stockage_chemin' => $this->config['cache']['stockageChemin'],
71
								'duree_de_vie' => $this->config['cache']['dureeDeVie']);
73
								'duree_de_vie' => $this->config['cache']['dureeDeVie']);
72
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
74
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
73
		$this->definirVersion();
75
		$this->definirVersion();
74
		$this->definirFormat();
76
		$this->definirFormat();
75
		$this->definirTable($this->version);
77
		$this->definirTable($this->version);
76
	}
78
	}
77
	
79
	
78
	
80
	
79
	
81
	
80
	abstract function definirTable($version);
82
	abstract function definirTable($version);
81
	
83
	
82
	
84
	
83
	private function getParametreTableau($cle) {
85
	private function getParametreTableau($cle) {
84
		$tableau = array();
86
		$tableau = array();
85
		$parametre = Config::get($cle);
87
		$parametre = Config::get($cle);
86
		if (empty($parametre) === false) {
88
		if (empty($parametre) === false) {
87
			$tableauPartiel = explode(',', $parametre);
89
			$tableauPartiel = explode(',', $parametre);
88
			$tableauPartiel = array_map('trim', $tableauPartiel);
90
			$tableauPartiel = array_map('trim', $tableauPartiel);
89
			foreach ($tableauPartiel as $champ) {
91
			foreach ($tableauPartiel as $champ) {
90
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
92
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
91
					list($cle, $val) = explode('=', $champ);
93
					list($cle, $val) = explode('=', $champ);
92
					$tableau[trim($cle)] = trim($val);
94
					$tableau[trim($cle)] = trim($val);
93
				} else {
95
				} else {
94
					$tableau[] = trim($champ);
96
					$tableau[] = trim($champ);
95
				}
97
				}
96
			}
98
			}
97
		}
99
		}
98
		return $tableau;
100
		return $tableau;
99
	}
101
	}
100
 
102
 
101
	//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
103
	//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
102
	
104
	
103
	//+---- paramètres ----+
105
	//+---- paramètres ----+
104
	
106
	
105
	private function verifierParametres() {
107
	private function verifierParametres() {
106
		if (isset($this->parametres)) {
108
		if (isset($this->parametres)) {
107
			$parametres_dispo = array('retour', 'retour.format', 'version.projet');
109
			$parametres_dispo = array('retour', 'retour.format', 'version.projet');
108
			$parametres = array_keys($this->parametres);
110
			$parametres = array_keys($this->parametres);
109
			foreach ($parametres as $param) {
111
			foreach ($parametres as $param) {
110
				if (!in_array($param, $parametres_dispo)) {
112
				if (!in_array($param, $parametres_dispo)) {
111
					$erreur = "Erreur : Le paramètre $param est inconnu.";
113
					$erreur = "Erreur : Le paramètre $param est inconnu.";
112
					$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
114
					$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
113
					throw new Exception($erreur, $code);
115
					throw new Exception($erreur, $code);
114
				}
116
				}
115
			}
117
			}
116
		}
118
		}
117
		
119
		
118
	}
120
	}
119
	
121
	
120
	//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
122
	//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
121
	private function definirVersion() { 
123
	private function definirVersion() { 
122
		$this->chargerVersions();
124
		$this->chargerVersions();
123
		if (!isset($this->parametres['version.projet']) ) {
125
		if (!isset($this->parametres['version.projet']) ) {
124
			$this->version = $this->metadonnees[0]['version'];
126
			$this->version = $this->metadonnees[0]['version'];
125
		} elseif ($this->parametres['version.projet'] == '+') {
127
		} elseif ($this->parametres['version.projet'] == '+') {
126
				 $this->version = $this->metadonnees[0]['version'];
128
				 $this->version = $this->metadonnees[0]['version'];
127
		} else {
129
		} else {
128
			if($this->verifierVersion($this->parametres['version.projet'])) {
130
			if($this->verifierVersion($this->parametres['version.projet'])) {
129
				$this->version = $this->parametres['version.projet'];
131
				$this->version = $this->parametres['version.projet'];
130
			}else {
132
			}else {
131
				$erreur = "Erreur : La version est inconnue.";
133
				$erreur = "Erreur : La version est inconnue.";
132
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
134
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
133
				throw new Exception($erreur, $code);
135
				throw new Exception($erreur, $code);
134
			}
136
			}
135
		}
137
		}
136
	}
138
	}
137
	
139
	
138
	private function verifierVersion($version){
140
	private function verifierVersion($version){
139
		$retour = false;
141
		$retour = false;
140
		foreach ($this->metadonnees as $vers) {
142
		foreach ($this->metadonnees as $vers) {
141
			if ($vers['version'] == $version ) {
143
			if ($vers['version'] == $version ) {
142
				$retour = true;
144
				$retour = true;
143
			}
145
			}
144
		}
146
		}
145
		return $retour;
147
		return $retour;
146
	}
148
	}
147
	private function definirFormat() {
149
	private function definirFormat() {
148
		if (isset($this->parametres['retour.format']) ){
150
		if (isset($this->parametres['retour.format']) ){
149
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
151
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
-
 
152
				if ($this->parametres['retour.format'] > 0) {
150
				$this->largeurSVG = $this->parametres['retour.format'];
153
					$this->largeurSVG = $this->parametres['retour.format'];
-
 
154
				} else {
-
 
155
					$erreur = "Erreur : valeur pour retour.format négative ou égale à 0.";
-
 
156
					$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
157
					throw new Exception($erreur, $code);
-
 
158
				}
151
			}else {
159
			}else {
152
				$erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
160
				$erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
153
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
161
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
154
				throw new Exception($erreur, $code);
162
				throw new Exception($erreur, $code);
155
			}
163
			}
156
		}
164
		}
157
		if (!isset($this->parametres['retour']) ){
165
		if (!isset($this->parametres['retour']) ){
158
			$this->parametres['retour'] = 'image/svg+xml';
166
			$this->parametres['retour'] = 'image/svg+xml';
159
		
167
		
160
		}else {
168
		}else {
161
			if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
169
			if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
162
				$erreur = "Erreur : valeur inconnue. Choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
170
				$erreur = "Erreur : valeur inconnue. Choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
163
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
171
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
164
				throw new Exception($erreur, $code);
172
				throw new Exception($erreur, $code);
165
			}
173
			}
166
		}
174
		}
167
	}
175
	}
168
	
176
	
169
	
177
	
170
	
178
	
171
	private function chargerVersions() {
179
	private function chargerVersions() {
172
		$requete = "SELECT version ".
180
		$requete = "SELECT version ".
173
							"FROM ".Config::get('bdd_table_meta')." ".
181
							"FROM ".Config::get('bdd_table_meta')." ".
174
							"ORDER BY date_creation DESC ";
182
							"ORDER BY date_creation DESC ";
175
		$resultats = $this->Bdd->recupererTous($requete);
183
		$resultats = $this->Bdd->recupererTous($requete);
176
		if (!is_array($resultats) || count($resultats) <= 0) {
184
		if (!is_array($resultats) || count($resultats) <= 0) {
177
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
185
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
178
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
186
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
179
			throw new Exception($message, $code);
187
			throw new Exception($message, $code);
180
		}
188
		}
181
	
189
	
182
		$this->metadonnees = $resultats;
190
		$this->metadonnees = $resultats;
183
	}
191
	}
184
	
192
	
185
	//+----- ressources -----+
193
	//+----- ressources -----+
186
	
194
	
187
	
195
	
188
	public function traiterRessources() {
196
	public function traiterRessources() {
189
		if(isset($this->ressources)) {
197
		if(isset($this->ressources)) {
190
			$this->traiterTypeGraphique();
198
			$this->traiterTypeGraphique();
191
			$this->traiterReferentielEtNum();
199
			$this->traiterReferentielEtNum();
192
		} else {
200
		} else {
193
			$e = 'Erreur dans l\'url de votre requête : </br> ressources insuffisantes.';
201
			$e = 'Erreur dans l\'url de votre requête : </br> ressources insuffisantes.';
194
			throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
202
			throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
195
		}
203
		}
196
	}
204
	}
197
	
205
	
198
	abstract function traiterReferentielEtNum();
206
	abstract function traiterReferentielEtNum();
199
	abstract function traiterTypeGraphique();
207
	abstract function traiterTypeGraphique();
200
	
208
	
201
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
209
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
202
	
210
	
203
	public function assemblerLaRequete() {
211
	public function assemblerLaRequete() {
204
		$requete = 	' SELECT '.$this->requete_champs.'  FROM '.$this->table.' '.$this->retournerRequeteCondition();
212
		$requete = 	' SELECT '.$this->requete_champs.'  FROM '.$this->table.' '.$this->retournerRequeteCondition();
205
		return $requete;
213
		return $requete;
206
	}
214
	}
207
	
215
	
208
	public  function retournerRequeteCondition() {
216
	public  function retournerRequeteCondition() {
209
		$condition = '';
217
		$condition = '';
210
		if ($this->requete_condition !== "") {
218
		if ($this->requete_condition !== "") {
211
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
219
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
212
		}
220
		}
213
		return $condition;
221
		return $condition;
214
	}
222
	}
215
	
223
	
216
	//+-------------------------- formatage du résultat  -------------------------------------------+
224
	//+-------------------------- formatage du résultat  -------------------------------------------+
217
 
225
 
218
	public function obtenirResultat($resultat) {
226
	public function obtenirResultat($resultat) {
219
		if ($resultat == ""){
227
		if ($resultat == ""){
220
			$message = 'La requête SQL formée comporte une erreur!';
228
			$message = 'La requête SQL formée comporte une erreur!';
221
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
229
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
222
			throw new Exception($message, $code);
230
			throw new Exception($message, $code);
223
		}elseif ($resultat) {
231
		}elseif ($resultat) {
224
			if ((count($this->ressources)) != 0) {
232
			if ((count($this->ressources)) != 0) {
225
				//$Atraiter = array_filter($resultat[0],function($var){return ($var != '');});
233
				//$Atraiter = array_filter($resultat[0],function($var){return ($var != '');});
226
				foreach ($resultat[0] as $champs => $valeur) {
234
				foreach ($resultat[0] as $champs => $valeur) {
227
					if ($valeur !== '') {
235
					if ($valeur !== '') {
228
						$Atraiter[$champs] = $valeur;
236
						$Atraiter[$champs] = $valeur;
229
					}
237
					}
230
				}
238
				}
231
				if (!empty($Atraiter)) {
239
				if (!empty($Atraiter)) {
232
					$this->traiterValeursEcologiques($Atraiter);
240
					$this->traiterValeursEcologiques($Atraiter);
233
					$svg = $this->genererSVG();
241
					$svg = $this->genererSVG();
234
					$resultat = new ResultatService();
242
					$resultat = new ResultatService();
235
					$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
243
					$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
236
					$resultat->mime = $this->parametres['retour'];
244
					$resultat->mime = $this->parametres['retour'];
237
				} else {
245
				} else {
238
					$resultat = null; 
246
					$resultat = null; 
239
				}
247
				}
240
			}
248
			}
241
		} else {
249
		} else {
242
			$resultat = null;
250
			$resultat = null;
243
		}
251
		}
244
		return $resultat;
252
		return $resultat;
245
	}
253
	}
246
	
254
	
247
	
255
	
248
	
256
	
249
	
257
	
250
	//+----- modification svg -----+
258
	//+----- modification svg -----+
251
	
259
	
252
	
260
	
253
 
261
 
254
	public function traiterValeursEcologiques($valeur){
262
	public function traiterValeursEcologiques($valeur){
255
		$this->valeurs_champs = $valeur; 
263
		$this->valeurs_champs = $valeur; 
256
	
264
	
257
		foreach($this->valeurs_champs as $cle => $val){
265
		foreach($this->valeurs_champs as $cle => $val){
258
				if (preg_match("/ve_humidite_edaph/", $cle)) {
266
				if (preg_match("/ve_humidite_edaph/", $cle)) {
259
					$this->valeurs_en_pourcentage[$cle] = round($val/13,1);
267
					$this->valeurs_en_pourcentage[$cle] = round($val/13,1);
260
				} elseif (preg_match("/ve_salinite/", $cle)) {
268
				} elseif (preg_match("/ve_salinite/", $cle)) {
261
					$this->valeurs_en_pourcentage[$cle] = round(($val+1)/11,1);
269
					$this->valeurs_en_pourcentage[$cle] = round(($val+1)/11,1);
262
				} else {
270
				} else {
263
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
271
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
264
				}
272
				}
265
		}
273
		}
266
	}
274
	}
-
 
275
	
-
 
276
	public function donnerHauteur($ancienne_largeur, $ancienne_hauteur) {
-
 
277
		$nouvelle_largeur = $this->largeurSVG;
-
 
278
		$ancienne_largeur = str_replace('px','',$ancienne_largeur);
-
 
279
		$ancienne_hauteur = str_replace('px','',$ancienne_hauteur);
-
 
280
		$rapport =   $nouvelle_largeur / $ancienne_largeur ;
-
 
281
		$nouvelle_hauteur = $ancienne_hauteur * $rapport;
-
 
282
		$this->hauteurSVG = $nouvelle_hauteur;
267
	
283
	}
-
 
284
	
-
 
285
	public function ajusterFormatSVG(){
-
 
286
		$svg = $this->dom->getElementsByTagName("svg")->item(0);
-
 
287
		$largeur = $svg->getAttribute('width');
-
 
288
		$hauteur = $svg->getAttribute('height');
-
 
289
		$this->donnerHauteur($largeur , $hauteur);
-
 
290
		$svg->setAttribute('width',$this->largeurSVG.'px');
-
 
291
		$svg->setAttribute('height',$this->hauteurSVG.'px');
-
 
292
		
268
	
293
	}
269
	
294
	
270
	public function genererSVG(){
295
	public function genererSVG(){
271
		$svg = null;
296
		$svg = null;
272
		$this->dom = new DOMDocument('1.0', 'UTF-8');
297
		$this->dom = new DOMDocument('1.0', 'UTF-8');
273
		$this->dom->validateOnParse = true;
298
		$this->dom->validateOnParse = true;
274
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
299
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
275
		$this->dom->load($fichierSvg);
300
		$this->dom->load($fichierSvg);
276
		$this->changerValeursSVG();
301
		$this->changerValeursSVG();
277
			$svg = $this->dom->saveXML();
302
		$svg = $this->dom->saveXML();
278
		return $svg;
303
		return $svg;
279
	}
304
	}
280
	
305
	
281
	abstract function changerValeursSVG();
306
	abstract function changerValeursSVG();
282
	
307
	
283
	public function recupererOntologies($valeur, $champs){
308
	public function recupererOntologies($valeur, $champs){
284
		$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
309
		$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
285
		$val = $this->consulterHref($url);
310
		$val = $this->consulterHref($url);
286
		return $val;
311
		return $val;
287
	}
312
	}
288
	
313
	
289
	public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){
314
	public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){
290
		if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) {
315
		if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) {
291
			$prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie );
316
			$prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie );
292
			$suiv = $this->recupererOntologies(($this->valeurs_champs[$champsTable]+1), $champsOntologie );
317
			$suiv = $this->recupererOntologies(($this->valeurs_champs[$champsTable]+1), $champsOntologie );
293
			$valeurTexte = "Intermédiaires entre $prec->nom et $suiv->nom ";
318
			$valeurTexte = "Intermédiaires entre $prec->nom et $suiv->nom ";
294
		}
319
		}
295
		return $valeurTexte;
320
		return $valeurTexte;
296
	}
321
	}
297
	
322
	
298
	/// +---- convertir png ----+
323
	/// +---- convertir png ----+
299
	
324
	
300
	public function convertirEnPNG($svg) {
325
	public function convertirEnPNG($svg) {
301
		$png = null;
326
		$png = null;
302
	
327
	
303
		if (isset($this->convertisseur)) {
328
		if (isset($this->convertisseur)) {
304
			if ($this->convertisseur == 'imagick') {
329
			if ($this->convertisseur == 'imagick') {
305
				if (extension_loaded('imagick')) {
330
				if (extension_loaded('imagick')) {
306
					$png = $this->convertirEnPNGAvecImageMagick($svg);
331
					$png = $this->convertirEnPNGAvecImageMagick($svg);
307
				} else {
332
				} else {
308
					$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
333
					$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
309
					$code = RestServeur::HTTP_CODE_ERREUR;
334
					$code = RestServeur::HTTP_CODE_ERREUR;
310
					throw new Exception($message, $code);
335
					throw new Exception($message, $code);
311
				}
336
				}
312
			} else if ($this->convertisseur == 'rsvg') {
337
			} else if ($this->convertisseur == 'rsvg') {
313
				$png = $this->convertirEnPNGAvecRsvg($svg);
338
				$png = $this->convertirEnPNGAvecRsvg($svg);
314
			} else {
339
			} else {
315
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
340
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
316
								"des convertisseurs disponibles : imagick, rsvg.";
341
								"des convertisseurs disponibles : imagick, rsvg.";
317
				$code = RestServeur::HTTP_CODE_ERREUR;
342
				$code = RestServeur::HTTP_CODE_ERREUR;
318
				throw new Exception($message, $code);
343
				throw new Exception($message, $code);
319
			}
344
			}
320
		} else {
345
		} else {
321
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
346
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
322
			$code = RestServeur::HTTP_CODE_ERREUR;
347
			$code = RestServeur::HTTP_CODE_ERREUR;
323
			throw new Exception($message, $code);
348
			throw new Exception($message, $code);
324
		}
349
		}
325
		return $png;
350
		return $png;
326
	}
351
	}
327
	
352
	
328
	public function convertirEnPNGAvecImageMagick($svg) {
353
	public function convertirEnPNGAvecImageMagick($svg) {
329
		$convertisseur = new Imagick();
354
		$convertisseur = new Imagick();
330
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
355
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
331
		$convertisseur->readImageBlob($svg);
356
		$convertisseur->readImageBlob($svg);
332
		$convertisseur->setImageFormat('png32');
357
		$convertisseur->setImageFormat('png32');
333
		$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
358
		$convertisseur->resizeImage($this->largeurSVG,$this->hauteurSVG, imagick::FILTER_LANCZOS, 0, true);
334
		$png = $convertisseur->getImageBlob();
359
		$png = $convertisseur->getImageBlob();
335
		$convertisseur->clear();
360
		$convertisseur->clear();
336
		$convertisseur->destroy();
361
		$convertisseur->destroy();
337
		return $png;
362
		return $png;
338
	}
363
	}
339
	
364
	
340
	public function convertirEnPNGAvecRsvg($svg) {
365
	public function convertirEnPNGAvecRsvg($svg) {
341
		$idFichier = $this->getIdFichier();
366
		$idFichier = $this->getIdFichier();
342
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
367
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
343
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
368
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
344
		file_put_contents($fichierSvg, $svg);
369
		file_put_contents($fichierSvg, $svg);
345
		$commande = "rsvg-convert  $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
370
		$commande = "rsvg-convert  $fichierSvg -w ".$this->largeurSVG ." -h ".$this->hauteurSVG ." -o $fichierPng";
-
 
371
		//echo $commande; exit;
346
		$rsvg = exec($commande);
372
		$rsvg = exec($commande);
347
		$this->indexerFichierPng($fichierPng);
373
		$this->indexerFichierPng($fichierPng);
348
		$png = file_get_contents($fichierPng);
374
		$png = file_get_contents($fichierPng);
349
		return $png;
375
		return $png;
350
	}
376
	}
351
	
377
	
352
	public function indexerFichierPng($fichierPng) {
378
	public function indexerFichierPng($fichierPng) {
353
		$img = imagecreatefrompng($fichierPng);
379
		$img = imagecreatefrompng($fichierPng);
354
		imagetruecolortopalette($img, false, 32);
380
		imagetruecolortopalette($img, false, 32);
355
		imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
381
		imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
356
	}
382
	}
357
	
383
	
358
	public function getIdFichier(){
384
	public function getIdFichier(){
359
		$idfichier = str_replace(".","-",$this->ressources[1]);
385
		$idfichier = str_replace(".","-",$this->ressources[1]);
360
		$idfichier = str_replace(':','-',$idfichier);
386
		$idfichier = str_replace(':','-',$idfichier);
361
		$idfichier .= "-".$this->ressources[0];
387
		$idfichier .= "-".$this->ressources[0];
362
		return $idfichier;
388
		return $idfichier;
363
	}
389
	}
364
}
390
}
365
?>
391
?>