Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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