Subversion Repositories Applications.gtt

Rev

Rev 89 | Rev 101 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
67 jpm 1
<?php
2
class GttCtrlActionStatTableauGlobal extends aControlleurAction {
3
 
4
	public function __construct(Registre $Registre)
5
    {
6
    	$Registre->ajouterEspace('StatTableauGlobal', 'stat_tableau_global');
7
    	$Registre->ajouterSquelette('stat_tableau_global', 'stat_tableau_global.tpl.html');
8
    }
9
 
10
    public function executer()
11
    {
12
   		$aso_stat = array();
13
    	$this->getRegistre()->setTitre('Tableau récapitulatif');
14
 
15
    	//+-------------------------------------------------------------------------------------------------+
16
		// GESTION DES CALENDRIERS
17
		//+-------------------------------------------------------------------------------------------------+
18
		// Initialisation des variables pour le calendrier
19
		if (!isset($_GET['annee'])) {
20
			$_GET['annee'] = date('Y');
21
		}
22
		if (!isset($_GET['mois'])) {
23
			$_GET['mois'] = date('m');
24
		}
25
 
26
		// Construction de l'objet mois
27
		$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
28
		$Month->build();
29
 
30
		// Construction du Calendrier
31
		$Calendrier = new Calendrier();
32
 
33
		// Construction de l'url pour les mois précédent/suivant
34
		$PMonth = $Month->prevMonth('object');
35
		$aso_stat['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_STAT_TAB_GLOB.'&amp;annee='.$PMonth->thisYear().'&amp;mois='.$PMonth->thisMonth();
36
		$NMonth = $Month->nextMonth('object');
37
		$aso_stat['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_GLOB.'&amp;annee='.$NMonth->thisYear().'&amp;mois='.$NMonth->thisMonth();
38
		$aso_stat['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());
39
		$aso_stat['mois']['annee'] = $Month->thisYear();
40
		$mois_courant_j1 = $Month->thisYear().'-'.sprintf("%02s", $Month->thisMonth()).'-'.sprintf("%02s", $Month->thisDay()).' 00:00:00';
41
		$mois_courant_j36 = date('Y-m-d H:i:s', mktime(0, 0, 0, $NMonth->thisMonth(), 0, $NMonth->thisYear()));
95 jpm 42
 
43
    	//+-------------------------------------------------------------------------------------------------+
44
		// GESTION D'INFO GLOBALES
45
		//+-------------------------------------------------------------------------------------------------+
46
		// Récupération des infos sur les utilisateurs
67 jpm 47
		$DaoUtilsateur = new Utilisateur();
48
    	$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS_AFFICHABLE);
95 jpm 49
 
50
		// Récupération des motifs d'absence
51
		$AbsenceMotif = new AbsenceMotif();
52
		$cmd = AbsenceMotif::GAM_TOUS;
53
		$tab_am = $AbsenceMotif->consulter($cmd);
54
    	if (false == $tab_am) {
55
    		$aso_stat['absences'] = false;
56
			$aso_stat['messages'][] = "Aucun motif d'absence de renseigné";
57
 
67 jpm 58
    	}
59
 
95 jpm 60
    	// Pour chaque utilisateur nous récupérons les infos
67 jpm 61
		foreach ($utilisateurs as $Utilisateur) {
62
			$aso_gestion = array();
63
			//+-------------------------------------------------------------------------------------------------+
64
			// GESTION DES PROJETS
65
			//+-------------------------------------------------------------------------------------------------+
66
	    	// Récupération des infos sur l'utilisateur
67
	 		$aso_gestion['prenom_nom'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
68
	 		$aso_gestion['conges_payes'] = $Utilisateur->getCongesPayes();
69
	 		$aso_gestion['rtt'] = $Utilisateur->getQuotaHeuresSupp();
70
	 		$aso_gestion['tps_w'] = $Utilisateur->getTempsDeTravailJour();
71
 
72
	    	// Récupération des projets sur lesquels l'utilisateur travaille
73
			$UtilsateurAProjet = new UtilisateurAProjet();
74
	    	$tab_uap = $UtilsateurAProjet->consulter(UtilisateurAProjet::GUAP_UTILISATEUR, $Utilisateur->getIdUtilisateur());
75
 
95 jpm 76
	    	if (false == $tab_uap) {
77
	    		$aso_stat['projets'] = false;
78
	    		$aso_stat['messages'][] = "Aucune information sur le travail de ${aso_gestion['prenom_nom']}";
79
	    	} else {
67 jpm 80
		    	//echo '<pre>la'.print_r($tab_uap, true).'</pre>';
81
		    	$tab_projet_id = array();
82
		    	foreach ($tab_uap as $uap) {
83
		    		$tab_projet_id[] = $uap->getIdProjet();
84
		    	}
85
 
86
		    	// Récupération du temps de travail pour un utilisateur à une date donnée
87
		    	$TravailProjet = new TravailProjet();
88
				$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
89
				$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
90
				$tab_tp = $TravailProjet->consulter($cmd, $param);
91
 
92
				// Récupération des infos sur les projets de l'utilisateur
93
		    	$aso_gestion['totaux'] = 0;
94
		    	$Projet = new Projet();
95
		    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
96
 
97
				foreach ($tab_p as $Projet) {
98
 
99
					// Récupération de la catégorie du projet
100
					$ProjetCategorie = new ProjetCategorie();
101
					$cmd = ProjetCategorie::GPC_ID;
102
					$param = $Projet->getCeCategorie();
103
					$Categorie = $ProjetCategorie->consulter($cmd, $param);
104
 
105
					// Nous vérifions le temps de travail pour ce projet pour la semaine courrante
106
					$aso_tps_w = 0;
107
					if (!isset($aso_gestion['categorie_totaux'][$Categorie->getLibelle()])) {
108
						$aso_gestion['categorie_totaux'][$Categorie->getLibelle()] = 0;
109
					}
110
					if ($tab_tp) {
111
						foreach ($tab_tp as $TP) {
112
							if ($TP->getIdProjet() == $Projet->getIdProjet()) {
113
								$aso_gestion['categorie_totaux'][$Categorie->getLibelle()] += $TP->getDuree();
114
								$aso_gestion['totaux'] += $TP->getDuree();
115
								// Stockage des infos nécessaire pour l'affichage
116
								if (!isset($aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()])) {
117
									$aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = array(
118
										'id' => $Projet->getIdProjet(),
82 jpm 119
										'nom' => $Projet->getNom(),
67 jpm 120
										'duree' => 0);
121
								}
122
								$aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['duree'] += $TP->getDuree();
123
							}
124
						}
125
					}
89 jpm 126
					$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = $Projet->getNom();
67 jpm 127
				}
128
	    	}
95 jpm 129
 
67 jpm 130
			//+-------------------------------------------------------------------------------------------------+
131
			// GESTION DES ABSENCES
132
			//+-------------------------------------------------------------------------------------------------+
133
			// Récupération des absences pour un utilisateur à une date donnée
134
	    	$Absence = new Absence();
135
			$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
136
			$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
137
			$tab_a = $Absence->consulter($cmd, $param);
138
			$aso_gestion['ab_total'] = '';
95 jpm 139
			if (false == $tab_a) {
140
				$aso_stat['absences'] = false;
141
				$aso_stat['messages'][] = "Aucune information sur les absences de ${aso_gestion['prenom_nom']}";
142
			} else {
143
				if (false != $tab_am) {
144
					foreach ($tab_am as $AM) {
145
						$aso_stat['absences'][$AM->getIdAbsenceMotif()] = $AM->getLibelle();
146
						//$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
67 jpm 147
						foreach ($tab_a as $A) {
148
							if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
149
								$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = $A->getDuree();
150
								$aso_gestion['ab_total'] += $A->getDuree();
151
								$aso_gestion['totaux'] += $A->getDuree();
152
							}
153
						}
154
					}
155
				}
156
			}
157
			$aso_stat['utilisateurs'][] = $aso_gestion;
158
    	}
95 jpm 159
 
67 jpm 160
		//trigger_error('<pre>'.print_r($aso_stat, true).'</pre>', E_USER_NOTICE);
161
		$this->getRegistre()->ajouterDonnee('stat_tableau_global', $aso_stat);
162
    }
163
}
164
?>