src/Entity/SubjectReference.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubjectReferenceRepository;
  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.  * Référentiel national d'une matière pour une ClassOption donnée,
  10.  * pour une "version du programme" (SchoolYear) donnée.
  11.  *
  12.  * Exemple : "Mathématiques" pour la ClassOption "3ème", coef 4,
  13.  * version programme 2025-2026 → 1 SubjectReference.
  14.  *
  15.  * Reprend volontairement les mêmes propriétés que Subject (name, nameEn,
  16.  * coef, year, subjectGroup) à l'exception de tout ce qui rattache Subject
  17.  * à une instance concrète (school, classe, prof, notes...).
  18.  *
  19.  * Le superadmin crée ces référentiels et leurs Chapter associés.
  20.  * Chaque Subject réel "hérite" de la progression via
  21.  * SubjectReferenceRepository::findForSubject().
  22.  */
  23. #[ORM\HasLifecycleCallbacks]
  24. #[ORM\Entity(repositoryClassSubjectReferenceRepository::class)]
  25. class SubjectReference
  26. {
  27.     use Timestampable;
  28.     #[ORM\Id]
  29.     #[ORM\GeneratedValue]
  30.     #[ORM\Column]
  31.     private ?int $id null;
  32.     #[ORM\Column(length255)]
  33.     private ?string $name null;
  34.     #[ORM\Column(length255nullabletrue)]
  35.     private ?string $nameEn null;
  36.     /**
  37.      * Coefficient de référence de la matière pour cette ClassOption.
  38.      * Sert d'indication / valeur par défaut ; chaque Subject réel garde
  39.      * son propre coef (qui peut différer selon l'école).
  40.      */
  41.     #[ORM\Column(nullabletrue)]
  42.     private ?float $coef null;
  43.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  44.     #[ORM\JoinColumn(nullablefalse)]
  45.     private ?ClassOption $classOption null;
  46.     /**
  47.      * Groupe de matières national (équivalent national de SubjectGroup).
  48.      */
  49.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  50.     private ?SubjectGroupReference $subjectGroupReference null;
  51.     /**
  52.      * "Version du programme national" : permet de faire évoluer le
  53.      * programme d'une année à l'autre sans perdre l'historique.
  54.      * Ex : SubjectReference "Maths - 3ème" version 2025-2026
  55.      *      vs           "Maths - 3ème" version 2026-2027.
  56.      */
  57.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  58.     #[ORM\JoinColumn(nullablefalse)]
  59.     private ?SchoolYear $year null;
  60.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntityChapter::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  61.     #[ORM\OrderBy(['position' => 'ASC'])]
  62.     private Collection $chapters;
  63.     #[ORM\ManyToOne]
  64.     private ?User $author null;
  65.     #[ORM\OneToMany(mappedBy'reference'targetEntitySubject::class)]
  66.     private Collection $subjects;
  67.     public function __construct()
  68.     {
  69.         $this->chapters = new ArrayCollection();
  70.         $this->subjects = new ArrayCollection();
  71.     }
  72.     public function __toString(): string
  73.     {
  74.         return $this->name ' (' . ($this->classOption?->getName() ?? '') . ')';
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getName(): ?string
  81.     {
  82.         return $this->name;
  83.     }
  84.     public function setName(string $name): static
  85.     {
  86.         $this->name $name;
  87.         return $this;
  88.     }
  89.     public function getNameEn(): ?string
  90.     {
  91.         return $this->nameEn;
  92.     }
  93.     public function setNameEn(?string $nameEn): static
  94.     {
  95.         $this->nameEn $nameEn;
  96.         return $this;
  97.     }
  98.     public function getCoef(): ?float
  99.     {
  100.         return $this->coef;
  101.     }
  102.     public function setCoef(?float $coef): static
  103.     {
  104.         $this->coef $coef;
  105.         return $this;
  106.     }
  107.     public function getClassOption(): ?ClassOption
  108.     {
  109.         return $this->classOption;
  110.     }
  111.     public function setClassOption(?ClassOption $classOption): static
  112.     {
  113.         $this->classOption $classOption;
  114.         return $this;
  115.     }
  116.     public function getSubjectGroupReference(): ?SubjectGroupReference
  117.     {
  118.         return $this->subjectGroupReference;
  119.     }
  120.     public function setSubjectGroupReference(?SubjectGroupReference $subjectGroupReference): static
  121.     {
  122.         $this->subjectGroupReference $subjectGroupReference;
  123.         return $this;
  124.     }
  125.     public function getYear(): ?SchoolYear
  126.     {
  127.         return $this->year;
  128.     }
  129.     public function setYear(?SchoolYear $year): static
  130.     {
  131.         $this->year $year;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection<int, Chapter>
  136.      */
  137.     public function getChapters(): Collection
  138.     {
  139.         return $this->chapters;
  140.     }
  141.     public function addChapter(Chapter $chapter): static
  142.     {
  143.         if (!$this->chapters->contains($chapter)) {
  144.             $this->chapters->add($chapter);
  145.             $chapter->setSubjectReference($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeChapter(Chapter $chapter): static
  150.     {
  151.         if ($this->chapters->removeElement($chapter)) {
  152.             if ($chapter->getSubjectReference() === $this) {
  153.                 $chapter->setSubjectReference(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function getAuthor(): ?User
  159.     {
  160.         return $this->author;
  161.     }
  162.     public function setAuthor(?User $author): static
  163.     {
  164.         $this->author $author;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection<int, Subject>
  169.      */
  170.     public function getSubjects(): Collection
  171.     {
  172.         return $this->subjects;
  173.     }
  174.     public function addSubject(Subject $subject): static
  175.     {
  176.         if (!$this->subjects->contains($subject)) {
  177.             $this->subjects->add($subject);
  178.             $subject->setReference($this);
  179.         }
  180.         return $this;
  181.     }
  182.     public function removeSubject(Subject $subject): static
  183.     {
  184.         if ($this->subjects->removeElement($subject)) {
  185.             // set the owning side to null (unless already changed)
  186.             if ($subject->getReference() === $this) {
  187.                 $subject->setReference(null);
  188.             }
  189.         }
  190.         return $this;
  191.     }
  192. }