ACM/classe/Classe/gestionUtilisateurSemaine.php
2025-03-26 10:57:42 +01:00

84 lines
4.2 KiB
PHP

<?php
namespace Module\ACM\Classe\Classe;
use DateTime;
use Module\ACM\Classe\Classe\GestionDate\GestionPeriode;
use Module\ACM\Classe\Classe\GestionDate\GestionSemaine;
use Module\ACM\Classe\GestionBD\gestionUtilisateur;
class gestionUtilisateurSemaine {
private $user;
private DateTime $dateLundi;
public function __construct($user, DateTime $dateLundi) {
$this->user = $user;
$this->dateLundi = $dateLundi;
}
public function getUser() : string {return $this->user;}
public function getDateLundi() : DateTime {return $this->dateLundi;}
public function getTravailSemaine() {}
public function getTeletravailSemaine() {}
public function getCongeSemaine() {
return $this->getSemaine("LEAVE_PAID_FR", "couleurCongee");
}
public function getRecupeSemaine() {
return $this->getSemaine("LEAVE_RECUP", "couleurRecupe");
}
private function getSemaine($code, $couleur) {
$dateDimanche = new DateTime($this->dateLundi->format('Y-m-d')." 08:00:00");
$dateDimanche->modify('+6 day');
$dateDimanche->modify('+7 hours');
$listeMalade = gestionUtilisateur::getListeCongeeParNomEtCode($this->user["login"], $code);
$periode = [];
foreach ($listeMalade as $malade) {
if ($malade && ($this->dateLundi->format("Ymd") <= (new DateTime($malade["date_fin"]))->format("Ymd") && (new DateTime($malade["date_debut"]))->format("Ymd") <= $dateDimanche->format("Ymd"))) {
if ( (new DateTime($malade["date_fin"]))->format("Ymd") >= $dateDimanche->format("Ymd")) {
$malade["date_fin"] = $dateDimanche->format("Y-m-d H:i:s");
}
if ((new DateTime($malade["date_debut"]))->format("Ymd") <= $this->dateLundi->format("Ymd")) {
$malade["date_debut"] = $this->dateLundi->format("Y-m-d H:i:s");
}
$periode[(new DateTime($malade["date_debut"]))->format("Y-m-d H:i:s")] = new gestionPeriode(new DateTime($malade["date_debut"]), new DateTime($malade["date_fin"]));
}
}
$retour = new GestionSemaine($couleur);
foreach ($periode as $key=>$malade) {
if ((new DateTime($key))->format("a") == "am")
$retour->setDayByNb((new DateTime($key))->format("N"), $malade->getNbDemiJournnees());
else
$retour->setDayByNb((new DateTime($key))->format("N"), 0, $malade->getNbDemiJournnees());
}
return $retour->toString();
}
public function getMaladeSemaine() {
$couleur = "couleurMalade";
$code1 = "LEAVE_SICK_WORK";
$code2 = "LEAVE_SICK";
$dateDimanche = new DateTime($this->dateLundi->format('Y-m-d')." 08:00:00");
$dateDimanche->modify('+6 day');
$dateDimanche->modify('+7 hours');
$listeMalade = gestionUtilisateur::getListeCongeeParNomEtDeuxCode($this->user["login"], $code1, $code2);
$periode = [];
foreach ($listeMalade as $malade) {
if ($malade && ($this->dateLundi->format("Ymd") <= (new DateTime($malade["date_fin"]))->format("Ymd") && (new DateTime($malade["date_debut"]))->format("Ymd") <= $dateDimanche->format("Ymd"))) {
if ( (new DateTime($malade["date_fin"]))->format("Ymd") >= $dateDimanche->format("Ymd")) {
$malade["date_fin"] = $dateDimanche->format("Y-m-d H:i:s");
}
if ((new DateTime($malade["date_debut"]))->format("Ymd") <= $this->dateLundi->format("Ymd")) {
$malade["date_debut"] = $this->dateLundi->format("Y-m-d H:i:s");
}
$periode[(new DateTime($malade["date_debut"]))->format("Y-m-d H:i:s")] = new gestionPeriode(new DateTime($malade["date_debut"]), new DateTime($malade["date_fin"]));
}
}
$retour = new GestionSemaine($couleur);
foreach ($periode as $key=>$malade) {
if ((new DateTime($key))->format("a") == "am")
$retour->setDayByNb((new DateTime($key))->format("N"), $malade->getNbDemiJournnees());
else
$retour->setDayByNb((new DateTime($key))->format("N"), 0, $malade->getNbDemiJournnees());
}
return $retour->toString();
}
}