Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 566 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
566 mathilde 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe gérant les graphiques et leurs légendes.
5
 *
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
8
 * @author		Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
9
 * @copyright	2011 Tela-Botanica
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
12
 * @version		$Id$
13
 */
1084 raphael 14
class Graphiques extends Eflore {
566 mathilde 15
 
16
	private $bdnt;
17
	private $num_nom;
18
	private $type_graph;
19
	private $classe;
20
	private $code;
1084 raphael 21
	// pour chaque code, [0] est le min (départ de recherche des valeurs)
22
	// et [1] est le max (fin)
23
	static $codes = array ("VEL" => array(1,9),
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) );
566 mathilde 33
 
34
	public function setType_graph($tg) {
35
		$this->type_graph = $tg;
36
	}
37
 
38
	public function setCode($code) {
39
		$this->code = $code;
40
	}
41
 
42
	public function setClasse($classe) {
43
		$this->classe = $classe;
44
	}
45
 
46
	public function setBdnt($bdnt){
47
		$this->bdnt = $bdnt;
48
	}
49
 
50
	public function setNum_nom($nn){
51
		$this->num_nom = $nn;
52
	}
1084 raphael 53
 
54
	// TODO: array_map() // XXX: PHP-5.3
55
	static function _build_range() {
56
		$ret = array();
57
		foreach (self::$codes as $classe => $val) {
58
			foreach(range($val[0], $val[1]) as $i) {
59
				$ret[] = $classe . ':' . $i;
60
			}
61
		}
62
		return implode(',', $ret);
63
	}
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
 
566 mathilde 75
	public function getLegendeGraphique() {
76
		$legende = array();
1084 raphael 77
		// eg: VEL:1,VEL:2,VEL:3,...VER:9,VETX:1,...
78
		$ressources = self::_build_range();
79
		$url = Eflore::s_formaterUrl(Config::get('legendeGraphiqueTpl'),
80
									 $this->ajouterParametreParDefaut(array('params' => $ressources)),
81
									 FALSE);
82
		$data = $this->chargerDonnees($url);
83
		return self::_split_data($data);
566 mathilde 84
	}
85
 
86
	public function getGraphique() {
87
		$url = $this->getUrlInformation();
88
		return $this->chargerDonnees($url);
89
	}
90
 
91
	public function getUrlGraphique() {
92
		$tpl = Config::get('graphiqueTpl');
93
		$params = array( 'bdnt' => $this->bdnt, 'num_nom' => $this->num_nom , 'type_graph' => $this->type_graph);
94
		$url = $this->formaterUrl($tpl, $params);
95
		return $url;
96
	}
97
 
98
}
99
?>