Subversion Repositories Applications.annuaire

Rev

Rev 294 | Rev 429 | Go to most recent revision | Details | Compare with Previous | 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
 
231 aurelien 14
class StatistiqueControleur extends AppControleur {
61 aurelien 15
 
16
	private $statistiques = null;
17
 
231 aurelien 18
	public function StatistiqueControleur() {
19
 
20
		$this->__construct();
61 aurelien 21
		$this->statistiques = Composant::fabrique('statistiques', array());
22
	}
231 aurelien 23
 
24
	public function obtenirStatistiquesInscritsParContinents($id_annuaire) {
25
 
26
		$cartographe = new CartoControleur();
27
		$annuaire_controleur = new AnnuaireControleur();
28
 
29
		$continents = array('Afrique (%1.2f%%)' => 'pays_afrique',
30
		 							'Amerique du nord (%1.2f%%)' => 'pays_nord_amerique',
31
		 							'Asie (%1.2f%%)' => 'pays_asie',
32
		 							'Europe (%1.2f%%)' => 'pays_europe',
33
		 							'Oceanie (%1.2f%%)' => 'pays_oceanie',
34
		 							'Amerique du sud (%1.2f%%)' => 'pays_sud_amerique',
35
		 							'Moyen Orient (%1.2f%%)' => 'pays_moyen_orient');
294 aurelien 36
 
231 aurelien 37
	    // pour chacun des continents, on fait la somme des membres de sa zone
38
    	foreach($continents as $id_continent => $continent) {
39
    		$zones_continent_ids = $cartographe->chargerInformationsPaysDuContinentsCsv($continent);
294 aurelien 40
    		$zones_continent_ids = array_map(array($this,'miniQuote'), array_keys($zones_continent_ids));
41
    		$nb_inscrits[$id_continent] = array_sum($annuaire_controleur->chargerNombreAnnuaireListeInscritsParPays($id_annuaire, $zones_continent_ids));
231 aurelien 42
    	}
294 aurelien 43
 
231 aurelien 44
    	$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits,'', array(650, 500));
45
 
46
    	return $this->dessinerGraph($graph);
61 aurelien 47
	}
231 aurelien 48
 
49
	public function obtenirStatistiquesInscritsEurope($id_annuaire) {
50
 
51
		$cartographe = new CartoControleur();
52
		$annuaire_controleur = new AnnuaireControleur();
53
		$cartographe = new CartoControleur();
54
 
55
		$ids_zones_europe = $cartographe->chargerInformationsPaysDuContinentsCsv('pays_europe');
294 aurelien 56
 
57
		$codes_zones_europe = array_map(array($this,'miniQuote'), array_keys($ids_zones_europe));
58
 
231 aurelien 59
		$titre_zone = $this->convertirPourLegende($zone[2]);
294 aurelien 60
    	$nb_inscrits_par_code = $annuaire_controleur->chargerNombreAnnuaireListeInscritsParPays($id_annuaire, $codes_zones_europe);
231 aurelien 61
 
62
    	$nb_inscrits_par_legende = array();
63
 
64
    	$inscrits_france = $nb_inscrits_par_code['fr'];
65
 
66
    	unset($nb_inscrits_par_code['fr']);
67
    	$somme_autres_pays = 0;
68
 
69
    	foreach($nb_inscrits_par_code as $code_pays => $inscrits_pays) {
70
 
71
    		$label_pays = $this->convertirPourLegende($ids_zones_europe[$code_pays][2].' (%1.2f%%)');
72
    		$nb_inscrits_par_legende[$label_pays] = $inscrits_pays;
73
    		$somme_autres_pays += $inscrits_pays;
74
    	}
294 aurelien 75
 
231 aurelien 76
    	$tableau_france_autres = array('France (%1.2f%%)' => $inscrits_france, 'Autres (%1.2f%%)' => $somme_autres_pays);
77
 
78
    	$graph_france = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$tableau_france_autres,'', array(320, 200));
79
		$graph_autres = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits_par_legende,'', array(900, 700));
80
		$graph = $this->statistiques->combinerGraphiques($graph_france, $graph_autres, array(920, 1200));
81
 
82
		return $this->dessinerGraph($graph);
83
	}
61 aurelien 84
 
231 aurelien 85
	public function obtenirStatistiquesParPays($id_annuaire) {
61 aurelien 86
 
87
	    $controleur = new AnnuaireControleur();
231 aurelien 88
 
89
	   	//$controleur = new AnnuaireControleur();
61 aurelien 90
	    $modele_meta = new MetadonneeModele();
91
	   	$modele_onto = new OntologieModele();
231 aurelien 92
	   	$id_champ = 12;
93
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
94
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
95
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
61 aurelien 96
 
97
		$valeurs_a_stat_code = array();
98
		$valeurs_a_stat_legende = array();
99
 
100
		foreach($valeurs as $valeur) {
101
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
102
		}
103
 
104
	    foreach($legendes as $legende) {
105
	    	$legende_nom = $legende['amo_nom'];
106
	    	$legende_code = $legende['amo_id_ontologie'];
107
 
108
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
109
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
110
	    	}
111
	    }
