src/Entity/Section.php line 23

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\enums\AgeRange;
  4. use App\Entity\Classroom;
  5. use Symfony\Component\Uid\Ulid;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\SectionRepository;
  8. use Doctrine\Common\Collections\Collection;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. #[ORM\Entity(repositoryClassSectionRepository::class)]
  15. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  16. #[ORM\HasLifecycleCallbacks()]
  17. #[ApiResource(
  18.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  19. )]
  20. class Section
  21. {
  22.     use Timestamps;
  23.     #[ORM\Id]
  24.     #[ORM\Column(type'ulid'uniquetrue)]
  25.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  26.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  27.     #[Groups(['read:section:basic''read:section:export'])]
  28.     private ?Ulid $id null;
  29.     #[ORM\Column(type'string'length255)]
  30.     #[Groups(['read:section:basic''read:section:export'])]
  31.     private $name;
  32.     #[ORM\Column(type'string'length255nullabletrue)]
  33.     #[Groups(['read:section:basic'])]
  34.     private $description;
  35.     #[ORM\Column(type'string'length255)]
  36.     #[Groups(['read:section:basic''read:section:export'])]
  37.     private $age_range;
  38.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'sections')]
  39.     #[ORM\JoinColumn(nullablefalse)]
  40.     private $owner;
  41.     #[ORM\OneToMany(mappedBy'section'targetEntityClassroom::class)]
  42.     private $classrooms;
  43.     #[ORM\OneToMany(mappedBy'section'targetEntityChild::class)]
  44.     private $children;
  45.     #[ORM\OneToMany(mappedBy'section'targetEntityPrechild::class)]
  46.     private $prechildren;
  47.     public function __construct()
  48.     {
  49.         $this->classrooms = new ArrayCollection();
  50.         $this->children = new ArrayCollection();
  51.         $this->prechildren = new ArrayCollection();
  52.     }
  53.     public function __toString()
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function getId(): ?Ulid
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getName(): ?string
  62.     {
  63.         return $this->name;
  64.     }
  65.     public function setName(string $name): self
  66.     {
  67.         $this->name $name;
  68.         return $this;
  69.     }
  70.     public function getDescription(): ?string
  71.     {
  72.         return $this->description;
  73.     }
  74.     public function setDescription(?string $description): self
  75.     {
  76.         $this->description $description;
  77.         return $this;
  78.     }
  79.     public function getAgeRange(): ?string
  80.     {
  81.         return $this->age_range;
  82.     }
  83.     public function setAgeRange(?string $age_range): self
  84.     {
  85.         $this->age_range $age_range;
  86.         return $this;
  87.     }
  88.     public function getOwner(): ?Company
  89.     {
  90.         return $this->owner;
  91.     }
  92.     public function setOwner(?Company $owner): self
  93.     {
  94.         $this->owner $owner;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, Classroom>
  99.      */
  100.     public function getClassrooms(): Collection
  101.     {
  102.         return $this->classrooms;
  103.     }
  104.     public function addClassroom(Classroom $classroom): self
  105.     {
  106.         if (!$this->classrooms->contains($classroom)) {
  107.             $this->classrooms[] = $classroom;
  108.             $classroom->setSection($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeClassroom(Classroom $classroom): self
  113.     {
  114.         if ($this->classrooms->removeElement($classroom)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($classroom->getSection() === $this) {
  117.                 $classroom->setSection(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection<int, Child>
  124.      */
  125.     public function getChildren(): Collection
  126.     {
  127.         return $this->children;
  128.     }
  129.     public function addChild(Child $child): self
  130.     {
  131.         if (!$this->children->contains($child)) {
  132.             $this->children[] = $child;
  133.             $child->setSection($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeChild(Child $child): self
  138.     {
  139.         if ($this->children->removeElement($child)) {
  140.             // set the owning side to null (unless already changed)
  141.             if ($child->getSection() === $this) {
  142.                 $child->setSection(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, Prechild>
  149.      */
  150.     public function getPrechildren(): Collection
  151.     {
  152.         return $this->prechildren;
  153.     }
  154.     public function addPrechild(Prechild $prechild): self
  155.     {
  156.         if (!$this->prechildren->contains($prechild)) {
  157.             $this->prechildren[] = $prechild;
  158.             $prechild->setSection($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removePrechild(Prechild $prechild): self
  163.     {
  164.         if ($this->prechildren->removeElement($prechild)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($prechild->getSection() === $this) {
  167.                 $prechild->setSection(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172. }