Subversion Repositories Applications.annuaire

Rev

Rev 120 | Rev 247 | Go to most recent revision | Show entire file | Ignore 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() {
26
 
23
		
27
	public function StatistiquesControleur() {
24
		$this->__construct();
28
		$this->statistiques = Composant::fabrique('statistiques', array());
25
		$this->statistiques = Composant::fabrique('statistiques', array());
29
	}
26
	}
-
 
27
	
30
 
28
	public function obtenirStatistiquesInscritsParContinents($id_annuaire) {
-
 
29
		
-
 
30
		$cartographe = new CartoControleur();
-
 
31
		$annuaire_controleur = new AnnuaireControleur();
-
 
32
		
31
	public function obtenirGraphiques($id_annuaire) {
33
		$continents = array('Afrique (%1.2f%%)' => 'pays_afrique',
-
 
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', 
-
 
38
		 							'Amerique du sud (%1.2f%%)' => 'pays_sud_amerique', 
32
 
39
		 							'Moyen Orient (%1.2f%%)' => 'pays_moyen_orient');
33
		$graph = array();
40
		
-
 
41
	    // pour chacun des continents, on fait la somme des membres de sa zone
-
 
42
    	foreach($continents as $id_continent => $continent) {
34
 
43
    		$zones_continent_ids = $cartographe->chargerInformationsPaysDuContinentsCsv($continent);
35
		//$this->obtenirStatistiquesParPays($id_annuaire);
44
    		$nb_inscrits[$id_continent] = array_sum($annuaire_controleur->chargerNombreAnnuaireListeInscritsParPays($id_annuaire, array_keys($zones_continent_ids)));
36
		$graph['pays'] =  $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_pays, $this->onto_pays);
45
    	}
-
 
46
    	
-
 
47
    	$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits,'', array(650, 500));
-
 
48
    	
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é');
49
    	return $this->dessinerGraph($graph);
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');
50
	}
39
 
51
	
-
 
52
	public function obtenirStatistiquesInscritsEurope($id_annuaire) {
-
 
53
		
-
 
54
		$cartographe = new CartoControleur();
-
 
55
		$annuaire_controleur = new AnnuaireControleur();
40
		$image = $this->statistiques->combinerGraphiques($graph);
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;
41
 
75
    		$somme_autres_pays += $inscrits_pays;
-
 
76
    	}
-
 
77
    	
-
 
78
    	$tableau_france_autres = array('France (%1.2f%%)' => $inscrits_france, 'Autres (%1.2f%%)' => $somme_autres_pays);
-
 
79
    	
42
		// Envoi d'une image png
80
    	$graph_france = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$tableau_france_autres,'', array(320, 200));
43
		header("Content-type: image/png");
81
		$graph_autres = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$nb_inscrits_par_legende,'', array(900, 700));
Line 44... Line 82...
44
		imagepng ($image);
82
		$graph = $this->statistiques->combinerGraphiques($graph_france, $graph_autres, array(920, 1200));
Line 45... Line 83...
45
 
83
		
46
		return $graph ;
84
		return $this->dessinerGraph($graph);
-
 
85
	}
47
	}
86
 
48
 
87
	public function obtenirStatistiquesParPays($id_annuaire) {
-
 
88
 
49
	public function obtenirStatistiquesParPays($id_annuaire, $titre = 'Répartition des inscrits par pays') {
89
	    $controleur = new AnnuaireControleur();
-
 
90
	   	
50
 
91
	   	//$controleur = new AnnuaireControleur();
Line 51... Line 92...
51
	    $controleur = new AnnuaireControleur();
92
	    $modele_meta = new MetadonneeModele();
52
 
93
	   	$modele_onto = new OntologieModele();
Line 53... Line 94...
53
	    $modele_meta = new MetadonneeModele();
94
	   	$id_champ = 12;
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();
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);
84
	    $valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
126
	    $id_onto = $modele_meta->obtenirOntologieLieeAChampParId($id_champ);
-
 
127
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
-
 
128
	   	
Line 85... Line 129...
85
	   	$legendes = $modele_onto->chargerListeOntologie($id_onto);
129
		$valeurs_a_stat_code = array();
86
 
130
		$valeurs_a_stat_legende = array();
87
		$valeurs_a_stat_code = array();
131
				
88
		$valeurs_a_stat_legende = array();
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) {
-
 
139
	    	$legende_nom = $this->convertirPourLegende($legende['amo_nom']);
-
 
140
	    	$legende_code = $legende['amo_id_ontologie'];
95
	    	$legende_nom = $legende['amo_nom'];
141
	    	
96
	    	$legende_code = $legende['amo_id_ontologie'];
142
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
97
 
143
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
98
	    	if(isset($valeurs_a_stat_code[$legende_code])) {
144
	    	} else {
-
 
145
	    		
99
				$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
146
	    	}
100
	    	}
