src/Entity/SubjectChapter.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubjectChapterRepository;
  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 LOCAL d'une matière dans un établissement.
  10.  *
  11.  * Créé automatiquement par copie du programme national (Chapter) lors
  12.  * de l'affectation d'un Subject à un SubjectReference, ou manuellement
  13.  * par l'admin/éditeur de l'école.
  14.  *
  15.  * Chaque école possède sa propre copie, modifiable indépendamment du
  16.  * programme national. `sourceChapter` garde la traçabilité de l'origine
  17.  * nationale (nullable : null si chapitre 100 % personnalisé).
  18.  *
  19.  * ChapterProgress pointe désormais ici (et non plus sur Chapter).
  20.  */
  21. #[ORM\HasLifecycleCallbacks]
  22. #[ORM\Entity(repositoryClassSubjectChapterRepository::class)]
  23. class SubjectChapter
  24. {
  25.     use Timestampable;
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column]
  29.     private ?int $id null;
  30.     #[ORM\Column(length255)]
  31.     private ?string $title null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     private ?string $titleEn null;
  34.     #[ORM\Column(type'text'nullabletrue)]
  35.     private ?string $description null;
  36.     /**
  37.      * Ordre du chapitre dans la progression locale (1, 2, 3...).
  38.      * L'admin peut réordonner librement via drag & drop.
  39.      */
  40.     #[ORM\Column]
  41.     private ?int $position null;
  42.     /**
  43.      * La matière réelle (école + classe + année) à laquelle ce chapitre appartient.
  44.      */
  45.     #[ORM\ManyToOne(inversedBy'subjectChapters')]
  46.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  47.     private ?Subject $subject null;
  48.     /**
  49.      * Chapitre national d'origine.
  50.      * NULL si le chapitre a été créé manuellement par l'admin (hors programme national).
  51.      * Permet au superadmin de tracer la couverture nationale via cette FK.
  52.      */
  53.     #[ORM\ManyToOne]
  54.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  55.     private ?Chapter $sourceChapter null;
  56.     /**
  57.      * Séquence avant la fin de laquelle ce chapitre doit être terminé.
  58.      */
  59.     #[ORM\ManyToOne]
  60.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  61.     private ?Quarter $deadlineQuarter null;
  62.     /**
  63.      * Date calendaire optionnelle de deadline (alternative à deadlineQuarter).
  64.      */
  65.     #[ORM\Column(type'date'nullabletrue)]
  66.     private ?\DateTimeInterface $deadlineDate null;
  67.     /**
  68.      * 1 SubjectChapter → au plus 1 ChapterProgress (même Subject fixé).
  69.      */
  70.     #[ORM\OneToMany(
  71.         mappedBy'subjectChapter',
  72.         targetEntityChapterProgress::class,
  73.         cascade: ['persist''remove'],
  74.         orphanRemovaltrue
  75.     )]
  76.     private Collection $progresses;
  77.     #[ORM\ManyToOne]
  78.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  79.     private ?User $author null;
  80.     public function __construct()
  81.     {
  82.         $this->progresses = new ArrayCollection();
  83.     }
  84.     public function __toString(): string
  85.     {
  86.         return $this->title ?? '';
  87.     }
  88.     public function getId(): ?int
  89.     {
  90.         return $this->id;
  91.     }
  92.     public function getTitle(): ?string
  93.     {
  94.         return $this->title;
  95.     }
  96.     public function setTitle(string $title): static
  97.     {
  98.         $this->title $title;
  99.         return $this;
  100.     }
  101.     public function getTitleEn(): ?string
  102.     {
  103.         return $this->titleEn;
  104.     }
  105.     public function setTitleEn(?string $titleEn): static
  106.     {
  107.         $this->titleEn $titleEn;
  108.         return $this;
  109.     }
  110.     public function getDescription(): ?string
  111.     {
  112.         return $this->description;
  113.     }
  114.     public function setDescription(?string $description): static
  115.     {
  116.         $this->description $description;
  117.         return $this;
  118.     }
  119.     public function getPosition(): ?int
  120.     {
  121.         return $this->position;
  122.     }
  123.     public function setPosition(int $position): static
  124.     {
  125.         $this->position $position;
  126.         return $this;
  127.     }
  128.     public function getSubject(): ?Subject
  129.     {
  130.         return $this->subject;
  131.     }
  132.     public function setSubject(?Subject $subject): static
  133.     {
  134.         $this->subject $subject;
  135.         return $this;
  136.     }
  137.     public function getSourceChapter(): ?Chapter
  138.     {
  139.         return $this->sourceChapter;
  140.     }
  141.     public function setSourceChapter(?Chapter $sourceChapter): static
  142.     {
  143.         $this->sourceChapter $sourceChapter;
  144.         return $this;
  145.     }
  146.     public function getDeadlineQuarter(): ?Quarter
  147.     {
  148.         return $this->deadlineQuarter;
  149.     }
  150.     public function setDeadlineQuarter(?Quarter $deadlineQuarter): static
  151.     {
  152.         $this->deadlineQuarter $deadlineQuarter;
  153.         return $this;
  154.     }
  155.     public function getDeadlineDate(): ?\DateTimeInterface
  156.     {
  157.         return $this->deadlineDate;
  158.     }
  159.     public function setDeadlineDate(?\DateTimeInterface $deadlineDate): static
  160.     {
  161.         $this->deadlineDate $deadlineDate;
  162.         return $this;
  163.     }
  164.     /** @return Collection<int, ChapterProgress> */
  165.     public function getProgresses(): Collection
  166.     {
  167.         return $this->progresses;
  168.     }
  169.     public function addProgress(ChapterProgress $progress): static
  170.     {
  171.         if (!$this->progresses->contains($progress)) {
  172.             $this->progresses->add($progress);
  173.             $progress->setSubjectChapter($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeProgress(ChapterProgress $progress): static
  178.     {
  179.         if ($this->progresses->removeElement($progress)) {
  180.             if ($progress->getSubjectChapter() === $this) {
  181.                 $progress->setSubjectChapter(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     public function getAuthor(): ?User
  187.     {
  188.         return $this->author;
  189.     }
  190.     public function setAuthor(?User $author): static
  191.     {
  192.         $this->author $author;
  193.         return $this;
  194.     }
  195.     /**
  196.      * true = chapitre 100 % custom (hors programme national).
  197.      * false = chapitre copié depuis le programme national.
  198.      */
  199.     public function isCustom(): bool
  200.     {
  201.         return $this->sourceChapter === null;
  202.     }
  203. }