src/Entity/AgendaElement.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Timestampable;
  4. use App\Repository\AgendaElementRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation\Groups;
  10. #[ORM\HasLifecycleCallbacks]
  11. #[ORM\Entity(repositoryClassAgendaElementRepository::class)]
  12. class AgendaElement
  13. {
  14.     use Timestampable;
  15.     
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     #[Groups(['getAgenda'])]
  20.     private ?int $id null;
  21.     #[ORM\Column(typeTypes::TIME_MUTABLE)]
  22.     #[Groups(['getAgenda'])]
  23.     private ?\DateTimeInterface $startAt null;
  24.     #[ORM\Column(typeTypes::TIME_MUTABLE)]
  25.     #[Groups(['getAgenda'])]
  26.     private ?\DateTimeInterface $endAt null;
  27.     #[ORM\Column(length255)]
  28.     #[Groups(['getAgenda'])]
  29.     private ?int $duration null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     #[Groups(['getAgenda'])]
  32.     private ?int $other null;
  33.     #[ORM\ManyToOne(inversedBy'agendaElements')]
  34.     #[Groups(['getAgenda'])]
  35.     private ?Subject $subject null;
  36.     #[ORM\ManyToOne(inversedBy'elements')]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     private ?AgendaDay $agendaDay null;
  39.     #[ORM\Column(options: ["default" => false])]
  40.     private ?bool $isPermanence false;
  41.     #[ORM\ManyToOne(inversedBy'agendaElements')]
  42.     #[ORM\JoinColumn(nullablefalse)]
  43.     private ?User $author null;
  44.     #[ORM\Column]
  45.     private ?bool $active null;
  46.     #[ORM\Column(nullabletrue)]
  47.     private ?\DateTimeImmutable $descativatedAt null;
  48.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityProfTime::class)]
  49.     private Collection $profTimes;
  50.     #[ORM\ManyToOne(inversedBy'agendaElements')]
  51.     #[ORM\JoinColumn(nullablefalse)]
  52.     private ?School $school null;
  53.     #[ORM\ManyToOne(inversedBy'agendaElements')]
  54.     #[ORM\JoinColumn(nullablefalse)]
  55.     private ?SchoolYear $year null;
  56.     #[ORM\ManyToOne(inversedBy'agendaElements')]
  57.     #[ORM\JoinColumn(nullablefalse)]
  58.     private ?TheClass $classe null;
  59.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityTeacherActivity::class, cascade: ['remove'], orphanRemovaltrue)]
  60.     private Collection $teacherActivities;
  61.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityTeacherAbsence::class, cascade: ['remove'], orphanRemovaltrue)]
  62.     private Collection $teacherAbsences;
  63.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityAttendanceActivity::class,cascade: ['remove'], orphanRemovaltrue)]
  64.     private Collection $attendanceActivities;
  65.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityAttendanceMissed::class, cascade: ['remove'], orphanRemovaltrue)]
  66.     private Collection $attendanceMisseds;
  67.     #[ORM\Column(nullabletrue)]
  68.     private ?int $position null;
  69.     #[ORM\ManyToMany(targetEntityTimeRange::class, inversedBy'agendaElements')]
  70.     private Collection $timeRanges;
  71.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityAbsence::class, cascade: ['remove'], orphanRemovaltrue)]
  72.     private Collection $absences;
  73.     /**
  74.      * Cahier de texte : entrées saisies par le prof pour ce créneau précis
  75.      * (avec ou sans chapitre du programme national concerné).
  76.      */
  77.     #[ORM\OneToMany(mappedBy'agendaElement'targetEntityLessonLog::class, cascade: ['remove'], orphanRemovaltrue)]
  78.     private Collection $lessonLogs;
  79.     public function __construct()
  80.     {
  81.         $this->profTimes = new ArrayCollection();
  82.         $this->teacherActivities = new ArrayCollection();
  83.         $this->teacherAbsences = new ArrayCollection();
  84.         $this->attendanceActivities = new ArrayCollection();
  85.         $this->attendanceMisseds = new ArrayCollection();
  86.         $this->timeRanges = new ArrayCollection();
  87.         $this->absences = new ArrayCollection();
  88.         $this->lessonLogs = new ArrayCollection();
  89.     }
  90.     public function __toString()
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getStartAt(): ?\DateTimeInterface
  99.     {
  100.         return $this->startAt;
  101.     }
  102.     public function setStartAt(\DateTimeInterface $startAt): static
  103.     {
  104.         $this->startAt $startAt;
  105.         return $this;
  106.     }
  107.     public function getEndAt(): ?\DateTimeInterface
  108.     {
  109.         return $this->endAt;
  110.     }
  111.     public function setEndAt(\DateTimeInterface $endAt): static
  112.     {
  113.         $this->endAt $endAt;
  114.         return $this;
  115.     }
  116.     public function getDuration(): ?int
  117.     {
  118.         return $this->duration;
  119.     }
  120.     public function setDuration(int $duration): static
  121.     {
  122.         $this->duration $duration;
  123.         return $this;
  124.     }
  125.     public function getOther(): ?int
  126.     {
  127.         return $this->other;
  128.     }
  129.     public function setOther(?int $other): static
  130.     {
  131.         $this->other $other;
  132.         return $this;
  133.     }
  134.     public function getSubject(): ?Subject
  135.     {
  136.         return $this->subject;
  137.     }
  138.     public function setSubject(?Subject $subject): static
  139.     {
  140.         $this->subject $subject;
  141.         return $this;
  142.     }
  143.     public function getAgendaDay(): ?AgendaDay
  144.     {
  145.         return $this->agendaDay;
  146.     }
  147.     public function setAgendaDay(?AgendaDay $agendaDay): static
  148.     {
  149.         $this->agendaDay $agendaDay;
  150.         return $this;
  151.     }
  152.     public function getAuthor(): ?User
  153.     {
  154.         return $this->author;
  155.     }
  156.     public function setAuthor(?User $author): static
  157.     {
  158.         $this->author $author;
  159.         return $this;
  160.     }
  161.     public function isActive(): ?bool
  162.     {
  163.         return $this->active;
  164.     }
  165.     public function setActive(bool $active): static
  166.     {
  167.         $this->active $active;
  168.         return $this;
  169.     }
  170.     public function isPermanence(): ?bool { return $this->isPermanence; }
  171.     public function setIsPermanence(bool $isPermanence): static { 
  172.         $this->isPermanence $isPermanence
  173.         return $this
  174.     }
  175.     #[ORM\PrePersist]
  176.     #[ORM\PreUpdate]
  177.     public function syncMetadata(): void
  178.     {
  179.         if (!$this->timeRanges->isEmpty()) {
  180.             $ranges $this->timeRanges->toArray();
  181.             usort($ranges, fn($a$b) => $a->getPosition() <=> $b->getPosition());
  182.             
  183.             // 1. Heures de début et fin
  184.             $this->startAt $ranges[0]->getStartAt();
  185.             $this->endAt end($ranges)->getEndAt();
  186.             
  187.             // 2. Duration = Nombre de tranches (slots)
  188.             $this->duration count($ranges);
  189.         }
  190.     }
  191.     #[ORM\PrePersist]
  192.     #[ORM\PreUpdate]
  193.     public function updateMetadata(): void
  194.     {
  195.         if (!$this->timeRanges->isEmpty()) {
  196.             $ranges $this->timeRanges->toArray();
  197.             // Tri par position pour avoir le vrai début et la vraie fin
  198.             usort($ranges, fn($a$b) => $a->getPosition() <=> $b->getPosition());
  199.             
  200.             $this->startAt $ranges[0]->getStartAt();
  201.             $this->endAt end($ranges)->getEndAt();
  202.             
  203.             // La durée est maintenant le nombre de tranches sélectionnées
  204.             $this->duration count($ranges);
  205.         }
  206.     }
  207.     public function areRangesConsecutive(): bool
  208.     {
  209.         if ($this->timeRanges->isEmpty()) return false;
  210.         $positions array_map(fn($r) => $r->getPosition(), $this->timeRanges->toArray());
  211.         sort($positions);
  212.         for ($i 0$i count($positions) - 1$i++) {
  213.             if ($positions[$i 1] !== $positions[$i] + 1) return false;
  214.         }
  215.         return true;
  216.     }
  217.     public function getDescativatedAt(): ?\DateTimeImmutable
  218.     {
  219.         return $this->descativatedAt;
  220.     }
  221.     public function setDescativatedAt(?\DateTimeImmutable $descativatedAt): static
  222.     {
  223.         $this->descativatedAt $descativatedAt;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection<int, ProfTime>
  228.      */
  229.     public function getProfTimes(): Collection
  230.     {
  231.         return $this->profTimes;
  232.     }
  233.     public function addProfTime(ProfTime $profTime): static
  234.     {
  235.         if (!$this->profTimes->contains($profTime)) {
  236.             $this->profTimes->add($profTime);
  237.             $profTime->setAgendaElement($this);
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeProfTime(ProfTime $profTime): static
  242.     {
  243.         if ($this->profTimes->removeElement($profTime)) {
  244.             // set the owning side to null (unless already changed)
  245.             if ($profTime->getAgendaElement() === $this) {
  246.                 $profTime->setAgendaElement(null);
  247.             }
  248.         }
  249.         return $this;
  250.     }
  251.     public function getSchool(): ?School
  252.     {
  253.         return $this->school;
  254.     }
  255.     public function setSchool(?School $school): static
  256.     {
  257.         $this->school $school;
  258.         return $this;
  259.     }
  260.     public function getYear(): ?SchoolYear
  261.     {
  262.         return $this->year;
  263.     }
  264.     public function setYear(?SchoolYear $year): static
  265.     {
  266.         $this->year $year;
  267.         return $this;
  268.     }
  269.     public function getClasse(): ?TheClass
  270.     {
  271.         return $this->classe;
  272.     }
  273.     public function setClasse(?TheClass $classe): static
  274.     {
  275.         $this->classe $classe;
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, TeacherActivity>
  280.      */
  281.     public function getTeacherActivities(): Collection
  282.     {
  283.         return $this->teacherActivities;
  284.     }
  285.     public function addTeacherActivity(TeacherActivity $teacherActivity): static
  286.     {
  287.         if (!$this->teacherActivities->contains($teacherActivity)) {
  288.             $this->teacherActivities->add($teacherActivity);
  289.             $teacherActivity->setAgendaElement($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeTeacherActivity(TeacherActivity $teacherActivity): static
  294.     {
  295.         if ($this->teacherActivities->removeElement($teacherActivity)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($teacherActivity->getAgendaElement() === $this) {
  298.                 $teacherActivity->setAgendaElement(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, TeacherAbsence>
  305.      */
  306.     public function getTeacherAbsences(): Collection
  307.     {
  308.         return $this->teacherAbsences;
  309.     }
  310.     public function addTeacherAbsence(TeacherAbsence $teacherAbsence): static
  311.     {
  312.         if (!$this->teacherAbsences->contains($teacherAbsence)) {
  313.             $this->teacherAbsences->add($teacherAbsence);
  314.             $teacherAbsence->setAgendaElement($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeTeacherAbsence(TeacherAbsence $teacherAbsence): static
  319.     {
  320.         if ($this->teacherAbsences->removeElement($teacherAbsence)) {
  321.             // set the owning side to null (unless already changed)
  322.             if ($teacherAbsence->getAgendaElement() === $this) {
  323.                 $teacherAbsence->setAgendaElement(null);
  324.             }
  325.         }
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection<int, AttendanceActivity>
  330.      */
  331.     public function getAttendanceActivities(): Collection
  332.     {
  333.         return $this->attendanceActivities;
  334.     }
  335.     public function addAttendanceActivity(AttendanceActivity $attendanceActivity): static
  336.     {
  337.         if (!$this->attendanceActivities->contains($attendanceActivity)) {
  338.             $this->attendanceActivities->add($attendanceActivity);
  339.             $attendanceActivity->setAgendaElement($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeAttendanceActivity(AttendanceActivity $attendanceActivity): static
  344.     {
  345.         if ($this->attendanceActivities->removeElement($attendanceActivity)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($attendanceActivity->getAgendaElement() === $this) {
  348.                 $attendanceActivity->setAgendaElement(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, AttendanceMissed>
  355.      */
  356.     public function getAttendanceMisseds(): Collection
  357.     {
  358.         return $this->attendanceMisseds;
  359.     }
  360.     public function addAttendanceMissed(AttendanceMissed $attendanceMissed): static
  361.     {
  362.         if (!$this->attendanceMisseds->contains($attendanceMissed)) {
  363.             $this->attendanceMisseds->add($attendanceMissed);
  364.             $attendanceMissed->setAgendaElement($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeAttendanceMissed(AttendanceMissed $attendanceMissed): static
  369.     {
  370.         if ($this->attendanceMisseds->removeElement($attendanceMissed)) {
  371.             // set the owning side to null (unless already changed)
  372.             if ($attendanceMissed->getAgendaElement() === $this) {
  373.                 $attendanceMissed->setAgendaElement(null);
  374.             }
  375.         }
  376.         return $this;
  377.     }
  378.     public function getPosition(): ?int
  379.     {
  380.         return $this->position;
  381.     }
  382.     public function setPosition(?int $position): static
  383.     {
  384.         $this->position $position;
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection<int, TimeRange>
  389.      */
  390.     public function getTimeRanges(): Collection
  391.     {
  392.         return $this->timeRanges;
  393.     }
  394.     public function addTimeRange(TimeRange $timeRange): static
  395.     {
  396.         if (!$this->timeRanges->contains($timeRange)) {
  397.             $this->timeRanges->add($timeRange);
  398.         }
  399.         return $this;
  400.     }
  401.     public function removeTimeRange(TimeRange $timeRange): static
  402.     {
  403.         $this->timeRanges->removeElement($timeRange);
  404.         return $this;
  405.     }
  406.     /**
  407.      * @return Collection<int, Absence>
  408.      */
  409.     public function getAbsences(): Collection
  410.     {
  411.         return $this->absences;
  412.     }
  413.     public function addAbsence(Absence $absence): static
  414.     {
  415.         if (!$this->absences->contains($absence)) {
  416.             $this->absences->add($absence);
  417.             $absence->setAgendaElement($this);
  418.         }
  419.         return $this;
  420.     }
  421.     public function removeAbsence(Absence $absence): static
  422.     {
  423.         if ($this->absences->removeElement($absence)) {
  424.             // set the owning side to null (unless already changed)
  425.             if ($absence->getAgendaElement() === $this) {
  426.                 $absence->setAgendaElement(null);
  427.             }
  428.         }
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection<int, LessonLog>
  433.      */
  434.     public function getLessonLogs(): Collection
  435.     {
  436.         return $this->lessonLogs;
  437.     }
  438.     public function addLessonLog(LessonLog $lessonLog): static
  439.     {
  440.         if (!$this->lessonLogs->contains($lessonLog)) {
  441.             $this->lessonLogs->add($lessonLog);
  442.             $lessonLog->setAgendaElement($this);
  443.         }
  444.         return $this;
  445.     }
  446.     public function removeLessonLog(LessonLog $lessonLog): static
  447.     {
  448.         if ($this->lessonLogs->removeElement($lessonLog)) {
  449.             if ($lessonLog->getAgendaElement() === $this) {
  450.                 $lessonLog->setAgendaElement(null);
  451.             }
  452.         }
  453.         return $this;
  454.     }
  455. }