Subversion Repositories Applications.gtt

Rev

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

Rev Author Line No. Line
11 jpm 1
<?php
2
require_once GTT_CHEMIN_CLASSE.'Calendrier.class.php';
3
 
4
require_once GTT_CHEMIN_ACTION.'GttCtrlActionIdentification.class.php';
5
 
6
require_once GTT_CHEMIN_PEAR.'Calendar/Month/Weeks.php';
7
require_once GTT_CHEMIN_PEAR.'Calendar/Week.php';
8
require_once GTT_CHEMIN_PEAR.'Calendar/Day.php';
9
 
10
require_once GTT_CHEMIN_METIER.'Projet.class.php';
11
require_once GTT_CHEMIN_METIER.'TravailProjet.class.php';
12
require_once GTT_CHEMIN_METIER.'ProjetCategorie.class.php';
13
require_once GTT_CHEMIN_METIER.'Utilisateur.class.php';
14
require_once GTT_CHEMIN_METIER.'UtilisateurAProjet.class.php';
15
 
16
class GttCtrlActionGestion extends aControlleurAction {
17
 
18
	public function __construct(Registre $Registre)
19
    {
20
    	$Registre->ajouterEspace('Gestion', 'gestion');
21
    	$Registre->ajouterSquelette('gestion', 'gestion.tpl.html');
22
    	// TODO : gérer les actions chainées provenant d'un autre ControlleurAction
23
    	$GttCtrlActionIdentification = new GttCtrlActionIdentification($this->getRegistre());
24
    	$GttCtrlActionIdentification->setSuivant('__defaut__');
25
    	$this->setSuivant($GttCtrlActionIdentification);
26
    }
27
 
28
    public function executer()
29
    {
30
    	$aso_gestion = array();
31
    	$this->getRegistre()->setTitre('Gérer son temps');
32
 
33
    	//+-------------------------------------------------------------------------------------------------+
34
		// GESTION DES CALENDRIERS
35
		//+-------------------------------------------------------------------------------------------------+
36
		// Initialisation des variables pour le calendrier
37
		if (!isset($_GET['annee'])) {
38
			$_GET['annee'] = date('Y');
39
		}
40
		if (!isset($_GET['mois'])) {
41
			$_GET['mois'] = date('m');
42
		}
43
		if (!isset($_GET['semaine'])) {
44
			$_GET['semaine'] = date('W');
45
		}
46
		if (!isset($_GET['jour'])) {
47
			$_GET['jour'] = date('d');
48
		}
49
		// Instanciation de la classe Calendrier France
50
		$Calendrier = new Calendrier($_GET['jour'], $_GET['semaine'], $_GET['mois'], $_GET['annee']);
51
		$tab_jours_feries = $Calendrier->getListeFeries();
52
 
53
		// Create an array of days which are "selected"
54
		// Used for Week::build() below
55
		$CalendrierJourCourrant = new Calendar_Week(date('Y'), date('m'), date('d'));
56
		$aso_gestion['jc']['jour'] = $CalendrierJourCourrant->thisDay();
57
		$aso_gestion['jc']['semaine'] = $CalendrierJourCourrant->thisWeek('n_in_year');
58
		$aso_gestion['jc']['mois'] = $CalendrierJourCourrant->thisMonth();
59
		$aso_gestion['jc']['mois_nom'] = $Calendrier->getNomMois($CalendrierJourCourrant->thisMonth());
60
		$aso_gestion['jc']['annee'] = $CalendrierJourCourrant->thisYear();
61
		$aso_gestion['jc_url'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$aso_gestion['jc']['annee'].'&amp;mois='.$aso_gestion['jc']['mois'].'&amp;semaine='.$aso_gestion['jc']['semaine'].'&amp;jour='.$aso_gestion['jc']['jour'];
62
 
63
		$CalendrierJourCourrant->build();
64
		$CalendrierSemaineCourrante = $CalendrierJourCourrant->thisWeek('object');
65
		$CalendrierSemaineCourrante->build();
66
		$tab_jours = $CalendrierSemaineCourrante->fetchAll();
67
		$aso_gestion['sjc_1']['jour'] = $tab_jours[1]->thisDay();
68
		$aso_gestion['sjc_1']['mois'] = $Calendrier->getNomMois($tab_jours[1]->thisMonth());
69
		$aso_gestion['sjc_1']['annee'] = $tab_jours[1]->thisYear();
70
		$aso_gestion['sjc_7']['jour'] = $tab_jours[7]->thisDay();
71
		$aso_gestion['sjc_7']['mois'] = $Calendrier->getNomMois($tab_jours[7]->thisMonth());
72
		$aso_gestion['sjc_7']['annee'] = $tab_jours[7]->thisYear();
73
 
74
		$aso_gestion['selectedDays'] = array ($CalendrierJourCourrant);
75
 
76
		// Instruct month to build Week objects
77
		// Construction de l'objet mois
78
		$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);
79
		$Month->build();
80
 
81
		while ($Week = $Month->fetch()) {
82
			$Week->build($aso_gestion['selectedDays']);
83
			//echo '<pre>'.print_r($Month, true).'</pre>';
84
			$tab_semaine_jours = $Week->fetchAll();
85
			foreach ($tab_semaine_jours as $num => $Day) {
86
				$element = array();
87
				$element['annee'] = $Day->thisYear();
88
				$element['mois'] = $Day->thisMonth();
89
				$element['jour'] = $Day->thisDay();
90
				$element['jour_nom'] = $Calendrier->getNomJours($num);
91
				$element['url'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$Day->thisYear().'&amp;mois='.$Day->thisMonth().'&amp;jour='.$Day->thisDay();
92
				// Check to see if day is selected
93
				if ($Day->isSelected()) {
94
					$element['class'] = 'jour_courrant';
95
				} else if ($Day->isEmpty()) {
96
					$element['class'] = 'jour_vide';
97
				} else {
98
					$element['class'] = 'jour';
99
				}
100
				foreach ($tab_jours_feries as $jour_ferie) {
101
					if ($Day->thisDay(true) ==  $jour_ferie) {
102
						$element['class'] = 'jour_ferie';
103
					}
104
				}
105
				$aso_gestion['elements'][$Week->thisWeek('n_in_year')][$num] = $element;
106
			}
107
		}
108
 
109
		// Construction de l'url pour les mois précédent/suivant
110
		$PMonth = $Month->prevMonth('object');
111
		$aso_gestion['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$PMonth->thisYear().'&amp;mois='.$PMonth->thisMonth().'&amp;jour='.$PMonth->thisDay();
112
		$NMonth = $Month->nextMonth('object');
113
		$aso_gestion['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$NMonth->thisYear().'&amp;mois='.$NMonth->thisMonth().'&amp;jour='.$NMonth->thisDay();
114
		$aso_gestion['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());
115
		$aso_gestion['mois']['annee'] = $Month->thisYear();
116
 
117
		// Construction de l'url pour les semaines précédente/suivante
118
		$Week = new Calendar_Week($_GET['annee'], $_GET['mois'], $_GET['jour']);
119
		$aso_gestion['s'] = $Week->thisWeek('n_in_year');
120
 
121
		$PWeek = $Week->prevWeek('object');
122
		$aso_gestion['url_semaine_precedente'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$PWeek->thisYear().'&amp;mois='.$PWeek->thisMonth().'&amp;jour='.$PWeek->thisDay();
123
 
124
		$url_sc_param_date = '&amp;annee='.$Week->thisYear().'&amp;mois='.$Week->thisMonth().'&amp;jour='.$Week->thisDay();
125
		$aso_gestion['url_semaine_courante'] = 'index.php?action='.GTT_ACTION_GESTION.$url_sc_param_date;
126
 
127
		$NWeek = $Week->nextWeek('object');
128
		$aso_gestion['url_semaine_suivante'] = 'index.php?action='.GTT_ACTION_GESTION.'&amp;annee='.$NWeek->thisYear().'&amp;mois='.$NWeek->thisMonth().'&amp;jour='.$NWeek->thisDay();
129
 
130
		$Week->build();
131
		$aso_jours = array();
132
		foreach($Week->fetchAll() as $num => $j) {
133
			$aso_gestion['sj_'.$num]['jour'] = $j->thisDay();
134
			$aso_gestion['sj_'.$num]['mois'] = $Calendrier->getNomMois($j->thisMonth());
135
			$aso_gestion['sj_'.$num]['annee'] = $j->thisYear();
136
			$aso_gestion['sj_'.$num]['mysql'] = $aso_gestion['sj_'.$num]['annee'].'-'.sprintf("%02s", $j->thisMonth()).'-'.$aso_gestion['sj_'.$num]['jour'];
137
			$aso_jours[$aso_gestion['sj_'.$num]['mysql']] = $num;
138
			$aso_tps_w_vide[$num] = '';
139
		}
140
 
141
		//+-------------------------------------------------------------------------------------------------+
142
		// GESTION DES PROJETS
143
		//+-------------------------------------------------------------------------------------------------+
144
    	// Récupération des infos sur l'utilisateur
145
 		$aso_gestion['conges_payes'] = $GLOBALS['_GTT_']['Utilisateur']->getCongesPayes();
146
 		$aso_gestion['rtt'] = $GLOBALS['_GTT_']['Utilisateur']->getQuotaHeuresSupp();
147
 		$aso_gestion['tps_w'] = $GLOBALS['_GTT_']['Utilisateur']->getTempsDeTravail();
148
 
149
    	// Récupération des projets sur lesquels l'utilisateur travaille
150
		$UtilsateurAProjet = new UtilisateurAProjet();
151
    	$tab_uap = $UtilsateurAProjet->consulter(UtilisateurAProjet::GUAP_UTILISATEUR, $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur());
152
    	$tab_projet_id = array();
153
    	foreach ($tab_uap as $uap) {
154
    		$tab_projet_id[] = $uap->getIdProjet();
155
    	}
156
 
157
    	// Récupération du temps de travail pour un utilisateur à une date donnée
158
    	$TravailProjet = new TravailProjet();
159
		$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;
160
		$param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_gestion['sj_1']['mysql'], $aso_gestion['sj_7']['mysql']);
161
		$tab_tp = $TravailProjet->consulter($cmd, $param);
162
		if ($tab_tp && count($tab_tp) == 1) {
163
			$tab_tp = array($tab_tp);
164
		}
165
 
166
		// Récupération des infos sur les projets de l'utilisateur
167
    	$Projet = new Projet();
168
    	$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));
169
		foreach ($tab_p as $Projet) {
170
 
171
			// Récupération de la catégorie du projet
172
			$ProjetCategorie = new ProjetCategorie();
173
			$cmd = ProjetCategorie::GPC_ID;
174
			$param = $Projet->getCeCategorie();
175
			$Categorie = $ProjetCategorie->consulter($cmd, $param);
176
 
177
			// Nous vérifions le temps de travail pour ce projet pour la semaine courrante
178
			$aso_tps_w = $aso_tps_w_vide;
179
			if ($tab_tp) {
180
				foreach ($tab_tp as $TP) {
181
					if ($TP->getIdProjet() == $Projet->getIdProjet()) {
182
						$aso_tps_w[$aso_jours[$TP->getIdDateTravail()]] = $TP->getDuree();
183
					}
184
				}
185
			}
186
 
187
			// Stockage des infos nécessaire pour l'affichage
188
			$aso_gestion['preferences'][$Categorie->getLibelle()][] = array(
189
				'id' => $Projet->getIdProjet(),
190
				'valeur' => $Projet->getIdProjet(),
191
				'nom' => $Projet->getNomProjet(),
192
				'date' => $aso_tps_w);
193
 
194
		}
195
		// Création de l'url de réponse du formulaire
196
		$aso_gestion['url_gestion_valider'] = 'index.php?action='.GTT_ACTION_GESTION_VALIDER.$url_sc_param_date;
197
 
198
    	//echo '<pre>'.print_r($aso_gestion, true).'</pre>';
199
		$this->getRegistre()->ajouterDonnee('gestion', $aso_gestion);
200
    }
201
 
202
	public function executerValider()
203
    {
204
    	//echo '<pre>'.print_r($_POST, true).'</pre>';
205
 
206
    	// Action suivante
207
    	$this->setSuivant('__defaut__');
208
    }
209
}
210
?>