Subversion Repositories Applications.annuaire

Rev

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

Rev Author Line No. Line
61 aurelien 1
<?php
2
/**
3
* PHP Version 5
4
*
5
* @category  PHP
6
* @package   annuaire
7
* @author    aurelien <aurelien@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
11
* @link      /doc/annuaire/
12
*/
13
 
14
class StatistiquesControleur extends Controleur {
15
 
16
	private $statistiques = null;
17
 
18
	private $champ_pays = '12';
19
	private $onto_pays = '1074';
20
 
21
	private $champ_rapport_activite_bota = '102';
22
	private $onto_rapport_activite_bota = '30797';
23
 
24
	private $champ_experience_bota = '4';
25
	private $onto_experience_bota = '30785';
26
 
27
	public function StatistiquesControleur() {
28
		$this->statistiques = Composant::fabrique('statistiques', array());
29
	}
30
 
31
	public function obtenirGraphiques($id_annuaire) {
32
 
33
		$graph = array();
34
 
35
		//$this->obtenirStatistiquesParPays($id_annuaire);
36
		$graph['pays'] =  $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_pays, $this->onto_pays);
37
		$graph['activite_bota'] = $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_rapport_activite_bota, $this->onto_rapport_activite_bota, 'Répartition des inscrits selon leur activité');
38
		$graph['experience_bota'] =  $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_experience_bota, $this->onto_experience_bota, 'Répartition des inscrits selon leur expérience botanique');
39
 
40
		/*$WIDTH1 = $WIDTH2 = $WIDTH3 = 500;
41
		$HEIGHT1 = $HEIGHT2 = $HEIGHT3 = 1500;
42
 
43
		$image = imagecreatetruecolor(500,1500);
44
		imagecopy($image, $graph['pays'],0, 0, 0, 0, $WIDTH1,$HEIGHT1);
45
		imagecopy($image, $graph['activite_bota'],0, 500, 0, 0, $WIDTH1,$HEIGHT1);
46
		imagecopy($image, $graph['experience_bota'],0, 1000, 0, 0, $WIDTH1,$HEIGHT1);*/
47
 
48
		//Debug::printr($graph);
49
 
50
		//TODO remplacer le fouillis ci dessus par ce qui suit
51
		$image = $this->statistiques->combinerGraphiques($graph);
52
 
53
		// Stream the result back as a PNG image
54
		header("Content-type: image/png");
55
		imagepng ($image);
56
 
57
		return $graph ;
58
	}
59
 
60
	public function obtenirStatistiquesParPays($id_annuaire, $titre = 'Répartition des inscrits par pays') {
61
 
62
	    $controleur = new AnnuaireControleur();
63
 
64
	    $modele_meta = new MetadonneeModele();
65
	   	$modele_onto = new OntologieModele();
66
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($this->champ_experience_bota);
67
	   	$legendes = $modele_onto->chargerListeOntologie($this->onto_experience_bota);
68
 
69
		$valeurs_a_stat_code = array();
70
		$valeurs_a_stat_legende = array();
71
 
72
		foreach($valeurs as $valeur) {
73
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
74
		}
75
 
76
	    foreach($legendes as $legende) {
77
	    	$legende_nom = $legende['amo_nom'];
78
	    	$legende_code = $legende['amo_id_ontologie'];
79
 
80
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
81
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
82
	    	}
83
	    }
84
 
85
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
86
 
87
	}
88
 
89
	public function obtenirStatistiquesParCritere($id_annuaire, $id_champ, $id_onto, $titre = '') {
90
 
91
	    $controleur = new AnnuaireControleur();
92
 
93
	    $modele_meta = new MetadonneeModele();
94
	   	$modele_onto = new OntologieModele();
95
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
96
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
97
 
98
		$valeurs_a_stat_code = array();
99
		$valeurs_a_stat_legende = array();
100
 
101
		foreach($valeurs as $valeur) {
102
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
103
		}
104
 
105
	    foreach($legendes as $legende) {
106
	    	$legende_nom = $legende['amo_nom'];
107
	    	$legende_code = $legende['amo_id_ontologie'];
108
 
109
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
110
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
111
	    	}
112
	    }
113
 
114
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre);
115
 
116
	}
117
 
118
	public function obtenirStatistiquesParAnnees($id_annuaire) {
119
 
120
	    $controleur = new AnnuaireControleur();
121
 
122
	    $modele_stats = new StatistiquesModele();
123
	    $valeurs = $modele_stats->obtenirNombreInscriptionsParDate($id_annuaire);
124
	   	$legendes = $modele_onto->chargerListeOntologie('1074');
125
 
126
 
127
		$valeurs_a_stat_code = array();
128
		$valeurs_a_stat_legende = array();
129
 
130
		foreach($valeurs as $valeur) {
131
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
132
		}
133
 
134
	    foreach($legendes as $legende) {
135
	    	$legende_nom = $legende['amo_nom'];
136
	    	$legende_code = $legende['amo_id_ontologie'];
137
 
138
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
139
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
140
	    	}
141
	    }
142
 
143
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
144
 
145
	}
146
 
147
}
148
?>