Subversion Repositories Applications.annuaire

Rev

Rev 120 | Rev 247 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 120 Rev 231
Line 9... Line 9...
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
*/
Line 13... Line 13...
13
 
13
 
Line 14... Line 14...
14
class StatistiquesControleur extends AppControleur {
14
class StatistiqueControleur extends AppControleur {
Line 15... Line 15...
15
 
15
 
16
	private $statistiques = null;
-
 
17
 
-
 
18
	private $champ_pays = '12';
16
	private $statistiques = null;
19
	private $onto_pays = '1074';
-
 
20
 
-
 
21
	private $champ_rapport_activite_bota = '102';
17
 
22
	private $onto_rapport_activite_bota = '30797';
-
 
Line 23... Line 18...
23
 
18
	private $champ_pays = '12';
-
 
19
	private $champ_rapport_activite_bota = '102';
-
 
20
	private $champ_experience_bota = '4';
24
	private $champ_experience_bota = '4';
21
 
25
	private $onto_experience_bota = '30785';
22
	public function StatistiqueControleur() {
Line 26... Line 23...
26
 
23
		
Line 27... Line 24...
27
	public function StatistiquesControleur() {
24
		$this->__construct();
-
 
25
		$this->statistiques = Composant::fabrique('statistiques', array());
Line 28... Line 26...
28
		$this->statistiques = Composant::fabrique('statistiques', array());
26
	}
29
	}
27
	
-
 
28
	public function obtenirStatistiquesInscritsParContinents($id_annuaire) {
-
 
29
		
-
 
30
		$cartographe = new CartoControleur();
30
 
31
		$annuaire_controleur = new AnnuaireControleur();
31
	public function obtenirGraphiques($id_annuaire) {
32
		
Line -... Line 33...
-
 
33
		$continents = array('Afrique (%1.2f%%)' => 'pays_afrique',
32
 
34
		 							'Amerique du nord (%1.2f%%)' => 'pays_nord_amerique', 
-
 
35
		 							'Asie (%1.2f%%)' => 'pays_asie', 
-
 
36
		 							'Europe (%1.2f%%)' => 'pays_europe', 
-
 
37
		 							'Oceanie (%1.2f%%)' => 'pays_oceanie', 
Line 33... Line -...
33
		$graph = array();
-
 
34
 
38
		 							'Amerique du sud (%1.2f%%)' => 'pays_sud_amerique', 
35
		//$this->obtenirStatistiquesParPays($id_annuaire);
-
 
Line 36... Line 39...
36
		$graph['pays'] =  $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_pays, $this->onto_pays);
39
		 							'Moyen Orient (%1.2f%%)' => 'pays_moyen_orient');
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é');
40
		
Line -... Line 41...
-
 
41
	    // pour chacun des continents, on fait la somme des membres de sa zone
-
 
42
    	foreach($continents as $id_continent => $continent) {
-
 
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
    	}
-
 
46
    	
-
 
47
    	$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits,'', array(650, 500));
-
 
48
    	
-
 
49
    	return $this->dessinerGraph($graph);
-
 
50
	}
-
 
51
	
-
 
52
	public function obtenirStatistiquesInscritsEurope($id_annuaire) {
-
 
53
		
-
 
54
		$cartographe = new CartoControleur();
-
 
55
		$annuaire_controleur = new AnnuaireControleur();
-
 
56
		$cartographe = new CartoControleur();
-
 
57
		
-
 
58
		$ids_zones_europe = $cartographe->chargerInformationsPaysDuContinentsCsv('pays_europe');
-
 
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;
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');
76
    	}
Line 39... Line 77...
39
 
77
    	
Line -... Line 78...
-
 
78
    	$tableau_france_autres = array('France (%1.2f%%)' => $inscrits_france, 'Autres (%1.2f%%)' => $somme_autres_pays);
40
		$image = $this->statistiques->combinerGraphiques($graph);
79
    	
41
 
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));
42
		// Envoi d'une image png
82
		$graph = $this->statistiques->combinerGraphiques($graph_france, $graph_autres, array(920, 1200));
-
 
83
		
43
		header("Content-type: image/png");
84
		return $this->dessinerGraph($graph);
Line 44... Line 85...
44
		imagepng ($image);
85
	}
45
 
86
 
Line 46... Line 87...
46
		return $graph ;
87
	public function obtenirStatistiquesParPays($id_annuaire) {
Line 69... Line 110...
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
	    }
Line 73... Line 114...
73
 
114
 
-
 
115
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
Line 74... Line 116...
74
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
116
	    return $this->dessinerGraph($graph);
Line 75... Line 117...
75
 
117
 
76
	}
-
 
77
 
-
 
Line 78... Line 118...
78
	public function obtenirStatistiquesParCritere($id_annuaire, $id_champ, $id_onto, $titre = '') {
118
	}
79
 
119
 
-
 
