src/Entity/Classroom.php line 47

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\enums\ClassroomStatus;
  4. use Symfony\Component\Uid\Ulid;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\ClassroomRepository;
  7. use Doctrine\Common\Collections\Collection;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. #[ORM\Entity(repositoryClassClassroomRepository::class)]
  14. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  15. #[ORM\HasLifecycleCallbacks]
  16. #[ApiResource(
  17.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  18.     itemOperations: [
  19.         'get' => [
  20.             'normalization_context' => [
  21.                 'groups' => [
  22.                     'read:classroom:basic',
  23.                     'read:employee:basic',
  24.                     'read:child:basic',
  25.                     'read:section:basic',
  26.                 ]
  27.             ]
  28.         ],
  29.     ],
  30.     collectionOperations: [
  31.         'get' => [
  32.             'normalization_context' => [
  33.                 'groups' => [
  34.                     'read:classroom:basic',
  35.                     'read:section:basic',
  36.                     'read:child:basic'
  37.                 ]
  38.             ]
  39.         ],
  40.     ],
  41. )]
  42. class Classroom
  43. {
  44.     use Timestamps;
  45.     #[ORM\Id]
  46.     #[ORM\Column(type'ulid'uniquetrue)]
  47.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  48.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  49.     #[Groups(['read:classroom:basic'])]
  50.     private ?Ulid $id null;
  51.     #[ORM\Column(type'string'length255)]
  52.     #[Groups(['read:classroom:basic'])]
  53.     private $name;
  54.     #[ORM\Column(type'string'length255nullabletrue)]
  55.     #[Groups(['read:classroom:basic'])]
  56.     private $description;
  57.     #[ORM\Column(type'integer')]
  58.     #[Groups(['read:classroom:basic'])]
  59.     private $capacity 1;
  60.     #[ORM\Column(type'string'length255enumTypeClassroomStatus::class)]
  61.     #[Groups(['read:classroom:basic'])]
  62.     private $status;
  63.     #[ORM\ManyToOne(targetEntitySection::class, inversedBy'classrooms')]
  64.     #[Groups(['read:classroom:basic'])]
  65.     private $section;
  66.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'classrooms')]
  67.     #[ORM\JoinColumn(nullablefalse)]
  68.     private $owner;
  69.     #[ORM\ManyToMany(targetEntityChild::class, inversedBy'classrooms')]
  70.     #[Groups(['read:classroom:basic'])]
  71.     private $children;
  72.     #[ORM\ManyToMany(targetEntityEmployee::class, inversedBy'classrooms')]
  73.     #[Groups(['read:classroom:basic'])]
  74.     private $teachers;
  75.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'classrooms')]
  76.     #[ORM\JoinColumn(nullablefalse)]
  77.     private $season;
  78.     public function __construct()
  79.     {
  80.         $this->children = new ArrayCollection();
  81.         $this->teachers = new ArrayCollection();
  82.     }
  83.     public function __toString()
  84.     {
  85.         return $this->name;
  86.     }
  87.     public function getId(): ?Ulid
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function getName(): ?string
  92.     {
  93.         return $this->name;
  94.     }
  95.     public function setName(string $name): self
  96.     {
  97.         $this->name $name;
  98.         return $this;
  99.     }
  100.     public function getDescription(): ?string
  101.     {
  102.         return $this->description;
  103.     }
  104.     public function setDescription(?string $description): self
  105.     {
  106.         $this->description $description;
  107.         return $this;
  108.     }
  109.     public function getCapacity(): ?int
  110.     {
  111.         return $this->capacity;
  112.     }
  113.     public function setCapacity(int $capacity): self
  114.     {
  115.         $this->capacity $capacity;
  116.         return $this;
  117.     }
  118.     #[Groups(['read:classroom:basic'])]
  119.     public function getAvailablePlaces(): ?int
  120.     {
  121.         return $this->capacity intval(count($this->getChildren()));
  122.     }
  123.     public function getStatus(): ?ClassroomStatus
  124.     {
  125.         return $this->status;
  126.     }
  127.     public function setStatus(ClassroomStatus $status): self
  128.     {
  129.         $this->status $status;
  130.         return $this;
  131.     }
  132.     public function getSection(): ?Section
  133.     {
  134.         return $this->section;
  135.     }
  136.     public function setSection(?Section $section): self
  137.     {
  138.         $this->section $section;
  139.         return $this;
  140.     }
  141.     public function getOwner(): ?Company
  142.     {
  143.         return $this->owner;
  144.     }
  145.     public function setOwner(?Company $owner): self
  146.     {
  147.         $this->owner $owner;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection<int, Child>
  152.      */
  153.     public function getChildren(): Collection
  154.     {
  155.         return $this->children;
  156.     }
  157.     public function addChild(Child $child): self
  158.     {
  159.         if (!$this->children->contains($child)) {
  160.             $this->children[] = $child;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeChild(Child $child): self
  165.     {
  166.         $this->children->removeElement($child);
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Employee>
  171.      */
  172.     public function getTeachers(): Collection
  173.     {
  174.         return $this->teachers;
  175.     }
  176.     public function addTeacher(Employee $teacher): self
  177.     {
  178.         if (!$this->teachers->contains($teacher)) {
  179.             $this->teachers[] = $teacher;
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeTeacher(Employee $teacher): self
  184.     {
  185.         $this->teachers->removeElement($teacher);
  186.         return $this;
  187.     }
  188.     public function getSeason(): ?Season
  189.     {
  190.         return $this->season;
  191.     }
  192.     public function setSeason(?Season $season): self
  193.     {
  194.         $this->season $season;
  195.         return $this;
  196.     }
  197. }