<?php
namespace App\Entity;
use App\Repository\AgendaTimeConvertionRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: AgendaTimeConvertionRepository::class)]
#[ORM\Table(name: "agenda_time_convertion", uniqueConstraints: [
new ORM\UniqueConstraint(name: "uniq_school_year", columns: ["school_id", "year_id"])
])]
class AgendaTimeConvertion
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?float $time = null;
#[ORM\ManyToOne(inversedBy: 'agendaTimeConvertions')]
#[ORM\JoinColumn(nullable: false)]
private ?School $school = null;
#[ORM\ManyToOne(inversedBy: 'agendaTimeConvertions')]
#[ORM\JoinColumn(nullable: false)]
private ?SchoolYear $year = null;
#[ORM\ManyToOne(inversedBy: 'agendaTimeConvertions')]
#[ORM\JoinColumn(nullable: false)]
private ?User $author = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startSchoolTime = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $arriveSchoolTime = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $firstBreakStartAt = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $firstBreakEndAt = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $secondBreakStartAt = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $secondBreakEndAt = null;
public function getId(): ?int
{
return $this->id;
}
public function getTime(): ?float
{
return $this->time;
}
public function setTime(float $time): static
{
$this->time = $time;
return $this;
}
public function getSchool(): ?School
{
return $this->school;
}
public function setSchool(?School $school): static
{
$this->school = $school;
return $this;
}
public function getYear(): ?SchoolYear
{
return $this->year;
}
public function setYear(?SchoolYear $year): static
{
$this->year = $year;
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function getStartSchoolTime(): ?\DateTimeInterface
{
return $this->startSchoolTime;
}
public function setStartSchoolTime(?\DateTimeInterface $startSchoolTime): static
{
$this->startSchoolTime = $startSchoolTime;
return $this;
}
public function getArriveSchoolTime(): ?\DateTimeInterface
{
return $this->arriveSchoolTime;
}
public function setArriveSchoolTime(?\DateTimeInterface $arriveSchoolTime): static
{
$this->arriveSchoolTime = $arriveSchoolTime;
return $this;
}
public function getFirstBreakStartAt(): ?\DateTimeInterface
{
return $this->firstBreakStartAt;
}
public function setFirstBreakStartAt(?\DateTimeInterface $firstBreakStartAt): static
{
$this->firstBreakStartAt = $firstBreakStartAt;
return $this;
}
public function getFirstBreakEndAt(): ?\DateTimeInterface
{
return $this->firstBreakEndAt;
}
public function setFirstBreakEndAt(?\DateTimeInterface $firstBreakEndAt): static
{
$this->firstBreakEndAt = $firstBreakEndAt;
return $this;
}
public function getSecondBreakStartAt(): ?\DateTimeInterface
{
return $this->secondBreakStartAt;
}
public function setSecondBreakStartAt(?\DateTimeInterface $secondBreakStartAt): static
{
$this->secondBreakStartAt = $secondBreakStartAt;
return $this;
}
public function getSecondBreakEndAt(): ?\DateTimeInterface
{
return $this->secondBreakEndAt;
}
public function setSecondBreakEndAt(?\DateTimeInterface $secondBreakEndAt): static
{
$this->secondBreakEndAt = $secondBreakEndAt;
return $this;
}
#[Assert\Callback(groups: ['full_config'])]
public function validate(ExecutionContextInterface $context, $payload): void
{
// Règle 1
if ($this->firstBreakStartAt >= $this->firstBreakEndAt) {
$context->buildViolation("L'heure de début doit être avant la fin.")
->atPath('firstBreakStartAt')
->addViolation();
}
// Règle 2 : Début pause 2 > Fin pause 1
if ($this->secondBreakStartAt <= $this->firstBreakEndAt) {
$context->buildViolation("La deuxième pause doit commencer après la première.")
->atPath('secondBreakStartAt')
->addViolation();
}
// Règle 3 : Fin pause 2 > Début pause 2
if ($this->secondBreakEndAt <= $this->secondBreakStartAt) {
$context->buildViolation("L'heure de fin doit être après le début.")
->atPath('secondBreakEndAt')
->addViolation();
}
}
}