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 Lesson 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.     /**
  44.      * Horaire hebdomadaire de référence (nombre d'heures de cours par
  45.      * semaine) pour cette matière du programme national, facultatif.
  46.      */
  47.     #[ORM\Column(nullabletrue)]
  48.     private ?float $horaire null;
  49.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  50.     #[ORM\JoinColumn(nullablefalse)]
  51.     private ?ClassOption $classOption null;
  52.     /**
  53.      * Groupe de matières national (équivalent national de SubjectGroup).
  54.      */
  55.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  56.     private ?SubjectGroupReference $subjectGroupReference null;
  57.     /**
  58.      * "Version du programme national" : permet de faire évoluer le
  59.      * programme d'une année à l'autre sans perdre l'historique.
  60.      * Ex : SubjectReference "Maths - 3ème" version 2025-2026
  61.      *      vs           "Maths - 3ème" version 2026-2027.
  62.      */
  63.     #[ORM\ManyToOne(inversedBy'subjectReferences')]
  64.     #[ORM\JoinColumn(nullablefalse)]
  65.     private ?SchoolYear $year null;
  66.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntityLesson::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  67.     #[ORM\OrderBy(['position' => 'ASC'])]
  68.     private Collection $lessons;
  69.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntityModule::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  70.     #[ORM\OrderBy(['position' => 'ASC'])]
  71.     private Collection $modules;
  72.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntityLearningUnit::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  73.     #[ORM\OrderBy(['position' => 'ASC'])]
  74.     private Collection $learningUnits;
  75.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntityCompetenceReference::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  76.     #[ORM\OrderBy(['quarterNumber' => 'ASC''position' => 'ASC'])]
  77.     private Collection $competenceReferences;
  78.     /**
  79.      * Sous-matières du programme national (écoles primaires/maternelles) —
  80.      * voir SubjectComponentReference.
  81.      */
  82.     #[ORM\OneToMany(mappedBy'subjectReference'targetEntitySubjectComponentReference::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  83.     #[ORM\OrderBy(['position' => 'ASC'])]
  84.     private Collection $subjectComponentReferences;
  85.     #[ORM\ManyToOne]
  86.     private ?User $author null;
  87.     #[ORM\OneToMany(mappedBy'reference'targetEntitySubject::class)]
  88.     private Collection $subjects;
  89.     public function __construct()
  90.     {
  91.         $this->lessons = new ArrayCollection();
  92.         $this->subjects = new ArrayCollection();
  93.         $this->competenceReferences = new ArrayCollection();
  94.         $this->subjectComponentReferences = new ArrayCollection();
  95.         $this->modules = new ArrayCollection();
  96.         $this->learningUnits = new ArrayCollection();
  97.     }
  98.     public function __toString(): string
  99.     {
  100.         return $this->name ' (' . ($this->classOption?->getName() ?? '') . ')';
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getName(): ?string
  107.     {
  108.         return $this->name;
  109.     }
  110.     public function setName(string $name): static
  111.     {
  112.         $this->name $name;
  113.         return $this;
  114.     }
  115.     public function getNameEn(): ?string
  116.     {
  117.         return $this->nameEn;
  118.     }
  119.     public function setNameEn(?string $nameEn): static
  120.     {
  121.         $this->nameEn $nameEn;
  122.         return $this;
  123.     }
  124.     public function getCoef(): ?float
  125.     {
  126.         return $this->coef;
  127.     }
  128.     public function setCoef(?float $coef): static
  129.     {
  130.         $this->coef $coef;
  131.         return $this;
  132.     }
  133.     public function getHoraire(): ?float
  134.     {
  135.         return $this->horaire;
  136.     }
  137.     public function setHoraire(?float $horaire): static
  138.     {
  139.         $this->horaire $horaire;
  140.         return $this;
  141.     }
  142.     public function getClassOption(): ?ClassOption
  143.     {
  144.         return $this->classOption;
  145.     }
  146.     public function setClassOption(?ClassOption $classOption): static
  147.     {
  148.         $this->classOption $classOption;
  149.         return $this;
  150.     }
  151.     public function getSubjectGroupReference(): ?SubjectGroupReference
  152.     {
  153.         return $this->subjectGroupReference;
  154.     }
  155.     public function setSubjectGroupReference(?SubjectGroupReference $subjectGroupReference): static
  156.     {
  157.         $this->subjectGroupReference $subjectGroupReference;
  158.         return $this;
  159.     }
  160.     public function getYear(): ?SchoolYear
  161.     {
  162.         return $this->year;
  163.     }
  164.     public function setYear(?SchoolYear $year): static
  165.     {
  166.         $this->year $year;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Lesson>
  171.      */
  172.     public function getLessons(): Collection
  173.     {
  174.         return $this->lessons;
  175.     }
  176.     public function addLesson(Lesson $lesson): static
  177.     {
  178.         if (!$this->lessons->contains($lesson)) {
  179.             $this->lessons->add($lesson);
  180.             $lesson->setSubjectReference($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeLesson(Lesson $lesson): static
  185.     {
  186.         if ($this->lessons->removeElement($lesson)) {
  187.             if ($lesson->getSubjectReference() === $this) {
  188.                 $lesson->setSubjectReference(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, CompetenceReference>
  195.      */
  196.     public function getCompetenceReferences(): Collection
  197.     {
  198.         return $this->competenceReferences;
  199.     }
  200.     public function addCompetenceReference(CompetenceReference $competenceReference): static
  201.     {
  202.         if (!$this->competenceReferences->contains($competenceReference)) {
  203.             $this->competenceReferences->add($competenceReference);
  204.             $competenceReference->setSubjectReference($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeCompetenceReference(CompetenceReference $competenceReference): static
  209.     {
  210.         if ($this->competenceReferences->removeElement($competenceReference)) {
  211.             if ($competenceReference->getSubjectReference() === $this) {
  212.                 $competenceReference->setSubjectReference(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return Collection<int, SubjectComponentReference>
  219.      */
  220.     public function getSubjectComponentReferences(): Collection
  221.     {
  222.         return $this->subjectComponentReferences;
  223.     }
  224.     public function addSubjectComponentReference(SubjectComponentReference $subjectComponentReference): static
  225.     {
  226.         if (!$this->subjectComponentReferences->contains($subjectComponentReference)) {
  227.             $this->subjectComponentReferences->add($subjectComponentReference);
  228.             $subjectComponentReference->setSubjectReference($this);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeSubjectComponentReference(SubjectComponentReference $subjectComponentReference): static
  233.     {
  234.         if ($this->subjectComponentReferences->removeElement($subjectComponentReference)) {
  235.             if ($subjectComponentReference->getSubjectReference() === $this) {
  236.                 $subjectComponentReference->setSubjectReference(null);
  237.             }
  238.         }
  239.         return $this;
  240.     }
  241.     public function getAuthor(): ?User
  242.     {
  243.         return $this->author;
  244.     }
  245.     public function setAuthor(?User $author): static
  246.     {
  247.         $this->author $author;
  248.         return $this;
  249.     }
  250.     /** @return Collection<int, Module> */
  251.     public function getModules(): Collection
  252.     {
  253.         return $this->modules;
  254.     }
  255.     /** @return Collection<int, LearningUnit> */
  256.     public function getLearningUnits(): Collection
  257.     {
  258.         return $this->learningUnits;
  259.     }
  260.     /**
  261.      * @return Collection<int, Subject>
  262.      */
  263.     public function getSubjects(): Collection
  264.     {
  265.         return $this->subjects;
  266.     }
  267.     public function addSubject(Subject $subject): static
  268.     {
  269.         if (!$this->subjects->contains($subject)) {
  270.             $this->subjects->add($subject);
  271.             $subject->setReference($this);
  272.         }
  273.         return $this;
  274.     }
  275.     public function removeSubject(Subject $subject): static
  276.     {
  277.         if ($this->subjects->removeElement($subject)) {
  278.             // set the owning side to null (unless already changed)
  279.             if ($subject->getReference() === $this) {
  280.                 $subject->setReference(null);
  281.             }
  282.         }
  283.         return $this;
  284.     }
  285. }