Subversion Repositories Applications.annuaire

Rev

Rev 120 | Rev 247 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 120 Rev 231
1
<?php
1
<?php
2
/**
2
/**
3
* PHP Version 5
3
* PHP Version 5
4
*
4
*
5
* @category  PHP
5
* @category  PHP
6
* @package   annuaire
6
* @package   annuaire
7
* @author    aurelien <aurelien@tela-botanica.org>
7
* @author    aurelien <aurelien@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
10
* @version   SVN: <svn_id>
11
* @link      /doc/annuaire/
11
* @link      /doc/annuaire/
12
*/
12
*/
13
 
13
 
14
class StatistiquesControleur extends AppControleur {
14
class StatistiqueControleur extends AppControleur {
15
 
15
 
16
	private $statistiques = null;
16
	private $statistiques = null;
17
 
17
 
18
	private $champ_pays = '12';
18
	private $champ_pays = '12';
19
	private $onto_pays = '1074';
-
 
20
 
-
 
21
	private $champ_rapport_activite_bota = '102';
19
	private $champ_rapport_activite_bota = '102';
22
	private $onto_rapport_activite_bota = '30797';
-
 
23
 
-
 
24
	private $champ_experience_bota = '4';
20
	private $champ_experience_bota = '4';
25
	private $onto_experience_bota = '30785';
-
 
26
 
21
 
-
 
22
	public function StatistiqueControleur() {
-
 
23
		
27
	public function StatistiquesControleur() {
24
		$this->__construct();
28
		$this->statistiques = Composant::fabrique('statistiques', array());
25
		$this->statistiques = Composant::fabrique('statistiques', array());
29
	}
26
	}
30
 
27
	
31
	public function obtenirGraphiques($id_annuaire) {
28
	public function obtenirStatistiquesInscritsParContinents($id_annuaire) {
32
 
29
		
-
 
30
		$cartographe = new CartoControleur();
33
		$graph = array();
31
		$annuaire_controleur = new AnnuaireControleur();
-
 
32
		
-
 
33
		$continents = array('Afrique (%1.2f%%)' => 'pays_afrique',
-
 
34
		 							'Amerique du nord (%1.2f%%)' => 'pays_nord_amerique', 
-
 
35
		 							'Asie (%1.2f%%)' => 'pays_asie', 
34
 
36
		 							'Europe (%1.2f%%)' => 'pays_europe', 
-
 
37
		 							'Oceanie (%1.2f%%)' => 'pays_oceanie', 
-
 
38
		 							'Amerique du sud (%1.2f%%)' => 'pays_sud_amerique', 
-
 
39
		 							'Moyen Orient (%1.2f%%)' => 'pays_moyen_orient');
-
 
40
		
-
 
41
	    // pour chacun des continents, on fait la somme des membres de sa zone
35
		//$this->obtenirStatistiquesParPays($id_annuaire);
42
    	foreach($continents as $id_continent => $continent) {
36
		$graph['pays'] =  $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_pays, $this->onto_pays);
43
    		$zones_continent_ids = $cartographe->chargerInformationsPaysDuContinentsCsv($continent);
-
 
44
    		$nb_inscrits[$id_continent] = array_sum($annuaire_controleur->chargerNombreAnnuaireListeInscritsParPays($id_annuaire, array_keys($zones_continent_ids)));
-
 
45
    	}
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é');
46
    	
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');
47
    	$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits,'', array(650, 500));
39
 
48
    	
-
 
49
    	return $this->dessinerGraph($graph);
-
 
50
	}
-
 
51
	
40
		$image = $this->statistiques->combinerGraphiques($graph);
52
	public function obtenirStatistiquesInscritsEurope($id_annuaire) {
41
 
53
		
42
		// Envoi d'une image png
54
		$cartographe = new CartoControleur();
-
 
55
		$annuaire_controleur = new AnnuaireControleur();
-
 
56
		$cartographe = new CartoControleur();
-
 
57
		
-
 
58
		$ids_zones_europe = $cartographe->chargerInformationsPaysDuContinentsCsv('pays_europe');
43
		header("Content-type: image/png");
59
		
-
 
60
		//Debug::printr()
-
 
61
		$titre_zone = $this->convertirPourLegende($zone[2]);
-
 
62
    	$nb_inscrits_par_code = $annuaire_controleur->chargerNombreAnnuaireListeInscritsParPays($id_annuaire, array_keys($ids_zones_europe));
-
 
63
		
-
 
64
    	$nb_inscrits_par_legende = array();
-
 
65
    	
-
 
66
    	$inscrits_france = $nb_inscrits_par_code['fr'];
-
 
67
    	
-
 
68
    	unset($nb_inscrits_par_code['fr']);
-
 
69
    	$somme_autres_pays = 0;
-
 
70
    	
-
 
71
    	foreach($nb_inscrits_par_code as $code_pays => $inscrits_pays) {
-
 
72
    		
-
 
73
    		$label_pays = $this->convertirPourLegende($ids_zones_europe[$code_pays][2].' (%1.2f%%)');
-
 
74
    		$nb_inscrits_par_legende[$label_pays] = $inscrits_pays;
-
 
75
    		$somme_autres_pays += $inscrits_pays;
-
 
76
    	}
-
 
77
    	
44
		imagepng ($image);
78
    	$tableau_france_autres = array('France (%1.2f%%)' => $inscrits_france, 'Autres (%1.2f%%)' => $somme_autres_pays);
-
 
79
    	
-
 
80
    	$graph_france = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$tableau_france_autres,'', array(320, 200));
-
 
81
		$graph_autres = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits_par_legende,'', array(900, 700));
