src/Entity/Chapter.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ChapterRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Traits\Timestampable;
  8. /**
  9.  * Chapitre du programme national (créé par le superadmin).
  10.  *
  11.  * Rattaché à un SubjectReference (= matière + ClassOption).
  12.  * `position` définit l'ordre d'apparition dans le programme.
  13.  * `deadlineQuarter` indique la séquence avant la fin de laquelle le
  14.  * chapitre doit être terminé (ex : "avant la fin de la Séquence 2").
  15.  *
  16.  * La date réelle de la deadline se calcule via deadlineQuarter->getEndDate()
  17.  * si ce champ existe sur Quarter, sinon on affiche juste le nom de la séquence.
  18.  */
  19. #[ORM\HasLifecycleCallbacks]
  20. #[ORM\Entity(repositoryClassChapterRepository::class)]
  21. class Chapter
  22. {
  23.     use Timestampable;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     private ?int $id null;
  28.     #[ORM\Column(length255)]
  29.     private ?string $title null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $titleEn null;
  32.     #[ORM\Column(type'text'nullabletrue)]
  33.     private ?string $description null;
  34.     /**
  35.      * Ordre du chapitre dans le programme (1, 2, 3...).
  36.      */
  37.     #[ORM\Column]
  38.     private ?int $position null;
  39.     #[ORM\ManyToOne(inversedBy'chapters')]
  40.     #[ORM\JoinColumn(nullablefalse)]
  41.     private ?SubjectReference $subjectReference null;
  42.     /**
  43.      * Séquence avant la fin de laquelle ce chapitre doit être terminé.
  44.      * Nullable : un chapitre peut ne pas avoir de deadline imposée.
  45.      */
  46.     #[ORM\ManyToOne]
  47.     private ?Quarter $deadlineQuarter null;
  48.     /**
  49.      * Date calendaire optionnelle, en complément ou alternative à deadlineQuarter.
  50.      * Permet une deadline fixe (ex: 15/11/2025) si le superadmin préfère.
  51.      */
  52.     #[ORM\Column(type'date'nullabletrue)]
  53.     private ?\DateTimeInterface $deadlineDate null;
  54.     #[ORM\OneToMany(mappedBy'chapter'targetEntityChapterProgress::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  55.     private Collection $progresses;
  56.     #[ORM\ManyToOne]
  57.     private ?User $author null;
  58.     public function __construct()
  59.     {
  60.         $this->progresses = new ArrayCollection();
  61.     }
  62.     public function __toString(): string
  63.     {
  64.         return $this->title;
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getTitle(): ?string
  71.     {
  72.         return $this->title;
  73.     }
  74.     public function setTitle(string $title): static
  75.     {
  76.         $this->title $title;
  77.         return $this;
  78.     }
  79.     public function getTitleEn(): ?string
  80.     {
  81.         return $this->titleEn;
  82.     }
  83.     public function setTitleEn(?string $titleEn): static
  84.     {
  85.         $this->titleEn $titleEn;
  86.         return $this;
  87.     }
  88.     public function getDescription(): ?string
  89.     {
  90.         return $this->description;
  91.     }
  92.     public function setDescription(?string $description): static
  93.     {
  94.         $this->description $description;
  95.         return $this;
  96.     }
  97.     public function getPosition(): ?int
  98.     {
  99.         return $this->position;
  100.     }
  101.     public function setPosition(int $position): static
  102.     {
  103.         $this->position $position;
  104.         return $this;
  105.     }
  106.     public function getSubjectReference(): ?SubjectReference
  107.     {
  108.         return $this->subjectReference;
  109.     }
  110.     public function setSubjectReference(?SubjectReference $subjectReference): static
  111.     {
  112.         $this->subjectReference $subjectReference;
  113.         return $this;
  114.     }
  115.     public function getDeadlineQuarter(): ?Quarter
  116.     {
  117.         return $this->deadlineQuarter;
  118.     }
  119.     public function setDeadlineQuarter(?Quarter $deadlineQuarter): static
  120.     {
  121.         $this->deadlineQuarter $deadlineQuarter;
  122.         return $this;
  123.     }
  124.     public function getDeadlineDate(): ?\DateTimeInterface
  125.     {
  126.         return $this->deadlineDate;
  127.     }
  128.     public function setDeadlineDate(?\DateTimeInterface $deadlineDate): static
  129.     {
  130.         $this->deadlineDate $deadlineDate;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, ChapterProgress>
  135.      */
  136.     public function getProgresses(): Collection
  137.     {
  138.         return $this->progresses;
  139.     }
  140.     public function addProgress(ChapterProgress $progress): static
  141.     {
  142.         if (!$this->progresses->contains($progress)) {
  143.             $this->progresses->add($progress);
  144.             $progress->setChapter($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeProgress(ChapterProgress $progress): static
  149.     {
  150.         if ($this->progresses->removeElement($progress)) {
  151.             if ($progress->getChapter() === $this) {
  152.                 $progress->setChapter(null);
  153.             }
  154.         }
  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. }