New file |
0,0 → 1,254 |
<?php |
class GttCtrlActionStatTableauCharge extends aControlleurAction { |
|
public function __construct(Registre $Registre) |
{ |
$Registre->ajouterEspace('StatTableauCharge', 'stat_tableau_charge'); |
} |
|
public function executer() |
{ |
//+-------------------------------------------------------------------------------------------------+ |
// GESTION D'INFO GLOBALES |
//+-------------------------------------------------------------------------------------------------+ |
$aso_stat = array('total_w' => 0,'total_a' => 0, 'total' => 0); |
$this->getRegistre()->setTitre('Plan de charge'); |
|
//+-------------------------------------------------------------------------------------------------+ |
// GESTION DES PARAMÊTRE de l'URL |
//+-------------------------------------------------------------------------------------------------+ |
// Initialisation des variables |
if (!isset($_GET['annee'])) { |
$_GET['annee'] = date('Y'); |
} |
if (!isset($_GET['mois'])) { |
$_GET['mois'] = date('m'); |
} |
if (!isset($_GET['uid'])) {// ID de l'utilisateur à afficher |
$_GET['uid'] = null; |
} |
//+-------------------------------------------------------------------------------------------------+ |
// GESTION DES UTILISATEURS |
//+-------------------------------------------------------------------------------------------------+ |
$DaoUtilsateur = new Utilisateur(); |
$utilisateurs = $DaoUtilsateur->consulter(Utilisateur::GU_TOUS); |
$UtilisateurCourant = null; |
foreach ($utilisateurs as $Utilisateur) { |
// Récupération des infos sur l'utilisateur |
$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = false; |
$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['nom'] = $Utilisateur->getNom().' '.$Utilisateur->getPrenom(); |
if ( (!is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $_GET['uid']) |
|| (is_null($_GET['uid']) && $Utilisateur->getIdUtilisateur() == $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur()) ) { |
$UtilisateurCourant = clone $Utilisateur; |
$aso_stat['utilisateurs'][$Utilisateur->getIdUtilisateur()]['courant'] = true; |
$aso_stat['utilisateur_courant'] = $Utilisateur->getNom().' '.$Utilisateur->getPrenom(); |
$_GET['uid'] = $Utilisateur->getIdUtilisateur(); |
} |
} |
$aso_stat['etre_admin'] = $GLOBALS['_GTT_']['Utilisateur']->getMarkAdmin(); |
$Utilisateur = $UtilisateurCourant; |
|
//+-------------------------------------------------------------------------------------------------+ |
// GESTION DES CALENDRIERS |
//+-------------------------------------------------------------------------------------------------+ |
|
// Construction du Calendrier |
$Calendrier = new Calendrier(); |
$tab_jours_feries = $Calendrier->getListeFeries(); |
|
// Construction de l'objet mois |
$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']); |
$Month->build(); |
|
// Récupération des jours du mois |
while ($Week = $Month->fetch()) { |
$Week->build(); |
//echo '<pre>'.print_r($Month, true).'</pre>'; |
$tab_semaine_jours = $Week->fetchAll(); |
foreach ($tab_semaine_jours as $num => $Day) { |
// Nous prenons en compte uniquement les jours du mois courant |
if ($Day->thisMonth() == $_GET['mois']) { |
$element = array('travail' => 0, 'absence' => 0, 'w_et_a' => 0); |
$element['jour'] = $Day->thisDay(); |
$element['jour_nom'] = $Calendrier->getNomJours($num); |
$element['class'] = 'jour'; |
// Nous vérifions le type de jour |
// Jour courrant |
if ($Day->isSelected()) { |
$element['class'] .= ' jour_courrant'; |
} |
// Jour n'appartenant pas au moins courrant |
if ($Day->isEmpty()) { |
$element['class'] .= ' jour_vide'; |
} |
// Jour férié |
foreach ($tab_jours_feries as $jour_ferie) { |
if ($Day->thisDay(true) == $jour_ferie) { |
$element['class'] .= ' jour_ferie'; |
} |
} |
// Jour de week-end |
if ($element['jour_nom'] == GESTION_DIM_L || $element['jour_nom'] == GESTION_SAM_L) { |
$element['class'] .= ' jour_we'; |
} |
$id = date('Y-m-d', mktime(0, 0, 0, $Day->thisMonth(), $Day->thisDay(), $Day->thisYear())); |
$aso_stat['elements'][$id] = $element; |
} |
} |
} |
|
// Construction de l'url pour les mois précédent/suivant/courant et paramêtres pour le formulaire utilisateur |
$aso_stat['form_url'] = 'index.php'; |
$aso_stat['form_param']['action'] = GTT_ACTION_STAT_TAB_CHARGE; |
$aso_stat['form_param']['annee'] = $Month->thisYear(); |
$aso_stat['form_param']['mois'] = $Month->thisMonth(); |
$aso_stat['url_mois_courant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&annee='.$Month->thisYear().'&mois='.$Month->thisMonth().'&uid='.$_GET['uid']; |
$PMonth = $Month->prevMonth('object'); |
$aso_stat['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&annee='.$PMonth->thisYear().'&mois='.$PMonth->thisMonth().'&uid='.$_GET['uid']; |
$NMonth = $Month->nextMonth('object'); |
$aso_stat['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_STAT_TAB_CHARGE.'&annee='.$NMonth->thisYear().'&mois='.$NMonth->thisMonth().'&uid='.$_GET['uid']; |
$aso_stat['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth()); |
$aso_stat['mois']['annee'] = $Month->thisYear(); |
$mois_courant_j1 = $Month->thisYear().'-'.sprintf("%02s", $Month->thisMonth()).'-'.sprintf("%02s", $Month->thisDay()).' 00:00:00'; |
$mois_courant_j36 = date('Y-m-d H:i:s', mktime(0, 0, 0, $NMonth->thisMonth(), 0, $NMonth->thisYear())); |
|
//+-------------------------------------------------------------------------------------------------+ |
// GESTION DES PROJETS |
//+-------------------------------------------------------------------------------------------------+ |
// Récupération du temps de travail pour un utilisateur pour le mois donné |
$TravailProjet = new TravailProjet(); |
$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN; |
$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36); |
$tab_tp = $TravailProjet->consulter($cmd, $param); |
|
if ($tab_tp != false) { |
$tab_projet_id = array(); |
foreach ($tab_tp as $utp) { |
$tab_projet_id[] = $utp->getIdProjet(); |
} |
// Nous vérifions qu'il y a des données pour l'utilisateur courant pour le mois donné |
// Récupération des infos sur les projets de l'utilisateur |
$Projet = new Projet(); |
$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id))); |
foreach ($tab_p as $Projet) { |
// Récupération de la catégorie du projet |
$ProjetCategorie = new ProjetCategorie(); |
$cmd = ProjetCategorie::GPC_ID; |
$param = $Projet->getCeCategorie(); |
$Categorie = current($ProjetCategorie->consulter($cmd, $param)); |
|
// Nous vérifions le temps de travail pour ce projet |
$aso_tps_w = 0; |
if ($tab_tp) { |
foreach ($tab_tp as $TP) { |
$j = date('Y-m-d', strtotime($TP->getIdDateTravail())); |
if ($TP->getIdProjet() == $Projet->getIdProjet()) { |
// Récupération des infos sur les catégories |
if (!isset($aso_stat['categories'][$Categorie->getLibelle()])) { |
$aso_stat['categories'][$Categorie->getLibelle()] = array( |
'total' => 0, |
'abreviation' => $Categorie->getAbreviation()); |
} |
if (!isset($aso_stat['categories'][$Categorie->getLibelle()][$j])) { |
$aso_stat['categories'][$Categorie->getLibelle()][$j] = 0; |
} |
$aso_stat['categories'][$Categorie->getLibelle()][$j] += $TP->getDuree(); |
$aso_stat['categories'][$Categorie->getLibelle()]['total'] += $TP->getDuree(); |
|
// Récupération du total de travail |
$aso_stat['total_w'] += $TP->getDuree(); |
|
// Récupération du total de temps global (travail+absence) |
$aso_stat['total'] += $TP->getDuree(); |
|
// Récupération d'info sur le temps travaillé |
$aso_stat['elements'][$j]['travail'] += $TP->getDuree(); |
|
// Récupération du total travail + absence par jour |
$aso_stat['elements'][$j]['w_et_a'] += $TP->getDuree(); |
|
// Récupération des infos sur les projets |
if (!isset($aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()])) { |
$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()] = array( |
'id' => $Projet->getIdProjet(), |
'nom' => $Projet->getNom(), |
'desc' => $Projet->getDescription(), |
'duree' => array(), |
'total' => 0); |
} |
$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['duree'][$j] = $TP->getDuree(); |
$aso_stat['projets'][$Categorie->getLibelle()][$Projet->getIdProjet()]['total'] += $TP->getDuree(); |
} |
} |
} |
} |
} else { |
$aso_stat['messages'][] = 'Aucune information sur le travail en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee']; |
} |
|
//+-------------------------------------------------------------------------------------------------+ |
// GESTION DES ABSENCES |
//+-------------------------------------------------------------------------------------------------+ |
// Récupération des motifs d'absence |
$AbsenceMotif = new AbsenceMotif(); |
$cmd = AbsenceMotif::GAM_TOUS; |
$tab_am = $AbsenceMotif->consulter($cmd); |
|
// Récupération des absences pour un utilisateur à une date donnée |
$Absence = new Absence(); |
$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN; |
$param = array($Utilisateur->getIdUtilisateur(), $mois_courant_j1, $mois_courant_j36); |
$tab_a = $Absence->consulter($cmd, $param); |
if ($tab_a != false) { |
$aso_stat['ab_total'] = ''; |
if ($tab_am) { |
foreach ($tab_am as $AM) { |
// Initialisation du tableau des types d'absences |
$aso_stat['absences'][$AM->getIdAbsenceMotif()]['nom'] = $AM->getLibelle(); |
if (!isset($aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'])) { |
$aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'] = 0; |
} |
|
if ($tab_a) { |
foreach ($tab_a as $A) { |
if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif() && $A->getDuree() != 0) { |
$j = date('Y-m-d', strtotime($A->getIdDateAbsence())); |
|
// Récupération des infos sur les absences |
$aso_stat['ab'][$AM->getIdAbsenceMotif()][$j] = $A->getDuree(); |
|
// Récupération du total des absences par jour |
$aso_stat['elements'][$j]['absence'] += $A->getDuree(); |
|
// Récupération du total travail + absence par jour |
$aso_stat['elements'][$j]['w_et_a'] += $A->getDuree(); |
|
// Récupération du total pour chaque type d'absence |
$aso_stat['absences'][$AM->getIdAbsenceMotif()]['total'] += $A->getDuree(); |
|
// Récupération du total des absences |
$aso_stat['total_a'] += $A->getDuree(); |
|
// Récupération du total de temps global (travail+absence) |
$aso_stat['total'] += $A->getDuree(); |
} |
} |
} |
} |
} |
} else { |
$aso_stat['messages'][] = 'Aucune absence de mentionnée en '.$aso_stat['mois']['mois'].' '.$aso_stat['mois']['annee']; |
} |
|
// Post-traitement des nombre pour l'affichage |
$formatage = array('ab', 'elements','absences', 'total_a', 'total_w', 'total', 'categories', 'projets'); |
foreach ($formatage as $cle) { |
$aso_stat[$cle] = Nombre::formaterNbre($aso_stat[$cle], GTT_LANGUE); |
} |
|
// Sortie |
//trigger_error(print_r($aso_stat, true), E_USER_NOTICE); |
$this->getRegistre()->ajouterDonnee('stat_tableau_charge', $aso_stat); |
} |
} |
?> |