-
 
82
		$graph = $this->statistiques->combinerGraphiques($graph_france, $graph_autres, array(920, 1200));
45
 
83
		
46
		return $graph ;
84
		return $this->dessinerGraph($graph);
47
	}
85
	}
48
 
86
 
49
	public function obtenirStatistiquesParPays($id_annuaire, $titre = 'Répartition des inscrits par pays') {
87
	public function obtenirStatistiquesParPays($id_annuaire) {
-
 
88
 
50
 
89
	    $controleur = new AnnuaireControleur();
51
	    $controleur = new AnnuaireControleur();
90
	   	
-
 
91
	   	//$controleur = new AnnuaireControleur();
52
 
92
	    $modele_meta = new MetadonneeModele();
-
 
93
	   	$modele_onto = new OntologieModele();
53
	    $modele_meta = new MetadonneeModele();
94
	   	$id_champ = 12;
54
	   	$modele_onto = new OntologieModele();
95
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
55
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($this->champ_experience_bota);
96
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
56
	   	$legendes = $modele_onto->chargerListeOntologie($this->onto_experience_bota);
97
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
57
 
98
 
58
		$valeurs_a_stat_code = array();
99
		$valeurs_a_stat_code = array();
59
		$valeurs_a_stat_legende = array();
100
		$valeurs_a_stat_legende = array();
60
 
101
 
61
		foreach($valeurs as $valeur) {
102
		foreach($valeurs as $valeur) {
62
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
103
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
63
		}
104
		}
64
 
105
 
65
	    foreach($legendes as $legende) {
106
	    foreach($legendes as $legende) {
66
	    	$legende_nom = $legende['amo_nom'];
107
	    	$legende_nom = $legende['amo_nom'];
67
	    	$legende_code = $legende['amo_id_ontologie'];
108
	    	$legende_code = $legende['amo_id_ontologie'];
68
 
109
 
69
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
110
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
70
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
111
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
71
	    	}
112
	    	}
72
	    }
113
	    }
73
 
114
 
-
 
115
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
74
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
116
	    return $this->dessinerGraph($graph);
75
 
117
 
76
	}
118
	}
77
 
119
 
