Subversion Repositories Applications.gtt

Rev

Rev 143 | 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
    }
8
 
9
    public function executer()
10
    {
11
   		$aso_stat = array();
103 jpm 12
    	$this->getRegistre()->setTitre('Tableau récapitulatif');
67 jpm 13
 
14
    	//+-------------------------------------------------------------------------------------------------+
15
		// GESTION DES CALENDRIERS
16
		//+-------------------------------------------------------------------------------------------------+
17
		// Initialisation des variables pour le calendrier
18
		if (!isset($_GET['annee'])) {
19
			$_GET['annee'] = date('Y');
20
		}
21
		if (!isset($_GET['mois'])) {
22
			$_GET['mois'] = date('m');
23
		}
24
 
25
		// Construction de l'objet mois
26
		$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
27
		$Month->build();
28
 
29
		// Construction du Calendrier
30
		$Calendrier = new Calendrier();
31
 
103 jpm 32
		// Construction de l'url pour les mois précédent/suivant
126 jpm 33
		$aso_stat['url_mois_courant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_GLOB.'&amp;annee='.$Month->thisYear().'&amp;mois='.$Month->thisMonth();
67 jpm 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
		//+-------------------------------------------------------------------------------------------------+
116 jpm 46
		// Initialisation de variables
47
		$aso_stat['absences'] = false;
48
	    $aso_stat['categories'] = false;
49
 
103 jpm 50
		// Récupération des infos sur les utilisateurs
67 jpm 51
		$DaoUtilsateur = new Utilisateur();
52
    	$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS_AFFICHABLE);
116 jpm 53
 
54
    	if (false == $utilisateurs) {
55
    		$aso_stat['messages'][] = "Aucun utilisateur affichable de disponible...";
56
    	} else {
57
			// Initialisation de variables communes à la gestion des projets et des absences
58
			$aso_stat['total_absences_projets'] = 0;
138 jpm 59
			// Initialisation de variables propre aux absences
60
			$aso_stat['total_absences'] = 0;
61
			// Initialisation de variables propre aux absences
62
			$aso_stat['total_projets'] = 0;
107 jpm 63
 
116 jpm 64
		    // Récupération des motifs d'absence
65
			$AbsenceMotif = new AbsenceMotif();
66
			$cmd = AbsenceMotif::GAM_TOUS;
67
			$tab_am = $AbsenceMotif->consulter($cmd);
68
	    	if (false == $tab_am) {
69
				$aso_stat['messages'][] = "Aucun motif d'absence de renseigné";
67 jpm 70
	    	}
116 jpm 71
 
72
	    	// Pour chaque utilisateur nous récupérons les infos
73
			foreach ($utilisateurs as $Utilisateur) {
74
				// Initialisation du talbeau des infos sur l'utilisateur
75
			 	$aso_gestion = array(	'prenom_nom' => $Utilisateur->getPrenom().' '.$Utilisateur->getNom(),
76
			 							'total_w' => 0,
77
			 							'total_a' => 0,
78
		 								'total' => 0);
79
 
80
				//+-------------------------------------------------------------------------------------------------+
81
				// GESTION DES PROJETS
82
				//+-------------------------------------------------------------------------------------------------+
83
		    	// Récupération du temps de travail pour un utilisateur à une date donnée
84
		    	$TravailProjet = new TravailProjet();
85
				$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
86
				$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
87
				$tab_tp = $TravailProjet->consulter($cmd, $param);
88
				if (false == $tab_tp) {
89
	    			$aso_stat['messages'][] = "Aucune information sur le travail de ${aso_gestion['prenom_nom']}";
90
	    		} else {
91
					// Récupération des identifiants des projets
92
			    	$tab_projet_id = array('');
93
			    	foreach ($tab_tp as $tp) {
94
			    		$tab_projet_id[0] .= $tp->getIdProjet().',';
95
			    	}
96
					$tab_projet_id[0] = rtrim($tab_projet_id[0], ',');
107 jpm 97
 
116 jpm 98
					// Récupération des infos sur les projets de l'utilisateur
99
			    	$Projet = new Projet();
100
			    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, $tab_projet_id);
101
 
102
					foreach ($tab_p as $Projet) {
103
						// Récupération de la catégorie du projet
104
						$ProjetCategorie = new ProjetCategorie();
105
						$cmd = ProjetCategorie::GPC_ID;
106
						$param = $Projet->getCeCategorie();
107
						$Categorie = current($ProjetCategorie->consulter($cmd, $param));
107 jpm 108
 
116 jpm 109
						// Info trans utilisateur sur les catégories
110
						if (!isset($aso_stat['categories'][$Categorie->getIdCategorie()])) {
111
							$aso_stat['categories'][$Categorie->getIdCategorie()] = array(	'projets' => array(),
143 jpm 112
																							'nom' => $Categorie->getLibelle(),
113
																							'abreviation' => $Categorie->getAbreviation(),
116 jpm 114
																							'total' => 0);
115
						}
107 jpm 116
 
116 jpm 117
						foreach ($tab_tp as $TP) {
118
							if ($TP->getIdProjet() == $Projet->getIdProjet()) {
119
								// Info trans utilisateur sur les catégories
138 jpm 120
								if (!isset($aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()])) {
121
									$aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()] =
122
										array(	'nom' => $Projet->getNom(),
123
												'desc' => $Projet->getDescription(),
124
												'total' => 0);
107 jpm 125
								}
138 jpm 126
								$aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()]['total'] += $TP->getDuree();
116 jpm 127
								$aso_stat['categories'][$Categorie->getIdCategorie()]['total'] += $TP->getDuree();
128
								// Stockage des infos nécessaire pour l'affichage d'un utilisateur
129
								if (!isset($aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()])) {
130
									$aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()] = array(
131
										'id' => $Projet->getIdProjet(),
132
										'nom' => $Projet->getNom(),
133
										'duree' => 0);
134
								}
135
								$aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()]['duree'] += $TP->getDuree();