112
 
231 aurelien 113
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
114
	    return $this->dessinerGraph($graph);
61 aurelien 115
 
116
	}
117
 
231 aurelien 118
	public function obtenirStatistiquesParCritere($id_annuaire, $code_champ, $titre = '') {
61 aurelien 119
 
120
	    $modele_meta = new MetadonneeModele();
121
	   	$modele_onto = new OntologieModele();
231 aurelien 122
	   	$id_champ = $modele_meta->renvoyerIdChampMetadonneeParAbreviation($id_annuaire, $code_champ);
61 aurelien 123
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
231 aurelien 124
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
61 aurelien 125
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
231 aurelien 126
 
61 aurelien 127
		$valeurs_a_stat_code = array();
128
		$valeurs_a_stat_legende = array();
231 aurelien 129
 
130
		$titre = $this->convertirPourLegende($titre);
61 aurelien 131
 
132
		foreach($valeurs as $valeur) {
133
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
134
		}
231 aurelien 135
 
61 aurelien 136
	    foreach($legendes as $legende) {
231 aurelien 137
	    	$legende_nom = $this->convertirPourLegende($legende['amo_nom']);
61 aurelien 138
	    	$legende_code = $legende['amo_id_ontologie'];
231 aurelien 139
 
61 aurelien 140
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
141
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
231 aurelien 142
	    	} else {
143
 
61 aurelien 144
	    	}
145
	    }
231 aurelien 146
 
147
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre, array(650, 400));
148
		return $this->dessinerGraph($graph);
149
 
61 aurelien 150
	}
404 aurelien 151
 
152
	public function obtenirStatistiquesPourAnnee($id_annuaire, $annee = null) {
153
 
154
		$annee = ($annee == null) ? date("Y") : $annee;
155
		$annuaire_modele = new AnnuaireModele();
156
 
157
		$valeurs_a_stat_code = array();
158
		$valeurs_a_stat_legende = array();
159
 
160
		$tab_mois = array("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Dec");
161
 
162
		$annee_debut = $annee;
163
		$mois = 1;
164
		$annee = $annee;
165
		$tps_debut = mktime(0,0,0,1,1,$annee);
166
		$tps_courant = $tps_debut;
167
 
168
		$annee_courante = date("Y");
169
		if($annee_fin == $annee_courante) {
170
			$tps_fin = time();// jour courant
171
		} else {
172
			$tps_fin = mktime(0,0,0,1,1,$annee+1);
173
		}
174
 
175
		//Requete par mois
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
			$nb_inscrits_dans_intervalle = $annuaire_modele->obtenirNombreInscriptionsDansIntervalleDate($id_annuaire, $tps_debut, $tps_courant);
186
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_inscrits_dans_intervalle;
187
 
188
			$tps_courant = $tps_mois_suivant;
189
			$mois++;
190
			$i++;
191
		}
192
 
193
		$nom_axeX = 'Mois depuis le 1er janvier '.$annee;
194
 
195
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_COURBE,$valeurs_a_stat_legende, '', array(500,490), $nom_axeX, '');
196
		return $this->dessinerGraph($graph);
197
	}
61 aurelien 198
 
231 aurelien 199
	public function obtenirStatistiquesParAnnees($id_annuaire, $annee_fin = '') {
61 aurelien 200
 
231 aurelien 201
	    $annuaire_modele = new AnnuaireModele();
61 aurelien 202
 
203
		$valeurs_a_stat_code = array();
204
		$valeurs_a_stat_legende = array();
231 aurelien 205
 
206
		$tab_mois = array("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Dec");
207
 
208
		$annee_debut = 2002;
209
		$mois = 4;
210
		$annee = 2002;
211
		$tps_debut = mktime(0,0,0,$mois,1,$annee);
212
		$tps_courant = $tps_debut;
213
 
214
		if($annee_fin != '') {
215
			$tps_fin = mktime(0,0,0,1,1,$annee_fin);
216
		} else {
217
			$tps_fin = time();// jour courant
218
		}
61 aurelien 219
 
231 aurelien 220
		//Requete par mois
221
		$i = 1;
222
		while  ($tps_courant <= $tps_fin) {
223
 
224
			if (($mois)/12 > 1) {
225
				$mois = 1;
226
				$annee = $annee+1;
227
			}
228
 
229
			$tps_mois_suivant = mktime(0,0,0,$mois+1,1,$annee);
230
 
231
			$nb_inscrits_dans_intervalle = $annuaire_modele->obtenirNombreInscriptionsDansIntervalleDate($id_annuaire, $tps_debut, $tps_courant);
232
 
233
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_inscrits_dans_intervalle;
234
 
235
			$tps_courant = $tps_mois_suivant;
236
			$mois++;
237
			$i++;
61 aurelien 238
		}
239
 
231 aurelien 240
		$nom_axeX = 'Mois depuis le 1er avril 2002';
241
 
242
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_COURBE,$valeurs_a_stat_legende, '', array(500,490), $nom_axeX, '');
243
	    return $this->dessinerGraph($graph);