78
	public function obtenirStatistiquesParCritere($id_annuaire, $id_champ, $id_onto, $titre = '') {
-
 
79
 
-
 
80
	    $controleur = new AnnuaireControleur();
120
	public function obtenirStatistiquesParCritere($id_annuaire, $code_champ, $titre = '') {
81
 
121
 
82
	    $modele_meta = new MetadonneeModele();
122
	    $modele_meta = new MetadonneeModele();
83
	   	$modele_onto = new OntologieModele();
123
	   	$modele_onto = new OntologieModele();
-
 
124
	   	$id_champ = $modele_meta->renvoyerIdChampMetadonneeParAbreviation($id_annuaire, $code_champ);
84
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
125
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
-
 
126
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
85
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
127
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
86
 
128
	   	
87
		$valeurs_a_stat_code = array();
129
		$valeurs_a_stat_code = array();
88
		$valeurs_a_stat_legende = array();
130
		$valeurs_a_stat_legende = array();
-
 
131
				
-
 
132
		$titre = $this->convertirPourLegende($titre);
89
 
133
 
90
		foreach($valeurs as $valeur) {
134
		foreach($valeurs as $valeur) {
91
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
135
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
92
		}
136
		}
93
 
137
		
94
	    foreach($legendes as $legende) {
138
	    foreach($legendes as $legende) {
95
	    	$legende_nom = $legende['amo_nom'];
139
	    	$legende_nom = $this->convertirPourLegende($legende['amo_nom']);
96
	    	$legende_code = $legende['amo_id_ontologie'];
140
	    	$legende_code = $legende['amo_id_ontologie'];
97
 
141
	    	
98
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
142
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
99
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
143
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
-
 
144
	    	} else {
-
 
145
	    		
100
	    	}
146
	    	}
101
	    }
147
	    }
102
 
148
	    
103
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre);
149
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre, array(650, 400));
-
 
150
		return $this->dessinerGraph($graph);
104
 
151
		
105
	}
152
	}
106
 
153
 
107
	public function obtenirStatistiquesParAnnees($id_annuaire) {
-
 
108
 
-
 
109
	    $controleur = new AnnuaireControleur();
-
 
110
 
-
 
111
	    $modele_stats = new StatistiquesModele();
-
 
112
	    $valeurs = $modele_stats->obtenirNombreInscriptionsParDate($id_annuaire);
-
 
-
 
154
	public function obtenirStatistiquesParAnnees($id_annuaire, $annee_fin = '') {
113
	   	$legendes = $modele_onto->chargerListeOntologie('1074');
155
 
114
 
156
	    $annuaire_modele = new AnnuaireModele();
115
 
157
 
116
		$valeurs_a_stat_code = array();
158
		$valeurs_a_stat_code = array();
117
		$valeurs_a_stat_legende = array();
159
		$valeurs_a_stat_legende = array();
-
 
160
			        
-
 
161
		$tab_mois = array("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Dec");
-
 
162
		
-
 
163
		$annee_debut = 2002;
-
 
164
		$mois = 4;
-
 
165
		$annee = 2002;
-
 
166
		$tps_debut = mktime(0,0,0,$mois,1,$annee);
-
 
167
		$tps_courant = $tps_debut;
-
 
168
		
-
 
169
		if($annee_fin != '') {
-
 
170
			$tps_fin = mktime(0,0,0,1,1,$annee_fin);
-
 
171
		} else {
-
 
172
			$tps_fin = time();// jour courant
-
 
173
		}
-
 
174
 
-
 
175
		//Requete par mois
118
 
176
		$i = 1;
-
 
177
		while  ($tps_courant <= $tps_fin) {
-
 
178
			
-
 
179
			if (($mois)/12 > 1) {
-
 
180
				$mois = 1;
-
 
181
				$annee = $annee+1;
-
 
182
			}
-
 
183
			
-
 
184
			$tps_mois_suivant = mktime(0,0,0,$mois+1,1,$annee);
-
 
185
			
-
 
186
			$nb_inscrits_dans_intervalle = $annuaire_modele->obtenirNombreInscriptionsDansIntervalleDate($id_annuaire, $tps_debut, $tps_courant);
119
		foreach($valeurs as $valeur) {
187
			
-
 
188
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_inscrits_dans_intervalle;
-
 
189
			
-
 
190
			$tps_courant = $tps_mois_suivant;
-
 
191
			$mois++;
120
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
192
			$i++;
121
		}
193
		}
-
 
194
 
122
 
195
		$nom_axeX = 'Mois depuis le 1er avril 2002'; 
123
	    foreach($legendes as $legende) {
196
		
-
 
197
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_COURBE,$valeurs_a_stat_legende, '', array(500,490), $nom_axeX, '');
-
 
198
	    return $this->dessinerGraph($graph);
-
 
199
 
-
 
200
	}
124
	    	$legende_nom = $legende['amo_nom'];
201
	
-
 
202
	public function ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type) {
-
 
203
		
-
 
204
		$this->chargerModele('StatistiqueModele');	
-
 
205
		$this->StatistiqueModele->ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type);
