src/Entity/AgendaTimeConvertion.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AgendaTimeConvertionRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. #[ORM\Entity(repositoryClassAgendaTimeConvertionRepository::class)]
  9. #[ORM\Table(name"agenda_time_convertion"uniqueConstraints: [
  10.     new ORM\UniqueConstraint(name"uniq_school_year"columns: ["school_id""year_id"])
  11. ])]
  12. class AgendaTimeConvertion
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column]
  19.     private ?float $time null;
  20.     #[ORM\ManyToOne(inversedBy'agendaTimeConvertions')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?School $school null;
  23.     #[ORM\ManyToOne(inversedBy'agendaTimeConvertions')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?SchoolYear $year null;
  26.     #[ORM\ManyToOne(inversedBy'agendaTimeConvertions')]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private ?User $author null;
  29.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  30.     private ?\DateTimeInterface $startSchoolTime null;
  31.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  32.     private ?\DateTimeInterface $arriveSchoolTime null;
  33.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  34.     private ?\DateTimeInterface $firstBreakStartAt null;
  35.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  36.     private ?\DateTimeInterface $firstBreakEndAt null;
  37.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  38.     private ?\DateTimeInterface $secondBreakStartAt null;
  39.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  40.     private ?\DateTimeInterface $secondBreakEndAt null;
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getTime(): ?float
  46.     {
  47.         return $this->time;
  48.     }
  49.     public function setTime(float $time): static
  50.     {
  51.         $this->time $time;
  52.         return $this;
  53.     }
  54.     public function getSchool(): ?School
  55.     {
  56.         return $this->school;
  57.     }
  58.     public function setSchool(?School $school): static
  59.     {
  60.         $this->school $school;
  61.         return $this;
  62.     }
  63.     public function getYear(): ?SchoolYear
  64.     {
  65.         return $this->year;
  66.     }
  67.     public function setYear(?SchoolYear $year): static
  68.     {
  69.         $this->year $year;
  70.         return $this;
  71.     }
  72.     public function getAuthor(): ?User
  73.     {
  74.         return $this->author;
  75.     }
  76.     public function setAuthor(?User $author): static
  77.     {
  78.         $this->author $author;
  79.         return $this;
  80.     }
  81.     public function getStartSchoolTime(): ?\DateTimeInterface
  82.     {
  83.         return $this->startSchoolTime;
  84.     }
  85.     public function setStartSchoolTime(?\DateTimeInterface $startSchoolTime): static
  86.     {
  87.         $this->startSchoolTime $startSchoolTime;
  88.         return $this;
  89.     }
  90.     public function getArriveSchoolTime(): ?\DateTimeInterface
  91.     {
  92.         return $this->arriveSchoolTime;
  93.     }
  94.     public function setArriveSchoolTime(?\DateTimeInterface $arriveSchoolTime): static
  95.     {
  96.         $this->arriveSchoolTime $arriveSchoolTime;
  97.         return $this;
  98.     }
  99.     public function getFirstBreakStartAt(): ?\DateTimeInterface
  100.     {
  101.         return $this->firstBreakStartAt;
  102.     }
  103.     public function setFirstBreakStartAt(?\DateTimeInterface $firstBreakStartAt): static
  104.     {
  105.         $this->firstBreakStartAt $firstBreakStartAt;
  106.         return $this;
  107.     }
  108.     public function getFirstBreakEndAt(): ?\DateTimeInterface
  109.     {
  110.         return $this->firstBreakEndAt;
  111.     }
  112.     public function setFirstBreakEndAt(?\DateTimeInterface $firstBreakEndAt): static
  113.     {
  114.         $this->firstBreakEndAt $firstBreakEndAt;
  115.         return $this;
  116.     }
  117.     public function getSecondBreakStartAt(): ?\DateTimeInterface
  118.     {
  119.         return $this->secondBreakStartAt;
  120.     }
  121.     public function setSecondBreakStartAt(?\DateTimeInterface $secondBreakStartAt): static
  122.     {
  123.         $this->secondBreakStartAt $secondBreakStartAt;
  124.         return $this;
  125.     }
  126.     public function getSecondBreakEndAt(): ?\DateTimeInterface
  127.     {
  128.         return $this->secondBreakEndAt;
  129.     }
  130.     public function setSecondBreakEndAt(?\DateTimeInterface $secondBreakEndAt): static
  131.     {
  132.         $this->secondBreakEndAt $secondBreakEndAt;
  133.         return $this;
  134.     }
  135.     #[Assert\Callback(groups: ['full_config'])]
  136.     public function validate(ExecutionContextInterface $context$payload): void
  137.     {
  138.         // Règle 1
  139.         if ($this->firstBreakStartAt >= $this->firstBreakEndAt) {
  140.             $context->buildViolation("L'heure de début doit être avant la fin.")
  141.                 ->atPath('firstBreakStartAt')
  142.                 ->addViolation();
  143.         }
  144.         // Règle 2 : Début pause 2 > Fin pause 1
  145.         if ($this->secondBreakStartAt <= $this->firstBreakEndAt) {
  146.             $context->buildViolation("La deuxième pause doit commencer après la première.")
  147.                 ->atPath('secondBreakStartAt')
  148.                 ->addViolation();
  149.         }
  150.         
  151.         // Règle 3 : Fin pause 2 > Début pause 2
  152.         if ($this->secondBreakEndAt <= $this->secondBreakStartAt) {
  153.             $context->buildViolation("L'heure de fin doit être après le début.")
  154.                 ->atPath('secondBreakEndAt')
  155.                 ->addViolation();
  156.         }
  157.     }
  158. }