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

78 lines
3.4 KiB
PHP

<?php
namespace Module\ACM\Classe\Classe\GestionDate;
use DateTime;
class GestionSemaine {
private string $nom;
private array $jours;
private static array $joursSemaine = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"];
public function __construct(string $nomClasse) {
$this->nom = $nomClasse;
$this->jours = [];
foreach (self::$joursSemaine as $jour) $this->jours[$jour] = [0, 0];
}
public function setLundi(int $matin, int $aprem = 0) {$this->jours["lundi"] = [$matin, $aprem];}
public function setMardi(int $matin, int $aprem = 0) {$this->jours["mardi"] = [$matin, $aprem];}
public function setMercredi(int $matin, int $aprem = 0) {$this->jours["mercredi"] = [$matin, $aprem];}
public function setJeudi(int $matin, int $aprem = 0) {$this->jours["jeudi"] = [$matin, $aprem];}
public function setVendredi(int $matin, int $aprem = 0) {$this->jours["vendredi"] = [$matin, $aprem];}
public function setSamedi(int $matin, int $aprem = 0) {$this->jours["samedi"] = [$matin, $aprem];}
public function setDimanche(int $matin, int $aprem = 0) {$this->jours["dimanche"] = [$matin, $aprem];}
public function setDayByNb(int $day, int $matin, int $aprem = 0 ){
switch ($day) {
case 1: $this->setLundi($matin, $aprem);break;
case 2: $this->setMardi($matin, $aprem);break;
case 3: $this->setMercredi($matin, $aprem);break;
case 4: $this->setJeudi($matin, $aprem);break;
case 5: $this->setVendredi($matin, $aprem);break;
case 6: $this->setSamedi($matin, $aprem);break;
case 7: $this->setDimanche($matin, $aprem);break;
}
}
public function getNom() : string {return $this->nom;}
public function toString() : string {
$texte = "";
$x = 0;
$td = 14;
if (!$this->estVide()){
foreach (GestionSemaine::$joursSemaine as $jour) {
if ($td <= 0){break;}
if ($x <= 0){
if ($this->jours[$jour][0] == 0 && $this->jours[$jour][1] == 0) {
$texte = $texte . "<td></td><td></td>";
$td -= 2;
}else {
if ($this->jours[$jour][0] != 0) {$x = $this->jours[$jour][0];
$texte = $texte . "<td class='$this->nom tailleDiv' colspan='". ($this->jours[$jour][0]) ."'><div>o</div></td>";
$td -= $this->jours[$jour][0];
}
elseif ($this->jours[$jour][1] != 0) {
$texte = $texte . "<td></td>";
$texte = $texte . "<td class='$this->nom tailleDiv' colspan='".($this->jours[$jour][1])."'><div>o</div></td>";
$x = $this->jours[$jour][1]-1;
$td -= ($this->jours[$jour][1]+1);
}
}
}
if ($x-2 >= 0) {
$x = $x - 2;
} elseif ($x-1 == 0) {
$x = $x - 1;
$texte = $texte . "<td></td>";
}
}
}
return $texte;
}
public function estVide() {
$somme = 0;
foreach (self::$joursSemaine as $jour) {$somme = $somme + $this->jours[$jour][0] + $this->jours[$jour][1];}
return $somme == 0;
}
}