Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1175 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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