Subversion Repositories Applications.gtt

Rev

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