138 jpm 136
								if (!isset($aso_gestion['projets'][$Categorie->getIdCategorie()]['total'])) {
137
									$aso_gestion['projets'][$Categorie->getIdCategorie()]['total'] = 0;
138
								}
139
								$aso_gestion['projets'][$Categorie->getIdCategorie()]['total'] += $TP->getDuree();
116 jpm 140
								$aso_gestion['total_w'] += $TP->getDuree();
67 jpm 141
							}
142
						}
143
					}
116 jpm 144
		    	}
145
				$aso_gestion['total'] = $aso_gestion['total_w'];
146
				$aso_stat['total_projets'] += $aso_gestion['total_w'];
147
 
148
				//+-------------------------------------------------------------------------------------------------+
149
				// GESTION DES ABSENCES
150
				//+-------------------------------------------------------------------------------------------------+
151
				// Récupération des absences pour un utilisateur à une date donnée
152
		    	$Absence = new Absence();
153
				$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
154
				$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
155
				$tab_a = $Absence->consulter($cmd, $param);
138 jpm 156
 
116 jpm 157
				if (false == $tab_a) {
158
					$aso_stat['messages'][] = "Aucune information sur les absences de ${aso_gestion['prenom_nom']}";
159
				} else {
160
					if (false != $tab_am) {
161
						foreach ($tab_am as $AM) {
138 jpm 162
							if (!isset($aso_stat['absences'][$AM->getIdAbsenceMotif()])) {
163
								$aso_stat['absences'][$AM->getIdAbsenceMotif()] =
164
									array( 	'nom' => $AM->getLibelle(),
165
											'total' => 0);
166
							}
116 jpm 167
 
168
							foreach ($tab_a as $A) {
169
								if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
138 jpm 170
									$aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'] += $A->getDuree();
171
									$aso_stat['total_absences'] += $A->getDuree();
172
									if (!isset($aso_gestion['ab'][$AM->getIdAbsenceMotif()])) {
173
										$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
116 jpm 174
									}
138 jpm 175
									$aso_gestion['ab'][$AM->getIdAbsenceMotif()] += $A->getDuree();
116 jpm 176
									$aso_gestion['total_a'] += $A->getDuree();
177
									$aso_gestion['total'] += $A->getDuree();
178
								}
179
							}
180
						}
181
					}
67 jpm 182
				}
116 jpm 183
				$aso_stat['total_absences_projets'] += $aso_gestion['total'];
184
				$aso_stat['utilisateurs'][] = $aso_gestion;
185
	    	}
67 jpm 186
    	}
116 jpm 187
 
138 jpm 188
    	// Post-traitement des nombre pour l'affichage
143 jpm 189
    	$formatage = array('total_projets', 'total_absences','total_absences_projets', 'utilisateurs', 'categories', 'projets', 'absences');
190
    	foreach ($formatage as $cle) {
191
    		$aso_stat[$cle] = Nombre::formaterNbre($aso_stat[$cle], GTT_LANGUE);
192
    	}
138 jpm 193
 
194
		// Sortie
195
		//trigger_error(print_r($aso_stat, true), E_USER_NOTICE);
67 jpm 196
		$this->getRegistre()->ajouterDonnee('stat_tableau_global', $aso_stat);
197
    }
198
}
199
?>