Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 712 | 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 :
507 mathilde 35
						$e = "Le référentiel {$retour[1]} n'existe pas.";
451 mathilde 36
					throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
37
					break;
38
				}
39
 
40
			}else {
507 mathilde 41
				$e = "Erreur dans l'url de votre requête :".
42
				" précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.";
451 mathilde 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 :".
507 mathilde 47
							" précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
451 mathilde 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);
697 aurelien 98
				// dans le cas de mauvaises données, pour ne pas que tout le graphique
698 delphine 99
				$case = $Dompath->query("//*[@id='".$grad_id."_".$champs."']")->item(0);
697 aurelien 100
				if($case != null) {
101
					$case->setAttribute('fill','#EA6624');
102
					$case->setAttribute('stroke','#EA6624');
712 aurelien 103
					$this->ajouterInfoAuSurvol($champs,$case);
697 aurelien 104
				}
451 mathilde 105
				$changement = true;
106
		}
514 mathilde 107
		$this->ajusterFormatSVG();
451 mathilde 108
	}
109
 
514 mathilde 110
 
111
 
451 mathilde 112
	public function ajouterValeursIntermediaires(){
113
		$champs_ecolo = array_keys($this->champs_ontologiques);
114
		foreach ($champs_ecolo as $chps ){
115
			$min = !empty($this->valeurs_en_pourcentage[$chps.'_min']) ? $this->valeurs_en_pourcentage[$chps.'_min'] : -1;
116
			$max = !empty($this->valeurs_en_pourcentage[$chps.'_max']) ? $this->valeurs_en_pourcentage[$chps.'_max'] : -1;
117
			if ($min < ($max-0.1) ){
118
				$i = $min + 0.1;
119
				$num = 1;
120
				for ($i ; $i < $max; $i += 0.1) {
121
					$this->valeurs_en_pourcentage[$chps.'_'.$num] = $i;
122
					$num++;
123
				}
124
			}
125
		}
126
	}
127
 
128
	public function ajouterInfoAuSurvol($champs, $case){
129
		$min = $this->valeurs_champs[$champs."_min"];
130
		$max = $this->valeurs_champs[$champs."_max"];
131
		if ($min != $max){
132
			$valeurMin = $this->recupererOntologies($min, $champs );
133
			$valeurMax = $this->recupererOntologies($max, $champs );
463 mathilde 134
			$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
135
			$valeurMax = $this->traiterIntermediaires($valeurMax->nom, $champs, $champs.'_max');
136
			$case->setAttribute('title',"de $min: $valeurMin à $max: $valeurMax " );
451 mathilde 137
		} else {
138
			$valeurMin = $this->recupererOntologies($min, $champs );
463 mathilde 139
			$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
140
			$case->setAttribute('title',"$min: $valeurMin" );
451 mathilde 141
		}
142
	}
143
 
144
 
145
}
146
?>