Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 566 Rev 1084
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe gérant les graphiques et leurs légendes.
4
 * Classe gérant les graphiques et leurs légendes.
5
 *
5
 *
6
 * @category	PHP 5.2
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
7
 * @package		eflore-consultation
8
 * @author		Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
8
 * @author		Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
9
 * @copyright	2011 Tela-Botanica
9
 * @copyright	2011 Tela-Botanica
10
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
10
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
12
 * @version		$Id$
12
 * @version		$Id$
13
 */
13
 */
14
class Graphiques  extends Eflore {
14
class Graphiques extends Eflore {
15
 
15
 
16
	private $bdnt;
16
	private $bdnt;
17
	private $num_nom;
17
	private $num_nom;
18
	private $type_graph;
18
	private $type_graph;
19
	private $classe;
19
	private $classe;
20
	private $code;
20
	private $code;
-
 
21
	// pour chaque code, [0] est le min (départ de recherche des valeurs)
-
 
22
	// et [1] est le max (fin)
21
	private $codes =  array ("VEL", "VET", "VEHA", "VEC", "VER", "VEHE", "VETX", "VEN", "VES","VEMO");
23
	static $codes = array ("VEL" => array(1,9),
22
	
-
 
23
	
-
 
-
 
24
						   "VET" => array(1,9),
-
 
25
						   "VEHA" => array(1,9),
-
 
26
						   "VEC" => array(1,9),
-
 
27
						   "VER" => array(1,9),
-
 
28
						   "VETX" => array(1,9),
-
 
29
						   "VEN" => array(1,9),
-
 
30
						   "VEMO" => array(1,9),
-
 
31
						   "VEHE" => array(1,12),
-
 
32
						   "VES" => array(0,9) );
24
 
33
 
25
	public function setType_graph($tg) {
34
	public function setType_graph($tg) {
26
		$this->type_graph = $tg;
35
		$this->type_graph = $tg;
27
	}
36
	}
28
	
37
	
29
	public function setCode($code) {
38
	public function setCode($code) {
30
		$this->code = $code;
39
		$this->code = $code;
31
	}
40
	}
32
	
41
	
33
	public function setClasse($classe) {
42
	public function setClasse($classe) {
34
		$this->classe = $classe;
43
		$this->classe = $classe;
35
	}
44
	}
36
	
45
	
37
	public function setBdnt($bdnt){
46
	public function setBdnt($bdnt){
38
		$this->bdnt = $bdnt;
47
		$this->bdnt = $bdnt;
39
	}
48
	}
40
	
49
	
41
	public function setNum_nom($nn){
50
	public function setNum_nom($nn){
42
		$this->num_nom = $nn;
51
		$this->num_nom = $nn;
43
	}
52
	}
44
	
-
 
45
	
53
 
-
 
54
	// TODO: array_map() // XXX: PHP-5.3
46
	public function getLegendeGraphique() {
55
	static function _build_range() {
47
		$legende = array();
56
		$ret = array();
48
		foreach ($this->codes as $cod){
57
		foreach (self::$codes as $classe => $val) {
49
			$i = ($cod == "VES") ?  0 : 1 ;
-
 
50
			$max = ($cod == "VEHE") ?  12 : 9 ;
58
			foreach(range($val[0], $val[1]) as $i) {
51
			while ($i < $max+1){
-
 
52
				$this->setClasse($cod);
59
				$ret[] = $classe . ':' . $i;
53
				$this->setCode($i);
-
 
54
				$url = $this->getUrlLegende();
-
 
55
				$legende[$cod][$i] = $this->chargerDonnees($url);
-
 
56
				$i++;
-
 
57
			}			
60
			}
58
		}
61
		}
59
		return $legende;
62
		return implode(',', $ret);
60
	}
63
	}
61
	
64
 
-
 
65
	// TODO: array_map() // XXX: PHP-5.3
-
 
66
	static function _split_data($tab) {
-
 
67
		$ret = array();
-
 
68
		foreach ($tab as $k => $v) {
-
 
69
			list($new_k, $sub_k) = explode(':', $k);
-
 
70
			$ret[$new_k][$sub_k] = $v;
-
 
71
		}
-
 
72
		return $ret;
-
 
73
	}
-
 
74
 
62
	public function getUrlLegende() {
75
	public function getLegendeGraphique() {
-
 
76
		$legende = array();
-
 
77
		// eg: VEL:1,VEL:2,VEL:3,...VER:9,VETX:1,...
-
 
78
		$ressources = self::_build_range();
63
		$tpl = Config::get('legendeGraphiqueTpl');
79
		$url = Eflore::s_formaterUrl(Config::get('legendeGraphiqueTpl'),
64
		$params = array( 'code' => $this->code, 'classe' => $this->classe );
80
									 $this->ajouterParametreParDefaut(array('params' => $ressources)),
-
 
81
									 FALSE);
65
		$url = $this->formaterUrl($tpl, $params);
82
		$data = $this->chargerDonnees($url);
66
		return $url ;
83
		return self::_split_data($data);
67
	}
84
	}
68
	
85
	
69
	public function getGraphique() {
86
	public function getGraphique() {
70
		$url = $this->getUrlInformation();
87
		$url = $this->getUrlInformation();
71
		return $this->chargerDonnees($url);
88
		return $this->chargerDonnees($url);
72
	}
89
	}
73
	
90
	
74
	public function getUrlGraphique() {
91
	public function getUrlGraphique() {
75
		$tpl = Config::get('graphiqueTpl');
92
		$tpl = Config::get('graphiqueTpl');
76
		$params = array( 'bdnt' => $this->bdnt, 'num_nom' => $this->num_nom , 'type_graph' => $this->type_graph);
93
		$params = array( 'bdnt' => $this->bdnt, 'num_nom' => $this->num_nom , 'type_graph' => $this->type_graph);
77
		$url = $this->formaterUrl($tpl, $params);
94
		$url = $this->formaterUrl($tpl, $params);
78
		return $url;
95
		return $url;
79
	}
96
	}
80
	
97
	
81
}
98
}
82
?>
99
?>