61 aurelien 244
 
231 aurelien 245
	}
246
 
247 aurelien 247
	public function obtenirStatistiquesModificationsProfil($id_annuaire, $annee_fin = '') {
248
 
249
	    $modele = new StatistiqueModele();
250
 
251
		$valeurs_a_stat_code = array();
252
		$valeurs_a_stat_legende = array();
253
 
254
		$tab_mois = array("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Dec");
255
 
256
		$annee_debut = 2010;
294 aurelien 257
		$mois = 1;
247 aurelien 258
		$annee = 2010;
259
		$tps_debut = mktime(0,0,0,$mois,1,$annee);
260
		$tps_courant = $tps_debut;
261
 
262
		if($annee_fin != '') {
263
			$tps_fin = mktime(0,0,0,1,1,$annee_fin);
264
		} else {
265
			$today = date_parse(date('Y-m-d H:i:s'));
266
 
267
			$annee_fin_today = $today['year'];
268
			$mois_fin_today = $today['month'];
269
 
270
			if($annee_debut == $annee_fin_today) {
271
				$tps_fin = mktime(0,0,0,$mois_fin_today+1,1,$annee_fin_today);
272
			} else {
273
				$tps_fin = time();// jour courant
274
			}
275
		}
276
 
277
		//Requete par mois
278
		$i = 1;
279
		while  ($tps_courant <= $tps_fin) {
280
 
281
			if (($mois)/12 > 1) {
282
				$mois = 1;
283
				$annee = $annee+1;
284
			}
285
 
286
			$tps_mois_suivant = mktime(0,0,0,$mois+1,1,$annee);
287
 
288
			$nb_modif_dans_intervalle = $modele->obtenirEvenementsDansIntervalle($id_annuaire,'modification', $tps_debut, $tps_courant);
289
 
290
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_modif_dans_intervalle;
291
 
292
			$tps_courant = $tps_mois_suivant;
293
			$mois++;
294
			$i++;
295
		}
296
 
297
		$nom_axeX = 'Mois depuis le 1er juillet 2010';
298
 
299
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_COURBE,$valeurs_a_stat_legende, '', array(500,490), $nom_axeX, '');
300
	    return $this->dessinerGraph($graph);
301
 
302
	}
303
 
231 aurelien 304
	public function ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type) {
305
 
306
		$this->chargerModele('StatistiqueModele');
307
		$this->StatistiqueModele->ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type);
308
 
309
	}
310
 
311
	public function obtenirDerniersEvenementsStatistique($id_annuaire, $type) {
312
 
313
		$this->chargerModele('StatistiqueModele');
314
		return $this->StatistiqueModele->obtenirDerniersEvenementsStatistique($id_annuaire, $type);
315
 
316
	}
317
 
318
	private function dessinerGraph($graph) {
319
		return $this->statistiques->dessinerGraph($graph);
320
	}
321
 
322
	private function convertirPourLegende($texte) {
61 aurelien 323
 
231 aurelien 324
		if(trim($texte) == '') {
325
			$texte = '' ;
326
		}
61 aurelien 327
 
231 aurelien 328
		$texte = str_replace(
329
			array(
330
				'à', 'â', 'ä', 'á', 'ã', 'å',
331
				'î', 'ï', 'ì', 'í',
332
				'ô', 'ö', 'ò', 'ó', 'õ', 'ø',
333
				'ù', 'û', 'ü', 'ú',
334
				'é', 'è', 'ê', 'ë',
335
				'ç', 'ÿ', 'ñ',
336
				'À', 'Â', 'Ä', 'Á', 'Ã', 'Å',
337
				'Î', 'Ï', 'Ì', 'Í',
338
				'Ô', 'Ö', 'Ò', 'Ó', 'Õ', 'Ø',
339
				'Ù', 'Û', 'Ü', 'Ú',
340
				'É', 'È', 'Ê', 'Ë',
341
				'Ç', 'Ÿ', 'Ñ',
342
			),
343
			array(
344
				'a', 'a', 'a', 'a', 'a', 'a',
345
				'i', 'i', 'i', 'i',
346
				'o', 'o', 'o', 'o', 'o', 'o',
347
				'u', 'u', 'u', 'u',
348
				'e', 'e', 'e', 'e',
349
				'c', 'y', 'n',
350
				'A', 'A', 'A', 'A', 'A', 'A',
351
				'I', 'I', 'I', 'I',
352
				'O', 'O', 'O', 'O', 'O', 'O',
353
				'U', 'U', 'U', 'U',
354
				'E', 'E', 'E', 'E',
355
				'C', 'Y', 'N',
356
			),$texte);
357
 
358
		return $texte;
61 aurelien 359
	}
294 aurelien 360
 
361
	private function miniQuote($chaine) {
362
		return "'".$chaine."'";
363
	}
61 aurelien 364
}
294 aurelien 365
?>