Subversion Repositories Applications.gtt

Rev

Rev 101 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
90 jpm 1
<?php
2
class GttCtrlActionStatTableauCharge extends aControlleurAction {
3
 
4
	public function __construct(Registre $Registre)
5
    {
6
    	$Registre->ajouterEspace('StatTableauCharge', 'stat_tableau_charge');
7
    	$Registre->ajouterSquelette('stat_tableau_charge', 'stat_tableau_charge.tpl.html');
8
    }
9
 
10
    public function executer()
11
    {
12
   		$aso_stat = array();
13
    	$this->getRegistre()->setTitre('Plan de charge');
14
 
15
    	//+-------------------------------------------------------------------------------------------------+
16
		// GESTION DES PARAMÊTRE de l'URL
17
		//+-------------------------------------------------------------------------------------------------+
18
		// Initialisation des variables
19
		if (!isset($_GET['annee'])) {
20
			$_GET['annee'] = date('Y');
21
		}
22
		if (!isset($_GET['mois'])) {
23
			$_GET['mois'] = date('m');
24
		}
25
		if (!isset($_GET['uid'])) {// ID de l'utilisateur à afficher
26
			$_GET['uid'] = null;
27
		}
28
		//+-------------------------------------------------------------------------------------------------+
29
		// GESTION DES UTILISATEURS
30
		//+-------------------------------------------------------------------------------------------------+
31
		$DaoUtilsateur = new Utilisateur();
32
    	$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS_AFFICHABLE);
33
    	if (is_object($utilisateurs)) {
34
    		$utilisateurs[0] = $utilisateurs;
35
    	}
36
    	$UtilisateurCourant = null;
37
    	foreach ($utilisateurs as $Utilisateur) {
38
	    	// Récupération des infos sur l'utilisateur
39
	 		$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = false;
40
	 		$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['nom'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
41
	 		if (	(!is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $_GET['uid'])
42
	 			||	(is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur()) ) {
43
	 			$UtilisateurCourant = clone $Utilisateur;
44
	 			$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = true;
45
	 			$aso_stat['utilisateur_courant'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
46
	 			$_GET['uid'] = $Utilisateur->getIdUtilisateur();
47
	 		}
48
    	}
49
    	$aso_stat['etre_admin'] = $GLOBALS['_GTT_']['Utilisateur']->getMarkAdmin();
50
		$Utilisateur = $UtilisateurCourant;
51
 
52
		//+-------------------------------------------------------------------------------------------------+
53
		// GESTION DES CALENDRIERS
54
		//+-------------------------------------------------------------------------------------------------+
55
 
56
		// Construction du Calendrier
57
		$Calendrier = new Calendrier();
58
		$tab_jours_feries = $Calendrier->getListeFeries();
59
 
60
		// Construction de l'objet mois
61
		$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
62
		$Month->build();
63
 
64
		// Récupération des jours du mois
65
		while ($Week = $Month->fetch()) {
66
			$Week->build();
67
			//echo '<pre>'.print_r($Month, true).'</pre>';
68
			$tab_semaine_jours = $Week->fetchAll();
69
			foreach ($tab_semaine_jours as $num => $Day) {
70
				// Nous prenons en compte uniquement les jours du mois courant
71
				if ($Day->thisMonth() == $_GET['mois']) {
72
					$element = array();
73
					$element['jour'] = $Day->thisDay();
74
					$element['jour_nom'] = $Calendrier->getNomJours($num);
75
					$element['class'] = 'jour';
76
					// Nous vérifions le type de jour
77
					// Jour courrant
78
					if ($Day->isSelected()) {
79
						$element['class'] .= ' jour_courrant';
80
					}
81
					// Jour n'appartenant pas au moins courrant
82
					if ($Day->isEmpty()) {
83
						$element['class'] .= ' jour_vide';
84
					}
85
					// Jour férié
86
					foreach ($tab_jours_feries as $jour_ferie) {
87
						if ($Day->thisDay(true) ==  $jour_ferie) {
88
							$element['class'] .= ' jour_ferie';
89
						}
90
					}
91
					// Jour de week-end
92
					if ($element['jour_nom'] == GESTION_DIM_L || $element['jour_nom'] == GESTION_SAM_L) {
93
						$element['class'] .= ' jour_we';
94
					}
95
					$id = date('Y-m-d', mktime(0, 0, 0, $Day->thisMonth(), $Day->thisDay(), $Day->thisYear()));
96
					$aso_stat['elements'][$id] = $element;
97
				}
98
			}
99
		}
100
 
101
		// Construction de l'url pour les mois précédent/suivant/courant et paramêtres pour le formulaire utilisateur
102
		$aso_stat['form_url'] = 'index.php';
103
		$aso_stat['form_param']['action'] = GTT_ACTION_STAT_TAB_CHARGE;
104
		$aso_stat['form_param']['annee'] = $Month->thisYear();
105
		$aso_stat['form_param']['mois'] = $Month->thisMonth();
106
		$PMonth = $Month->prevMonth('object');
107
		$aso_stat['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&amp;annee='.$PMonth->thisYear().'&amp;mois='.$PMonth->thisMonth().'&amp;uid='.$_GET['uid'];
108
		$NMonth = $Month->nextMonth('object');
109
		$aso_stat['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&amp;annee='.$NMonth->thisYear().'&amp;mois='.$NMonth->thisMonth().'&amp;uid='.$_GET['uid'];
110
		$aso_stat['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());
111
		$aso_stat['mois']['annee'] = $Month->thisYear();
112
		$mois_courant_j1 = $Month->thisYear().'-'.sprintf("%02s", $Month->thisMonth()).'-'.sprintf("%02s", $Month->thisDay()).' 00:00:00';
113
		$mois_courant_j36 = date('Y-m-d H:i:s', mktime(0, 0, 0, $NMonth->thisMonth(), 0, $NMonth->thisYear()));
114
 
115
		//+-------------------------------------------------------------------------------------------------+
116
		// GESTION DES PROJETS
117
		//+-------------------------------------------------------------------------------------------------+
118
    	// Récupération du temps de travail pour un utilisateur pour le mois donné
119
    	$TravailProjet = new TravailProjet();
120
		$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
121
		$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
122
		$tab_tp = $TravailProjet->consulter($cmd, $param);
123
		if ($tab_tp && count($tab_tp) == 1) {
124
			$tab_tp = array($tab_tp);
125
		}
126
 
127
		if ($tab_tp != false) {
128
			$tab_projet_id = array();
129
			foreach ($tab_tp as $utp) {
130
    			$tab_projet_id[] = $utp->getIdProjet();
131
    		}
132
			// Nous vérifions qu'il y a des données pour l'utilisateur courant pour le mois donné
133
			// Récupération des infos sur les projets de l'utilisateur
134
	    	$Projet = new Projet();
135
	    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
136
			foreach ($tab_p as $Projet) {
137
				// Récupération de la catégorie du projet
138
				$ProjetCategorie = new ProjetCategorie();
139
				$cmd = ProjetCategorie::GPC_ID;
140
				$param = $Projet->getCeCategorie();
141
				$Categorie = $ProjetCategorie->consulter($cmd, $param);
142
 
143
				// Nous vérifions le temps de travail pour ce projet
144
				$aso_tps_w = 0;
145
				if ($tab_tp) {
146
					foreach ($tab_tp as $TP) {
147
						$j = date('Y-m-d', strtotime($TP->getIdDateTravail()));
148
						if ($TP->getIdProjet() == $Projet->getIdProjet()) {
149
							// Récupération des infos sur les catégories
150
							if (!isset($aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j])) {
151
								$aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j] = 0;
152
							}
153
							$aso_stat['categorie_totaux'][$Categorie->getLibelle()][$j] += $TP->getDuree();
154
							// Récupération des infos sur les projets
155
							if (!isset($aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()])) {
156
								$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = array(
157
									'id' => $Projet->getIdProjet(),
158
									'nom' => $Projet->getNom(),
159
									'duree' => array());
160
							}
161
							$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['duree'][$j] = $TP->getDuree();
162
						}
163
					}
164
				}
165
			}
166
		} else {
167
			$aso_stat['messages'][] = 'Aucune information sur le travail en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee'];
168
		}
169
 
170
		//+-------------------------------------------------------------------------------------------------+
171
		// GESTION DES ABSENCES
172
		//+-------------------------------------------------------------------------------------------------+
173
		// Récupération des motifs d'absence
174
		$AbsenceMotif = new AbsenceMotif();
175
		$cmd = AbsenceMotif::GAM_TOUS;
176
		$tab_am = $AbsenceMotif->consulter($cmd);
177
		if ($tab_am && count($tab_am) == 1) {
178
			$tab_am = array($tab_am);
179
		}
180
 
181
		// Récupération des absences pour un utilisateur à une date donnée
182
    	$Absence = new Absence();
183
		$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
184
		$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
185
		$tab_a = $Absence->consulter($cmd, $param);
186
		if ($tab_a && count($tab_a) == 1) {
187
			$tab_a = array($tab_a);
188
		}
189
		if ($tab_a != false) {
190
			$aso_stat['ab_total'] = '';
191
			if ($tab_am) {
192
				foreach ($tab_am as $AM) {
193
					$aso_stat['absences'][$AM->getIdAbsenceMotif()] = $AM->getLibelle();
194
					//$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
195
					if ($tab_a) {
196
						foreach ($tab_a as $A) {
197
							if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
198
								$j = date('Y-m-d', strtotime($A->getIdDateAbsence()));
199
								// Récupération des infos sur les absences
200
								$aso_stat['ab'][$AM->getIdAbsenceMotif()][$j] = $A->getDuree();
201
								// Récupération du total des absences
202
								if (!isset($aso_stat['ab_total'][$j])) {
203
									$aso_stat['ab_total'][$j] = 0;
204
								}
205
								$aso_stat['ab_total'][$j] += $A->getDuree();
206
							}
207
						}
208
					}
209
				}
210
			}
211
		} else {
212
			$aso_stat['messages'][] = 'Aucune absence de mentionnée en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee'];
213
		}
214
 
215
 
216
		trigger_error('<pre>'.print_r($aso_stat, true).'</pre>', E_USER_NOTICE);
217
		$this->getRegistre()->ajouterDonnee('stat_tableau_charge', $aso_stat);
218
    }
219
}
220
?>