Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 502 | Rev 507 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
451 mathilde 1
<?php
2
/**
3
* Classe GraphiquesTaxonsSup.php transforme les données écologiques de la table baseflor_rang_sup_ecologie
4
* en graphique svg
5
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
6
*
7
*
8
* @package eflore-projets
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
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>
13
* @version 1.0
14
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
15
*/
16
 
17
class GraphiquesTaxonsSup extends CommunGraphiques{
18
 
19
 
20
 
21
 
22
	public function definirTable($version){
23
		$this->table = Config::get('bdd_table_rang_sup')."_v".$version;
24
	}
25
 
26
	//+---- ressources ----+
27
	public function traiterReferentieletNum(){
502 mathilde 28
		if (!empty($this->ressources[1])) {
451 mathilde 29
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour) == 1){
30
				switch ($retour[1]) {
31
					case 'bdtfx' : // pour le moment un seul referentiel disponible
32
						$this->requete_condition[]= "num_nomen = ".$retour[2]." AND bdnt = 'bdtfx' ";
33
						break;
34
					default :
35
						$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
36
					.$retour[1].' " n\'existe pas.';
37
					throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
38
					break;
39
				}
40
 
41
			}else {
42
				$e = 'Erreur dans l\'url de votre requête : </br> La ressource  n\'existe pas.';
43
				throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
44
			}
45
		} else {
504 mathilde 46
			throw new Exception( "Erreur dans l'url de votre requête :".
451 mathilde 47
							"preciser le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
48
			RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
49
		}
50
 
51
	}
52
 
53
 
54
 
55
	public function traiterTypeGraphique(){
502 mathilde 56
		if (!empty($this->ressources[0])) {
451 mathilde 57
			switch ($this->ressources[0]) {
58
				case  'climat' :
59
					$this->requete_champs = ' ve_lumiere_min, ve_lumiere_max, ve_temperature_min,'.
60
											' ve_temperature_max, ve_continentalite_min,'.
61
											' ve_continentalite_max, ve_humidite_atmos_min,'.
62
											' ve_humidite_atmos_max' ;
63
					$this->nomGraphique= 'climat_min_max';
64
					break;
65
				case 'sol' :
66
					$this->requete_champs = ' ve_humidite_edaph_min , ve_humidite_edaph_max,'.
67
											' ve_reaction_sol_min, ve_reaction_sol_max, '.
68
											' ve_nutriments_sol_min, ve_nutriments_sol_max,'.
69
											' ve_salinite_min, ve_salinite_max,'.
70
											' ve_texture_sol_min, ve_texture_sol_max,'.
71
											've_mat_org_sol_min,ve_mat_org_sol_max ' ;
72
					$this->nomGraphique = 'sol_min_max';
73
					break;
74
				default :
504 mathilde 75
					$e = "Erreur dans l'url de votre requête :".
76
					"</br> précisez le graphique -> \"sol\" ou \"climat\".";
451 mathilde 77
				throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
78
				break;
79
			}
80
		}else {
504 mathilde 81
			throw new Exception("Erreur dans l'url de votre requête :".
451 mathilde 82
					"</br> precisez le graphique -> \"sol\" ou \"climat\".", RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
83
		}
84
	}
85
 
86
 
87
 
88
 
89
	//+-------------------------- formatage du résultat  -------------------------------------------+
90
 
91
	public function changerValeursSVG(){
92
		$this->ajouterValeursIntermediaires();
93
		$Dompath = new DOMXPath($this->dom);
94
		foreach ($this->valeurs_en_pourcentage as $cle => $val){
95
				$val = preg_replace('/,/','.', $val);
96
				$grad_id = array_search($val,$this->graduations_id);
97
				$champs = preg_replace('/_min|_max|_[0-9]/','', $cle);
98
				$case = $Dompath->query("//*[@id='".$grad_id."_".$champs."']")->item(0);
99
				$case->setAttribute('fill','#EA6624');
100
				$case->setAttribute('stroke','#EA6624');
101
				$this->ajouterInfoAuSurvol($champs,$case);
102
				$changement = true;
103
		}
104
		$svg = $this->dom->getElementsByTagName("svg")->item(0);
105
		$svg->setAttribute('width',$this->largeurSVG);
106
	}
107
 
108
	public function ajouterValeursIntermediaires(){
109
		$champs_ecolo = array_keys($this->champs_ontologiques);
110
		foreach ($champs_ecolo as $chps ){
111
			$min = !empty($this->valeurs_en_pourcentage[$chps.'_min']) ? $this->valeurs_en_pourcentage[$chps.'_min'] : -1;
112
			$max = !empty($this->valeurs_en_pourcentage[$chps.'_max']) ? $this->valeurs_en_pourcentage[$chps.'_max'] : -1;
113
			if ($min < ($max-0.1) ){
114
				$i = $min + 0.1;
115
				$num = 1;
116
				for ($i ; $i < $max; $i += 0.1) {
117
					$this->valeurs_en_pourcentage[$chps.'_'.$num] = $i;
118
					$num++;
119
				}
120
			}
121
		}
122
	}
123
 
124
	public function ajouterInfoAuSurvol($champs, $case){
125
		$min = $this->valeurs_champs[$champs."_min"];
126
		$max = $this->valeurs_champs[$champs."_max"];
127
		if ($min != $max){
128
			$valeurMin = $this->recupererOntologies($min, $champs );
129
			$valeurMax = $this->recupererOntologies($max, $champs );
463 mathilde 130
			$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
131
			$valeurMax = $this->traiterIntermediaires($valeurMax->nom, $champs, $champs.'_max');
132
			$case->setAttribute('title',"de $min: $valeurMin à $max: $valeurMax " );
451 mathilde 133
		} else {
134
			$valeurMin = $this->recupererOntologies($min, $champs );
463 mathilde 135
			$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
136
			$case->setAttribute('title',"$min: $valeurMin" );
451 mathilde 137
		}
138
	}
139
 
140
 
141
}
142
?>