Subversion Repositories Applications.gtt

Rev

Rev 16 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
require_once GTT_CHEMIN_CLASSE.'Calendrier.class.php';

require_once GTT_CHEMIN_ACTION.'GttCtrlActionIdentification.class.php';

require_once GTT_CHEMIN_PEAR.'Calendar/Month/Weeks.php';
require_once GTT_CHEMIN_PEAR.'Calendar/Week.php';
require_once GTT_CHEMIN_PEAR.'Calendar/Day.php';

require_once GTT_CHEMIN_METIER.'Projet.class.php';
require_once GTT_CHEMIN_METIER.'TravailProjet.class.php';
require_once GTT_CHEMIN_METIER.'ProjetCategorie.class.php';
require_once GTT_CHEMIN_METIER.'Utilisateur.class.php';
require_once GTT_CHEMIN_METIER.'UtilisateurAProjet.class.php';

class GttCtrlActionGestion extends aControlleurAction {

        public function __construct(Registre $Registre)
    {
        $Registre->ajouterEspace('Gestion', 'gestion');
        $Registre->ajouterSquelette('gestion', 'gestion.tpl.html');
        // TODO : gérer les actions chainées provenant d'un autre ControlleurAction
        $GttCtrlActionIdentification = new GttCtrlActionIdentification($this->getRegistre());
        $GttCtrlActionIdentification->setSuivant('__defaut__');
        $this->setSuivant($GttCtrlActionIdentification);
    }
        
