src/Entity/SchoolSection.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SchoolSectionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use App\Entity\Traits\Timestampable;
  9. #[ORM\HasLifecycleCallbacks]
  10. #[ORM\Entity(repositoryClassSchoolSectionRepository::class)]
  11. #[UniqueEntity(fields: ['name'], message'There is already an section with this name')]
  12. class SchoolSection
  13. {
  14.     use Timestampable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\OneToMany(mappedBy'section'targetEntityTheClass::class)]
  22.     private Collection $theClasses;
  23.     #[ORM\ManyToOne(inversedBy'schoolSections'cascade: ["persist"])]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?User $author null;
  26.     #[ORM\ManyToOne(inversedBy'schoolSectionsEdited'cascade: ["persist"])]
  27.     private ?User $editor null;
  28.     #[ORM\ManyToOne(inversedBy'schoolSections'cascade: ["persist"])]
  29.     private ?School $school null;
  30.     public function __toString():string
  31.     {
  32.         return $this->name;
  33.     }
  34.     public function __construct()
  35.     {
  36.         $this->theClasses = new ArrayCollection();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     public function setName(string $name): static
  47.     {
  48.         $this->name $name;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection<int, TheClass>
  53.      */
  54.     public function getTheClasses(): Collection
  55.     {
  56.         return $this->theClasses;
  57.     }
  58.     public function addTheClass(TheClass $theClass): static
  59.     {
  60.         if (!$this->theClasses->contains($theClass)) {
  61.             $this->theClasses->add($theClass);
  62.             $theClass->setSection($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function removeTheClass(TheClass $theClass): static
  67.     {
  68.         if ($this->theClasses->removeElement($theClass)) {
  69.             // set the owning side to null (unless already changed)
  70.             if ($theClass->getSection() === $this) {
  71.                 $theClass->setSection(null);
  72.             }
  73.         }
  74.         return $this;
  75.     }
  76.     public function getAuthor(): ?User
  77.     {
  78.         return $this->author;
  79.     }
  80.     public function setAuthor(?User $author): static
  81.     {
  82.         $this->author $author;
  83.         return $this;
  84.     }
  85.     public function getEditor(): ?User
  86.     {
  87.         return $this->editor;
  88.     }
  89.     public function setEditor(?User $editor): static
  90.     {
  91.         $this->editor $editor;
  92.         return $this;
  93.     }
  94.     public function getSchool(): ?School
  95.     {
  96.         return $this->school;
  97.     }
  98.     public function setSchool(?School $school): static
  99.     {
  100.         $this->school $school;
  101.         return $this;
  102.     }
  103. }