Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
398 mathilde 1
<?php
2
/**
3
*
4
*
5
* Encodage en entrée : utf8
6
* Encodage en sortie : utf8
7
* @package eflore-projets
8
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
10
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
* @version 1.0
13
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
*/
15
 
16
class ClimatGraph {
17
 
18
	private $parametres = array();
19
	private $ressources = array();
20
	private $Bdd;
21
	private $nomGraphique = 'graphique_11';
22
	protected $table="";
23
	private $requete_condition = "";
24
	private $config;
25
	private $convertisseur;
26
	private $cheminGraphBase;
27
	private $cache;
28
	protected $serviceNom = 'Graphiques';
29
	private $valeurs_en_pourcentage ;//array ("ve_temperature" => 0.1, "ve_continentalite" => 0.7, "ve_lumiere" => 0.9, "ve_humidite_atmos" => 0.2 );
30
	private $dom;
31
	private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
32
									"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
33
									"dix" => 1 );
34
 
35
 
36
 
37
	public function __construct(Conteneur $conteneur) {
38
		$this->Bdd = $conteneur->getBdd();
39
		$this->config = $conteneur->getParametre('Graphiques');
40
		//$this->convertisseur = $this->config['convertisseur'];
41
		$this->cheminGraphBase = $this->config['chemin'];
42
		/*$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
43
							'stockage_chemin' => $this->config['cache']['stockageChemin'],
44
							'duree_de_vie' => $this->config['cache']['dureeDeVie']);
45
		$this->cache = $conteneur->getCacheSimple($cacheOptions);*/
46
	}
47
 
48
 
49
	public function consulter($ressources, $parametres) {
50
		$this->ressources = $ressources;
51
		$this->parametres = $parametres;
52
 
53
		//à faire traiter les versions du projet
54
		$resultats = '';
55
  		$this->table = Config::get('bdd_table')."_v2012_03_19";
56
  		$this->traiterRessources();
57
		$requete = $this->assemblerLaRequete();
58
		$resultat = $this->Bdd->recupererTous($requete);
59
 
60
		$versionResultat = $this->obtenirResultat($resultat);
61
 
62
		return $versionResultat;
63
	}
64
 
65
 
66
 
67
 
68
	//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
69
	public function traiterRessources() {
70
		if (isset($this->ressources) && !empty($this->ressources[1])) {
71
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour)==1){
72
				switch ($retour[1]) {
73
					case 'bdtfx' :
74
						$this->requete_condition[]= "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
75
						break;
76
					case  'bdafx' :
77
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
78
						break;
79
					case  'bdbfx' :
80
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
81
						break;
82
					default :
83
						$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
84
							.$retour[1].' " n\'existe pas.';
85
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
86
						break;
87
				}
88
 
89
			}
90
		}
91
	}
92
 
93
 
94
	//+-------------------------- formatage du résultat  -------------------------------------------+
95
 
96
	public function obtenirResultat($resultat) {
97
		if ((count($this->ressources)) != 0) {
98
			$this->traiterValeursEcologiques($resultat[0]);
99
 
100
			$svg = $this->genererSVG_sol();
101
 
102
			$resultat = new ResultatService();
103
			$resultat->corps = $svg;
104
			$resultat->mime = 'image/svg+xml';
105
		}
106
		return $resultat;
107
	}
108
 
109
 
110
	public function traiterValeursEcologiques($valeurs){
111
		//humidite edaphique sur echelle de 12
112
		foreach($valeurs as $cle => $val){
113
			/*if ($cle == 've_humidite_edaph'){
114
				$this->valeurs_en_pourcentage[$cle] = round($val/12,1);
115
			}else{*/
116
				//salinite commence à 0
117
				if($val == 0){
118
					$this->valeurs_en_pourcentage[$cle] = 0;
119
				}else{
120
					$this->valeurs_en_pourcentage[$cle] = round($val/9,1);
121
				}
122
			}
123
		//}
124
	}
125
 
126
	public function genererSVG_sol(){
127
 
128
		$this->dom = new DOMDocument('1.0', 'UTF-8');
129
		//verifie que le xml est bien formé
130
		$this->dom->validateOnParse = true;
131
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
132
		$this->dom->load($fichierSvg);
133
		$this->changerValeursSVG();
134
		$svg = $this->dom->saveXML();
135
		return $svg;
136
	}
137
 
138
 
139
	public function changerValeursSVG(){
140
		foreach ($this->valeurs_en_pourcentage as $cle => $val){
141
 			$grad_id = array_search($val,$this->graduations_id);
142
			$element = $this->dom->getElementById($grad_id);
143
			$pos_x = $element->getAttribute('x1');
144
			$curseur = $this->dom->getElementById($cle);
145
				$curseur->setAttribute('cx', $pos_x);
146
		}
147
	}
148
 
149
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
150
 
151
	public function assemblerLaRequete() {
152
		$requete = 	' SELECT ve_lumiere , ve_temperature, ve_continentalite, ve_humidite_atmos
153
		 FROM '.$this->table.' '.$this->retournerRequeteCondition();
154
		return $requete;
155
	}
156
 
157
	public  function retournerRequeteCondition() {
158
		$condition = '';
159
		if ($this->requete_condition !== "") {
160
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
161
		}
162
		return $condition;
163
	}
164
 
165
 
166
}
167
?>