src/Entity/SubjectLearningUnit.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubjectLearningUnitRepository;
  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.  * Unité d'Apprentissage (UA) LOCALE d'une matière dans un établissement.
  10.  *
  11.  * Pendant de LearningUnit (programme national) pour la partie du cahier de
  12.  * texte "hors programme national" — voir SubjectModule pour le même
  13.  * principe côté Thème. Scopée au Subject réel (matière + classe + année +
  14.  * école), comme SubjectLesson.
  15.  *
  16.  * `subjectModule` (local) est indépendant de `module` national :
  17.  * SubjectLesson peut être rattachée à une UA locale sans passer par un
  18.  * thème local (subjectModule null), exactement comme LearningUnit peut
  19.  * exister sans Module parent côté programme national.
  20.  */
  21. #[ORM\HasLifecycleCallbacks]
  22. #[ORM\Entity(repositoryClassSubjectLearningUnitRepository::class)]
  23. class SubjectLearningUnit
  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]
  35.     private ?int $position null;
  36.     #[ORM\ManyToOne(inversedBy'subjectLearningUnits')]
  37.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  38.     private ?Subject $subject null;
  39.     #[ORM\ManyToOne(inversedBy'subjectLearningUnits')]
  40.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  41.     private ?SubjectModule $subjectModule null;
  42.     /**
  43.      * Thème national (Module) rattaché DIRECTEMENT, sans passer par une
  44.      * copie locale — même principe que SubjectLesson::$module : permet à
  45.      * l'école de classer une UA locale sous un thème du programme national
  46.      * existant plutôt que de forcément créer un SubjectModule pour ça.
  47.      * Indépendant de $subjectModule (l'un OU l'autre, jamais les deux —
  48.      * voir normalizeTheme()).
  49.      */
  50.     #[ORM\ManyToOne]
  51.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  52.     private ?Module $module null;
  53.     #[ORM\OneToMany(mappedBy'subjectLearningUnit'targetEntitySubjectLesson::class)]
  54.     private Collection $subjectLessons;
  55.     #[ORM\ManyToOne]
  56.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  57.     private ?User $author null;
  58.     public function __construct()
  59.     {
  60.         $this->subjectLessons = 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 getPosition(): ?int
  89.     {
  90.         return $this->position;
  91.     }
  92.     public function setPosition(int $position): static
  93.     {
  94.         $this->position $position;
  95.         return $this;
  96.     }
  97.     public function getSubject(): ?Subject
  98.     {
  99.         return $this->subject;
  100.     }
  101.     public function setSubject(?Subject $subject): static
  102.     {
  103.         $this->subject $subject;
  104.         return $this;
  105.     }
  106.     public function getSubjectModule(): ?SubjectModule
  107.     {
  108.         return $this->subjectModule;
  109.     }
  110.     public function setSubjectModule(?SubjectModule $subjectModule): static
  111.     {
  112.         $this->subjectModule $subjectModule;
  113.         return $this;
  114.     }
  115.     public function getModule(): ?Module
  116.     {
  117.         return $this->module;
  118.     }
  119.     public function setModule(?Module $module): static
  120.     {
  121.         $this->module $module;
  122.         return $this;
  123.     }
  124.     /**
  125.      * Libellé du thème effectif (local OU national), pour affichage uniforme
  126.      * dans les templates — voir SubjectLesson::getEffectiveThemeLabel()
  127.      * pour le même principe.
  128.      */
  129.     public function getEffectiveThemeLabel(): ?string
  130.     {
  131.         return $this->subjectModule?->getTitle() ?? $this->module?->getTitle();
  132.     }
  133.     /**
  134.      * Empêche l'état incohérent "thème local ET thème national tous les
  135.      * deux renseignés" — voir SubjectLesson::normalizeTheme() pour le même
  136.      * principe (le formulaire propose les deux comme deux champs
  137.      * indépendants, voir SubjectLearningUnitType).
  138.      */
  139.     public function normalizeTheme(): void
  140.     {
  141.         if ($this->subjectModule !== null) {
  142.             $this->module null;
  143.         }
  144.     }
  145.     /** @return Collection<int, SubjectLesson> */
  146.     public function getSubjectLessons(): Collection
  147.     {
  148.         return $this->subjectLessons;
  149.     }
  150.     public function getAuthor(): ?User
  151.     {
  152.         return $this->author;
  153.     }
  154.     public function setAuthor(?User $author): static
  155.     {
  156.         $this->author $author;
  157.         return $this;
  158.     }
  159. }