Subversion Repositories Applications.annuaire

Compare Revisions

Ignore whitespace Rev 60 → Rev 61

/trunk/controleurs/StatistiquesControleur.php
New file
0,0 → 1,148
<?php
/**
* PHP Version 5
*
* @category PHP
* @package annuaire
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2010 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/annuaire/
*/
 
class StatistiquesControleur extends Controleur {
 
private $statistiques = null;
 
private $champ_pays = '12';
private $onto_pays = '1074';
 
private $champ_rapport_activite_bota = '102';
private $onto_rapport_activite_bota = '30797';
 
private $champ_experience_bota = '4';
private $onto_experience_bota = '30785';
 
public function StatistiquesControleur() {
$this->statistiques = Composant::fabrique('statistiques', array());
}
 
public function obtenirGraphiques($id_annuaire) {
 
$graph = array();
 
//$this->obtenirStatistiquesParPays($id_annuaire);
$graph['pays'] = $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_pays, $this->onto_pays);
$graph['activite_bota'] = $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_rapport_activite_bota, $this->onto_rapport_activite_bota, 'Répartition des inscrits selon leur activité');
$graph['experience_bota'] = $this->obtenirStatistiquesParCritere($id_annuaire, $this->champ_experience_bota, $this->onto_experience_bota, 'Répartition des inscrits selon leur expérience botanique');
 
/*$WIDTH1 = $WIDTH2 = $WIDTH3 = 500;
$HEIGHT1 = $HEIGHT2 = $HEIGHT3 = 1500;
 
$image = imagecreatetruecolor(500,1500);
imagecopy($image, $graph['pays'],0, 0, 0, 0, $WIDTH1,$HEIGHT1);
imagecopy($image, $graph['activite_bota'],0, 500, 0, 0, $WIDTH1,$HEIGHT1);
imagecopy($image, $graph['experience_bota'],0, 1000, 0, 0, $WIDTH1,$HEIGHT1);*/
 
//Debug::printr($graph);
 
//TODO remplacer le fouillis ci dessus par ce qui suit
$image = $this->statistiques->combinerGraphiques($graph);
 
// Stream the result back as a PNG image
header("Content-type: image/png");
imagepng ($image);
 
return $graph ;
}
 
public function obtenirStatistiquesParPays($id_annuaire, $titre = 'Répartition des inscrits par pays') {
 
$controleur = new AnnuaireControleur();
 
$modele_meta = new MetadonneeModele();
$modele_onto = new OntologieModele();
$valeurs = $modele_meta->obtenirNombreValeurMetadonnee($this->champ_experience_bota);
$legendes = $modele_onto->chargerListeOntologie($this->onto_experience_bota);
 
$valeurs_a_stat_code = array();
$valeurs_a_stat_legende = array();
 
foreach($valeurs as $valeur) {
$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
}
 
foreach($legendes as $legende) {
$legende_nom = $legende['amo_nom'];
$legende_code = $legende['amo_id_ontologie'];
 
if(isset($valeurs_a_stat_code[$legende_code])) {
$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
}
}
 
return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
 
}
 
public function obtenirStatistiquesParCritere($id_annuaire, $id_champ, $id_onto, $titre = '') {
 
$controleur = new AnnuaireControleur();
 
$modele_meta = new MetadonneeModele();
$modele_onto = new OntologieModele();
$valeurs = $modele_meta->obtenirNombreValeurMetadonnee($id_champ);
$legendes = $modele_onto->chargerListeOntologie($id_onto);
 
$valeurs_a_stat_code = array();
$valeurs_a_stat_legende = array();
 
foreach($valeurs as $valeur) {
$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
}
 
foreach($legendes as $legende) {
$legende_nom = $legende['amo_nom'];
$legende_code = $legende['amo_id_ontologie'];
 
if(isset($valeurs_a_stat_code[$legende_code])) {
$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
}
}
 
return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende, $titre);
 
}
 
public function obtenirStatistiquesParAnnees($id_annuaire) {
 
$controleur = new AnnuaireControleur();
 
$modele_stats = new StatistiquesModele();
$valeurs = $modele_stats->obtenirNombreInscriptionsParDate($id_annuaire);
$legendes = $modele_onto->chargerListeOntologie('1074');
 
 
$valeurs_a_stat_code = array();
$valeurs_a_stat_legende = array();
 
foreach($valeurs as $valeur) {
$valeurs_a_stat_code[$valeur['amv_valeur']] = $valeur['nb'];
}
 
foreach($legendes as $legende) {
$legende_nom = $legende['amo_nom'];
$legende_code = $legende['amo_id_ontologie'];
 
if(isset($valeurs_a_stat_code[$legende_code])) {
$valeurs_a_stat_legende[$legende_nom] = $valeurs_a_stat_code[$legende_code];
}
}
 
return $this->statistiques->genererGraphique(Statistiques::GRAPH_CAMEMBERT,$valeurs_a_stat_legende);
 
}
 
}
?>