Subversion Repositories Applications.annuaire

Rev

Rev 120 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?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 AppControleur {

        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');

                $image = $this->statistiques->combinerGraphiques($graph);

                // Envoi d'une image png
                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);

        }

}
?>