147
	    }
Line 101... Line 148...
101
	    }
148
	    
102
 
-
 
103
		return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre);
-
 
104
 
-
 
105
	}
-
 
106
 
-
 
107
	public function obtenirStatistiquesParAnnees($id_annuaire) {
-
 
Line -... Line 149...
-
 
149
		$graph = $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre, array(650, 400));
Line 108... Line 150...
108
 
150
		return $this->dessinerGraph($graph);
109
	    $controleur = new AnnuaireControleur();
151
		
-
 
152
	}
-
 
153
 
-
 
154
	public function obtenirStatistiquesParAnnees($id_annuaire, $annee_fin = '') {
-
 
155
 
-
 
156
	    $annuaire_modele = new AnnuaireModele();
-
 
157
 
-
 
158
		$valeurs_a_stat_code = 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;
Line -... Line 166...
-
 
166
		$tps_debut = mktime(0,0,0,$mois,1,$annee);
-
 
167
		$tps_courant = $tps_debut;
110
 
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
			
111
	    $modele_stats = new StatistiquesModele();
179
			if (($mois)/12 > 1) {
-
 
180
				$mois = 1;
-
 
181
				$annee = $annee+1;
-
 
182
			}
-
 
183
			
112
	    $valeurs = $modele_stats->obtenirNombreInscriptionsParDate($id_annuaire);
184
			$tps_mois_suivant = mktime(0,0,0,$mois+1,1,$annee);
Line 113... Line 185...
113
	   	$legendes = $modele_onto->chargerListeOntologie('1074');
185
			
-
 
186
			$nb_inscrits_dans_intervalle = $annuaire_modele->obtenirNombreInscriptionsDansIntervalleDate($id_annuaire, $tps_debut, $tps_courant);
114
 
187
			
115
 
188
			$valeurs_a_stat_legende[$tab_mois[$mois-1].' '.$annee] = $nb_inscrits_dans_intervalle;
Line -... Line 189...
-
 
189
			
-
 
190
			$tps_courant = $tps_mois_suivant;
-
 
191
			$mois++;
-
 
192
			$i++;
116
		$valeurs_a_stat_code = array();
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, '');
-
 
198
	    return $this->dessinerGraph($graph);
-
 
199
 
-
 
200
	}
117
		$valeurs_a_stat_legende = array();
201
	
-
 
202
	public function ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type) {
118
 
203
		
-
 
204
		$this->chargerModele('StatistiqueModele');	
-
 
205
		$this->StatistiqueModele->ajouterEvenementStatistique($id_annuaire, $id_utilisateur, $type);
-
 
206
		
119
		foreach($valeurs as $valeur) {
207
	}
-
 
208
	
-
 
209
	public function obtenirDerniersEvenementsStatistique($id_annuaire, $type) {
Line 120... Line 210...
120
			$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
210
		
-
 
211
		$this->chargerModele('StatistiqueModele');	
-
 
212
		return $this->StatistiqueModele->obtenirDerniersEvenementsStatistique($id_annuaire, $type);
Line -... Line 213...
-
 
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
				'É', 'È', 'Ê', 'Ë', 
-
 
239
				'Ç', 'Ÿ', 'Ñ',
-
 
240
			),
-
 
241
			array(
-
 
242
				'a', 'a', 'a', 'a', 'a', 'a', 
-
 
243
				'i', 'i', 'i', 'i', 
121
		}
244
				'o', 'o', 'o', 'o', 'o', 'o', 
122
 
-
 
123
	    foreach($legendes as $legende) {
245
				'u', 'u', 'u', 'u', 
124
	    	$legende_nom = $legende['amo_nom'];
246
				'e', 'e', 'e', 'e',