-
 
206
		
-
 
207
	}
-
 
208
	
125
	    	$legende_code = $legende['amo_id_ontologie'];
209
	public function obtenirDerniersEvenementsStatistique($id_annuaire, $type) {
-
 
210
		
126
 
211
		$this->chargerModele('StatistiqueModele');	
-
 
212
		return $this->StatistiqueModele->obtenirDerniersEvenementsStatistique($id_annuaire, $type);
-
 
213
		
-
 
214
	}
127
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
215
	
-
 
216
	private function dessinerGraph($graph) {
-
 
217
		return $this->statistiques->dessinerGraph($graph);
128
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
218
	}
-
 
219
	
-
 
220
	private function convertirPourLegende($texte) {	
-
 
221
 
-
 
222
		if(trim($texte) == '') {
-
 
223
			$texte = '' ;
-
 
224
		}
-
 
225
 
-
 
226
		$texte = str_replace(
-
 
227
			array(
-
 
228
				'à', 'â', 'ä', 'á', 'ã', 'å',
-
 
229
				'î', 'ï', 'ì', 'í', 
-
 
230
				'ô', 'ö', 'ò', 'ó', 'õ', 'ø', 
-
 
231
				'ù', 'û', 'ü', 'ú', 
-
 
232
				'é', 'è', 'ê', 'ë', 
-
 
233
				'ç', 'ÿ', 'ñ',
-
 
234
				'À', 'Â', 'Ä', 'Á', 'Ã', 'Å',
-
 
235
				'Î', 'Ï', 'Ì', 'Í', 
-
 
236
				'Ô', 'Ö', 'Ò', 'Ó', 'Õ', 'Ø', 
-
 
237
				'Ù', 'Û', 'Ü', 'Ú', 
-
 
238
				'É', 'È', 'Ê', 'Ë', 
-
 
239
				'Ç', 'Ÿ', 'Ñ',
-
 
240
			),
-
 
241
			array(
-
 
242
				'a', 'a', 'a', 'a', 'a', 'a', 
-
 
243
				'i', 'i', 'i', 'i', 
-
 
244
				'o', 'o', 'o', 'o', 'o', 'o', 
-
 
245
				'u', 'u', 'u', 'u', 
-
 
246
				'e', 'e', 'e', 'e', 
-
 
247
				'c', 'y', 'n', 
-
 
248
				'A', 'A', 'A', 'A', 'A', 'A', 
-
 
249
				'I', 'I', 'I', 'I', 
-
 
250
				'O', 'O', 'O', 'O', 'O', 'O', 
-
 
251
				'U', 'U', 'U', 'U', 
129
	    	}
252
				'E', 'E', 'E', 'E', 
130
	    }
-
 
131
 
253
				'C', 'Y', 'N', 
132
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
254
			),$texte);
133
 
255
		
134
	}
256
		return $texte;	
135
 
257
	}
136
}
258
}
137
?>
259
?>