Subversion Repositories Applications.gtt

Rev

Rev 67 | Rev 89 | 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()));
42
 
43
		$DaoUtilsateur = new Utilisateur();
44
    	$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS_AFFICHABLE);
45
    	if (is_object($utilisateurs)) {
46
    		$utilisateurs[0] = $utilisateurs;
47
    	}
48
 
49
		foreach ($utilisateurs as $Utilisateur) {
50
			$aso_gestion = array();
51
			//+-------------------------------------------------------------------------------------------------+
52
			// GESTION DES PROJETS
53
			//+-------------------------------------------------------------------------------------------------+
54
	    	// Récupération des infos sur l'utilisateur
55
	 		$aso_gestion['prenom_nom'] = $Utilisateur->getPrenom().' '.$Utilisateur->getNom();
56
	 		$aso_gestion['conges_payes'] = $Utilisateur->getCongesPayes();
57
	 		$aso_gestion['rtt'] = $Utilisateur->getQuotaHeuresSupp();
58
	 		$aso_gestion['tps_w'] = $Utilisateur->getTempsDeTravailJour();
59
 
60
	    	// Récupération des projets sur lesquels l'utilisateur travaille
61
			$UtilsateurAProjet = new UtilisateurAProjet();
62
	    	$tab_uap = $UtilsateurAProjet->consulter(UtilisateurAProjet::GUAP_UTILISATEUR, $Utilisateur->getIdUtilisateur());
63
 
64
	    	if (is_array($tab_uap) && count($tab_uap) > 0) {
65
		    	//echo '<pre>la'.print_r($tab_uap, true).'</pre>';
66
		    	$tab_projet_id = array();
67
		    	foreach ($tab_uap as $uap) {
68
		    		$tab_projet_id[] = $uap->getIdProjet();
69
		    	}
70
 
71
		    	// Récupération du temps de travail pour un utilisateur à une date donnée
72
		    	$TravailProjet = new TravailProjet();
73
				$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
74
				$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
75
				$tab_tp = $TravailProjet->consulter($cmd, $param);
76
				if ($tab_tp && count($tab_tp) == 1) {
77
					$tab_tp = array($tab_tp);
78
				}
79
 
80
				// Récupération des infos sur les projets de l'utilisateur
81
		    	$aso_gestion['totaux'] = 0;
82
		    	$Projet = new Projet();
83
		    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
84
 
85
				foreach ($tab_p as $Projet) {
86
 
87
					// Récupération de la catégorie du projet
88
					$ProjetCategorie = new ProjetCategorie();
89
					$cmd = ProjetCategorie::GPC_ID;
90
					$param = $Projet->getCeCategorie();
91
					$Categorie = $ProjetCategorie->consulter($cmd, $param);
92
 
93
					// Nous vérifions le temps de travail pour ce projet pour la semaine courrante
94
					$aso_tps_w = 0;
95
					if (!isset($aso_gestion['categorie_totaux'][$Categorie->getLibelle()])) {
96
						$aso_gestion['categorie_totaux'][$Categorie->getLibelle()] = 0;
97
					}
98
					if ($tab_tp) {
99
						foreach ($tab_tp as $TP) {
100
							if ($TP->getIdProjet() == $Projet->getIdProjet()) {
101
								$aso_gestion['categorie_totaux'][$Categorie->getLibelle()] += $TP->getDuree();
102
								$aso_gestion['totaux'] += $TP->getDuree();
103
								// Stockage des infos nécessaire pour l'affichage
104
								if (!isset($aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()])) {
105
									$aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = array(
106
										'id' => $Projet->getIdProjet(),
82 jpm 107
										'nom' => $Projet->getNom(),
67 jpm 108
										'duree' => 0);
109
								}
110
								$aso_gestion['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['duree'] += $TP->getDuree();
111
							}
112
						}
113
					}
114
					$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = $Projet->getNomProjet();
115
				}
116
	    	}
117
			//+-------------------------------------------------------------------------------------------------+
118
			// GESTION DES ABSENCES
119
			//+-------------------------------------------------------------------------------------------------+
120
			// Récupération des motifs d'absence
121
			$AbsenceMotif = new AbsenceMotif();
122
			$cmd = AbsenceMotif::GAM_TOUS;
123
			$tab_am = $AbsenceMotif->consulter($cmd);
124
			if ($tab_am && count($tab_am) == 1) {
125
				$tab_am = array($tab_am);
126
			}
127
 
128
			// Récupération des absences pour un utilisateur à une date donnée
129
	    	$Absence = new Absence();
130
			$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;
131
			$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36);
132
			$tab_a = $Absence->consulter($cmd, $param);
133
			if ($tab_a && count($tab_a) == 1) {
134
				$tab_a = array($tab_a);
135
			}
136
 
137
			$aso_gestion['ab_total'] = '';
138
			if ($tab_am) {
139
				foreach ($tab_am as $AM) {
140
					$aso_stat['absences'][$AM->getIdAbsenceMotif()] = $AM->getLibelle();
141
					//$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = 0;
142
					if ($tab_a) {
143
						foreach ($tab_a as $A) {
144
							if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) {
145
								$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = $A->getDuree();
146
								$aso_gestion['ab_total'] += $A->getDuree();
147
								$aso_gestion['totaux'] += $A->getDuree();
148
							}
149
						}
150
					}
151
				}
152
			}
153
			$aso_stat['utilisateurs'][] = $aso_gestion;
154
    	}
155
 
156
		//trigger_error('<pre>'.print_r($aso_stat, true).'</pre>', E_USER_NOTICE);
157
		$this->getRegistre()->ajouterDonnee('stat_tableau_global', $aso_stat);
158
    }
159
}
160
?>