Subversion Repositories Applications.gtt

Rev

Rev 103 | Rev 110 | 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
					}
107 jpm 110
					$aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()]['nom'] = $Projet->getNom();
111
 
112
					foreach ($tab_tp as $TP) {
113
						if ($TP->getIdProjet() == $Projet->getIdProjet()) {
114
							// Info trans utilisateur sur les catégories
115
							if (!isset($aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()]['total'])) {
116
								$aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()]['total'] = 0;
117
							} else {
118
								$aso_stat['categories'][$Categorie->getIdCategorie()]['projets'][$Projet->getIdProjet()]['total'] += $TP->getDuree();
67 jpm 119
							}
107 jpm 120
							$aso_stat['categories'][$Categorie->getIdCategorie()]['total'] += $TP->getDuree();
121
							// Stockage des infos nécessaire pour l'affichage d'un utilisateur
122
							if (!isset($aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()])) {
123
								$aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()] = array(
124
									'id' => $Projet->getIdProjet(),
125
									'nom' => $Projet->getNom(),
126
									'duree' => 0);
127
							}
128
							$aso_gestion['projets'][$Categorie->getIdCategorie()][$Projet->getIdProjet()]['duree'] += $TP->getDuree();
129
							$aso_gestion['total_w'] += $TP->getDuree();
67 jpm 130
						}
131
					}
132
				}
133
	    	}
107 jpm 134
			$aso_gestion['total'] = $aso_gestion['total_w'];
135
			$aso_stat['total_projets'] += $aso_gestion['total_w'];
136
 
67 jpm 137
			//+-------------------------------------------------------------------------------------------------+
138
			// GESTION DES ABSENCES
139
			//+-------------------------------------------------------------------------------------------------+
107 jpm 140
			// Initialisation de variables propre aux absences
141
			$aso_stat['total_absences'] = 0;
142
 
103 jpm 143
			// Récupération des absences pour un utilisateur à une date donnée
67 jpm 144
	    	$Absence = new Absence();
145
			$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
146
			$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
147
			$tab_a = $Absence->consulter($cmd, $param);
95 jpm 148
			if (false == $tab_a) {
149
				$aso_stat['absences'] = false;
150
				$aso_stat['messages'][] = "Aucune information sur les absences de ${aso_gestion['prenom_nom']}";
151
			} else {
152
				if (false != $tab_am) {
153
					foreach ($tab_am as $AM) {
107 jpm 154
						$aso_stat['absences'][$AM->getIdAbsenceMotif()]['nom'] = $AM->getLibelle();
155
 
95 jpm 156
						//$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
67 jpm 157
						foreach ($tab_a as $A) {
158
							if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
107 jpm 159
								if (!isset($aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'])) {
160
									$aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'] = 0;
161
								} else {
162
									$aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'] += $A->getDuree();
163
								}
164
								$aso_stat['total_absences'] += $A->getDuree();
67 jpm 165
								$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = $A->getDuree();
107 jpm 166
								$aso_gestion['total_a'] += $A->getDuree();
167
								$aso_gestion['total'] += $A->getDuree();
67 jpm 168
							}
169
						}
170
					}
171
				}
172
			}
107 jpm 173
			$aso_stat['total_absences_projets'] += $aso_gestion['total'];
67 jpm 174
			$aso_stat['utilisateurs'][] = $aso_gestion;
175
    	}
95 jpm 176
 
67 jpm 177
		//trigger_error('<pre>'.print_r($aso_stat, true).'</pre>', E_USER_NOTICE);
178
		$this->getRegistre()->ajouterDonnee('stat_tableau_global', $aso_stat);
179
    }
180
}
181
?>