src/Entity/Classroom.php line 47
<?php
namespace App\Entity;
use App\Entity\enums\ClassroomStatus;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ClassroomRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ClassroomRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
itemOperations: [
'get' => [
'normalization_context' => [
'groups' => [
'read:classroom:basic',
'read:employee:basic',
'read:child:basic',
'read:section:basic',
]
]
],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => [
'read:classroom:basic',
'read:section:basic',
'read:child:basic'
]
]
],
],
)]
class Classroom
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:classroom:basic'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:classroom:basic'])]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:classroom:basic'])]
private $description;
#[ORM\Column(type: 'integer')]
#[Groups(['read:classroom:basic'])]
private $capacity = 1;
#[ORM\Column(type: 'string', length: 255, enumType: ClassroomStatus::class)]
#[Groups(['read:classroom:basic'])]
private $status;
#[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'classrooms')]
#[Groups(['read:classroom:basic'])]
private $section;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'classrooms')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\ManyToMany(targetEntity: Child::class, inversedBy: 'classrooms')]
#[Groups(['read:classroom:basic'])]
private $children;
#[ORM\ManyToMany(targetEntity: Employee::class, inversedBy: 'classrooms')]
#[Groups(['read:classroom:basic'])]
private $teachers;
#[ORM\ManyToOne(targetEntity: Season::class, inversedBy: 'classrooms')]
#[ORM\JoinColumn(nullable: false)]
private $season;
public function __construct()
{
$this->children = new ArrayCollection();
$this->teachers = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCapacity(): ?int
{
return $this->capacity;
}
public function setCapacity(int $capacity): self
{
$this->capacity = $capacity;
return $this;
}
#[Groups(['read:classroom:basic'])]
public function getAvailablePlaces(): ?int
{
return $this->capacity - intval(count($this->getChildren()));
}
public function getStatus(): ?ClassroomStatus
{
return $this->status;
}
public function setStatus(ClassroomStatus $status): self
{
$this->status = $status;
return $this;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Child>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Child $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
}
return $this;
}
public function removeChild(Child $child): self
{
$this->children->removeElement($child);
return $this;
}
/**
* @return Collection<int, Employee>
*/
public function getTeachers(): Collection
{
return $this->teachers;
}
public function addTeacher(Employee $teacher): self
{
if (!$this->teachers->contains($teacher)) {
$this->teachers[] = $teacher;
}
return $this;
}
public function removeTeacher(Employee $teacher): self
{
$this->teachers->removeElement($teacher);
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
}