    public function executer()
    {
        $aso_gestion = array();
        $this->getRegistre()->setTitre('Gérer son temps');

        //+-------------------------------------------------------------------------------------------------+
                // GESTION DES CALENDRIERS
                //+-------------------------------------------------------------------------------------------------+
                // Initialisation des variables pour le calendrier
                if (!isset($_GET['annee'])) {
                        $_GET['annee'] = date('Y');
                }
                if (!isset($_GET['mois'])) {
                        $_GET['mois'] = date('m');
                }
                if (!isset($_GET['semaine'])) {
                        $_GET['semaine'] = date('W');
                }
                if (!isset($_GET['jour'])) {
                        $_GET['jour'] = date('d');
                }
                // Instanciation de la classe Calendrier France
                $Calendrier = new Calendrier($_GET['jour'], $_GET['semaine'], $_GET['mois'], $_GET['annee']);
                $tab_jours_feries = $Calendrier->getListeFeries();

                // Create an array of days which are "selected"
                // Used for Week::build() below
                $CalendrierJourCourrant = new Calendar_Week(date('Y'), date('m'), date('d'));
                $aso_gestion['jc']['jour'] = $CalendrierJourCourrant->thisDay();
                $aso_gestion['jc']['semaine'] = $CalendrierJourCourrant->thisWeek('n_in_year');         
                $aso_gestion['jc']['mois'] = $CalendrierJourCourrant->thisMonth();
                $aso_gestion['jc']['mois_nom'] = $Calendrier->getNomMois($CalendrierJourCourrant->thisMonth());
                $aso_gestion['jc']['annee'] = $CalendrierJourCourrant->thisYear();
                $aso_gestion['jc_url'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$aso_gestion['jc']['annee'].'&amp;mois='.$aso_gestion['jc']['mois'].'&amp;semaine='.$aso_gestion['jc']['semaine'].'&amp;jour='.$aso_gestion['jc']['jour'];
                
                $CalendrierJourCourrant->build();
                $CalendrierSemaineCourrante = $CalendrierJourCourrant->thisWeek('object');
                $CalendrierSemaineCourrante->build();
                $tab_jours = $CalendrierSemaineCourrante->fetchAll();
                $aso_gestion['sjc_1']['jour'] = $tab_jours[1]->thisDay();
                $aso_gestion['sjc_1']['mois'] = $Calendrier->getNomMois($tab_jours[1]->thisMonth());
                $aso_gestion['sjc_1']['annee'] = $tab_jours[1]->thisYear();
                $aso_gestion['sjc_7']['jour'] = $tab_jours[7]->thisDay();
                $aso_gestion['sjc_7']['mois'] = $Calendrier->getNomMois($tab_jours[7]->thisMonth());
                $aso_gestion['sjc_7']['annee'] = $tab_jours[7]->thisYear();
                                
                $aso_gestion['selectedDays'] = array ($CalendrierJourCourrant);
                
                // Instruct month to build Week objects
                // Construction de l'objet mois
                $Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
                $Month->build();
                
                while ($Week = $Month->fetch()) {
                        $Week->build($aso_gestion['selectedDays']);
                        //echo '<pre>'.print_r($Month, true).'</pre>';
                        $tab_semaine_jours = $Week->fetchAll();
                        foreach ($tab_semaine_jours as $num => $Day) {
                                $element = array();
                                $element['annee'] = $Day->thisYear();
                                $element['mois'] = $Day->thisMonth();
                                $element['jour'] = $Day->thisDay();
                                $element['jour_nom'] = $Calendrier->getNomJours($num);
                                $element['url'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$Day->thisYear().'&amp;mois='.$Day->thisMonth().'&amp;jour='.$Day->thisDay();
                                // Check to see if day is selected
                                if ($Day->isSelected()) {
                                        $element['class'] = 'jour_courrant';
                                } else if ($Day->isEmpty()) {
                                        $element['class'] = 'jour_vide';
                                } else {
                                        $element['class'] = 'jour';
                                }
                                foreach ($tab_jours_feries as $jour_ferie) {
                                        if ($Day->thisDay(true) ==  $jour_ferie) {
                                                $element['class'] = 'jour_ferie';
                                        }
                                }
                                $aso_gestion['elements'][$Week->thisWeek('n_in_year')][$num] = $element;
                        }
                }
                
                // Construction de l'url pour les mois précédent/suivant
                $PMonth = $Month->prevMonth('object');
                $aso_gestion['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$PMonth->thisYear().'&amp;mois='.$PMonth->thisMonth().'&amp;jour='.$PMonth->thisDay();
                $NMonth = $Month->nextMonth('object');
                $aso_gestion['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$NMonth->thisYear().'&amp;mois='.$NMonth->thisMonth().'&amp;jour='.$NMonth->thisDay();
                $aso_gestion['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());
                $aso_gestion['mois']['annee'] = $Month->thisYear();
                
                // Construction de l'url pour les semaines précédente/suivante
                $Week = new Calendar_Week($_GET['annee'], $_GET['mois'], $_GET['jour']);
                $aso_gestion['s'] = $Week->thisWeek('n_in_year');
                
                $PWeek = $Week->prevWeek('object');
                $aso_gestion['url_semaine_precedente'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$PWeek->thisYear().'&amp;mois='.$PWeek->thisMonth().'&amp;jour='.$PWeek->thisDay();
                
                $url_sc_param_date = '&amp;annee='.$Week->thisYear().'&amp;mois='.$Week->thisMonth().'&amp;jour='.$Week->thisDay();
                $aso_gestion['url_semaine_courante'] = 'index.php?action='.GTT_ACTION_GESTION.$url_sc_param_date;
                
                $NWeek = $Week->nextWeek('object');
                $aso_gestion['url_semaine_suivante'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$NWeek->thisYear().'&amp;mois='.$NWeek->thisMonth().'&amp;jour='.$NWeek->thisDay();
                
                $Week->build();
                $aso_jours = array();
                foreach($Week->fetchAll() as $num => $j) {
                        $aso_gestion['sj_'.$num]['jour'] = $j->thisDay();
                        $aso_gestion['sj_'.$num]['mois'] = $Calendrier->getNomMois($j->thisMonth());
                        $aso_gestion['sj_'.$num]['annee'] = $j->thisYear();
                        $aso_gestion['sj_'.$num]['mysql'] = $aso_gestion['sj_'.$num]['annee'].'-'.sprintf("%02s", $j->thisMonth()).'-'.$aso_gestion['sj_'.$num]['jour'];
                        $aso_jours[$aso_gestion['sj_'.$num]['mysql']] = $num;
                        $aso_tps_w_vide[$num] = '';
                }
                
                //+-------------------------------------------------------------------------------------------------+
                // GESTION DES PROJETS
                //+-------------------------------------------------------------------------------------------------+
        // Récupération des infos sur l'utilisateur
                $aso_gestion['conges_payes'] = $GLOBALS['_GTT_']['Utilisateur']->getCongesPayes();
                $aso_gestion['rtt'] = $GLOBALS['_GTT_']['Utilisateur']->getQuotaHeuresSupp();
                $aso_gestion['tps_w'] = $GLOBALS['_GTT_']['Utilisateur']->getTempsDeTravail();
                
        // Récupération des projets sur lesquels l'utilisateur travaille
                $UtilsateurAProjet = new UtilisateurAProjet();
        $tab_uap = $UtilsateurAProjet->consulter(UtilisateurAProjet::GUAP_UTILISATEUR, $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur());
        $tab_projet_id = array();
        foreach ($tab_uap as $uap) {
                $tab_projet_id[] = $uap->getIdProjet();
        }

        // Récupération du temps de travail pour un utilisateur à une date donnée
        $TravailProjet = new TravailProjet();
                $cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
                $param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_gestion['sj_1']['mysql'], $aso_gestion['sj_7']['mysql']);
                $tab_tp = $TravailProjet->consulter($cmd, $param);
                if ($tab_tp && count($tab_tp) == 1) {
                        $tab_tp = array($tab_tp);
                }

                // Récupération des infos sur les projets de l'utilisateur 
        $Projet = new Projet();
        $tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
                foreach ($tab_p as $Projet) {

                        // Récupération de la catégorie du projet
                        $ProjetCategorie = new ProjetCategorie();
                        $cmd = ProjetCategorie::GPC_ID;
                        $param = $Projet->getCeCategorie();
                        $Categorie = $ProjetCategorie->consulter($cmd, $param);
                        
                        // Nous vérifions le temps de travail pour ce projet pour la semaine courrante
                        $aso_tps_w = $aso_tps_w_vide;
                        if ($tab_tp) {
                                foreach ($tab_tp as $TP) {
                                        if ($TP->getIdProjet() == $Projet->getIdProjet()) {
                                                $aso_tps_w[$aso_jours[$TP->getIdDateTravail()]] = $TP->getDuree();
                                        }
                                }
                        }
                        
                        // Stockage des infos nécessaire pour l'affichage
                        $aso_gestion['preferences'][$Categorie->getLibelle()][] = array(
                                'id' => $Projet->getIdProjet(), 
                                'valeur' => $Projet->getIdProjet(), 
                                'nom' => $Projet->getNomProjet(),
                                'date' => $aso_tps_w);
                                
                }
                // Création de l'url de réponse du formulaire
                $aso_gestion['url_gestion_valider'] = 'index.php?action='.GTT_ACTION_GESTION_VALIDER.$url_sc_param_date;
                
        //echo '<pre>'.print_r($aso_gestion, true).'</pre>';
                $this->getRegistre()->ajouterDonnee('gestion', $aso_gestion);
    }
    
        public function executerValider()
    {
        //echo '<pre>'.print_r($_POST, true).'</pre>';
                
        // Action suivante
        $this->setSuivant('__defaut__');
    }
}
?>