120
	public function obtenirStatistiquesParCritere($id_annuaire, $code_champ, $titre = '') {
80
	    $controleur = new AnnuaireControleur();
121
 
-
 
122
	    $modele_meta = new MetadonneeModele();
81
 
123
	   	$modele_onto = new OntologieModele();
Line 82... Line 124...
82
	    $modele_meta = new MetadonneeModele();
124
	   	$id_champ = $modele_meta->renvoyerIdChampMetadonneeParAbreviation($id_annuaire, $code_champ);
83
	   	$modele_onto = new OntologieModele();
125
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
Line -... Line 126...
-
 
126
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
-
 
127
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
84
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
128
	   	
85
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
129
		$valeurs_a_stat_code = array();
86
 
130
		$valeurs_a_stat_legende = array();
Line 87... Line 131...
87
		$valeurs_a_stat_code = array();
131
				
88
		$valeurs_a_stat_legende = array();
132
		$titre = $this->convertirPourLegende($titre);
89
 
133
 
Line 90... Line 134...
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'];
-
 
136
		}
-
 
137
		
92
		}
138
	    foreach($legendes as $legende) {
93
 
139
	    	$legende_nom = $this->convertirPourLegende($legende['amo_nom']);
Line 94... Line 140...
94
	    foreach($legendes as $legende) {
140
	    	$legende_code = $legende['amo_id_ontologie'];
-
 
141
	    	
Line 95... Line 142...
95
	    	$legende_nom = $legende['amo_nom'];
142
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
Line 96... Line 143...
96
	    	$legende_code = $legende['amo_id_ontologie'];
143
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
97
 
-
 
98
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
-
 
99
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
-
 
100
	    	}
-
 
101
	    }
-
 
102
 
-
 
Line -... Line 144...
-
 
144
	    	} else {
Line 103... Line 145...
103
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre);
145
	    		
104
 
146
	    	}
Line -... Line 147...
-
 
147
	    }
-
 
148
	    
-
 
149
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre, array(650, 400));
-
 
150
		return $this->dessinerGraph($graph);
-
 
151
		
-
 
152
	}
-
 
153
 
-
 
154
	public function obtenirStatistiquesParAnnees($id_annuaire, $annee_fin = '') {
105
	}
155
 
106
 
156
	    $annuaire_modele = new AnnuaireModele();
-
 
157
 
-
 
158
		$valeurs_a_stat_code = array();
107
	public function obtenirStatistiquesParAnnees($id_annuaire) {
159
		$valeurs_a_stat_legende = array();
Line -... Line 160...
-
 
160
			        
-
 
161
		$tab_mois = array("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aout","Sep","Oct","Nov","Dec");
108
 
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
-
 
176
		$i = 1;
-
 
177
		while  ($tps_courant <= $tps_fin) {
-
 
178
			
-
 
179
			if (($mois)/12 > 1) {
-
 
180
				$mois = 1;
-
 
181
				$annee = $annee+1;
-
 
182
			}
109
	    $controleur = new AnnuaireControleur();
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);
-
 
187
			
-
 
188
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_inscrits_dans_intervalle;
110
 
189
			
-
 
190
			$tps_courant = $tps_mois_suivant;
Line 111... Line -...
111
	    $modele_stats = new StatistiquesModele();
-
 
112
	    $valeurs = $modele_stats->obtenirNombreInscriptionsParDate($id_annuaire);
-
 
113
	   	$legendes = $modele_onto->chargerListeOntologie('1074');
191
			$mois++;
-
 
192
			$i++;
-
 
193
		}
-
 
194
 
-
 
195
		$nom_axeX = 'Mois depuis le 1er avril 2002'; 
-
 
196
		
-
 
197
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_COURBE,$valeurs_a_stat_legende, '', array(500,490), $nom_axeX, '');
114
 
198
	    return $this->dessinerGraph($graph);
Line -... Line 199...
-
 
199
 
115
 
200
	}
-
 
201
	
Line -... Line 202...
-
 
202
	public function ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type) {
-
 
203
		
-
 
204
		$this->chargerModele('StatistiqueModele');	
-
 
205
		$this->StatistiqueModele->ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type);
116
		$valeurs_a_stat_code = array();
206
		
Line -... Line 207...
-
 
207
	}
-
 
208
	
-
 
209
	public function obtenirDerniersEvenementsStatistique($id_annuaire, $type) {
-
 
210
		
-
 
211
		$this->chargerModele('StatistiqueModele');	
-
 
212
		return $this->StatistiqueModele->obtenirDerniersEvenementsStatistique($id_annuaire, $type);
-
 
213
		
-
 
214
	}
-
 
215
	
-
 
216
	private function dessinerGraph($graph) {
-
 
217
		return $this->statistiques->dessinerGraph($graph);
-
 
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
				'É', 'È', 'Ê', 'Ë', 
117
		$valeurs_a_stat_legende = array();
239
				'Ç', 'Ÿ', 'Ñ',
118
 
240
			),