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