src/Entity/SubjectGroupReference.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubjectGroupReferenceRepository;
  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.  * Groupe de matières national (équivalent national de SubjectGroup).
  10.  *
  11.  * Exemple : "Matières Littéraires", "Matières Scientifiques", "Matières
  12.  * Complémentaires" pour la ClassOption "3ème".
  13.  *
  14.  * Créé par le superadmin. Chaque SubjectReference s'y rattache, ce qui
  15.  * permet de reproduire la même organisation par groupe que dans les
  16.  * bulletins (cf. SubjectGroup), mais au niveau du programme national.
  17.  */
  18. #[ORM\HasLifecycleCallbacks]
  19. #[ORM\Entity(repositoryClassSubjectGroupReferenceRepository::class)]
  20. class SubjectGroupReference
  21. {
  22.     use Timestampable;
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\Column(length255)]
  28.     private ?string $name null;
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $nameEn null;
  31.     #[ORM\Column(nullabletrue)]
  32.     private ?int $position null;
  33.     #[ORM\ManyToOne(inversedBy'subjectGroupReferences')]
  34.     #[ORM\JoinColumn(nullablefalse)]
  35.     private ?ClassOption $classOption null;
  36.     #[ORM\OneToMany(mappedBy'subjectGroupReference'targetEntitySubjectReference::class)]
  37.     private Collection $subjectReferences;
  38.     #[ORM\ManyToOne]
  39.     private ?User $author null;
  40.     #[ORM\OneToMany(mappedBy'reference'targetEntitySubjectGroup::class)]
  41.     private Collection $subjectGroups;
  42.     public function __construct()
  43.     {
  44.         $this->subjectReferences = new ArrayCollection();
  45.         $this->subjectGroups = new ArrayCollection();
  46.     }
  47.     public function __toString(): string
  48.     {
  49.         return $this->name ' (' . ($this->classOption?->getName() ?? '') . ')';
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getName(): ?string
  56.     {
  57.         return $this->name;
  58.     }
  59.     public function setName(string $name): static
  60.     {
  61.         $this->name $name;
  62.         return $this;
  63.     }
  64.     public function getNameEn(): ?string
  65.     {
  66.         return $this->nameEn;
  67.     }
  68.     public function setNameEn(?string $nameEn): static
  69.     {
  70.         $this->nameEn $nameEn;
  71.         return $this;
  72.     }
  73.     public function getPosition(): ?int
  74.     {
  75.         return $this->position;
  76.     }
  77.     public function setPosition(?int $position): static
  78.     {
  79.         $this->position $position;
  80.         return $this;
  81.     }
  82.     public function getClassOption(): ?ClassOption
  83.     {
  84.         return $this->classOption;
  85.     }
  86.     public function setClassOption(?ClassOption $classOption): static
  87.     {
  88.         $this->classOption $classOption;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return Collection<int, SubjectReference>
  93.      */
  94.     public function getSubjectReferences(): Collection
  95.     {
  96.         return $this->subjectReferences;
  97.     }
  98.     public function addSubjectReference(SubjectReference $subjectReference): static
  99.     {
  100.         if (!$this->subjectReferences->contains($subjectReference)) {
  101.             $this->subjectReferences->add($subjectReference);
  102.             $subjectReference->setSubjectGroupReference($this);
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeSubjectReference(SubjectReference $subjectReference): static
  107.     {
  108.         if ($this->subjectReferences->removeElement($subjectReference)) {
  109.             if ($subjectReference->getSubjectGroupReference() === $this) {
  110.                 $subjectReference->setSubjectGroupReference(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function getAuthor(): ?User
  116.     {
  117.         return $this->author;
  118.     }
  119.     public function setAuthor(?User $author): static
  120.     {
  121.         $this->author $author;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return Collection<int, SubjectGroup>
  126.      */
  127.     public function getSubjectGroups(): Collection
  128.     {
  129.         return $this->subjectGroups;
  130.     }
  131.     public function addSubjectGroup(SubjectGroup $subjectGroup): static
  132.     {
  133.         if (!$this->subjectGroups->contains($subjectGroup)) {
  134.             $this->subjectGroups->add($subjectGroup);
  135.             $subjectGroup->setReference($this);
  136.         }
  137.         return $this;
  138.     }
  139.     public function removeSubjectGroup(SubjectGroup $subjectGroup): static
  140.     {
  141.         if ($this->subjectGroups->removeElement($subjectGroup)) {
  142.             // set the owning side to null (unless already changed)
  143.             if ($subjectGroup->getReference() === $this) {
  144.                 $subjectGroup->setReference(null);
  145.             }
  146.         }
  147.         return $this;
  148.     }
  149. }