src/Entity/Section.php line 23
<?php
namespace App\Entity;
use App\Entity\enums\AgeRange;
use App\Entity\Classroom;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\SectionRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: SectionRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
)]
class Section
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:section:basic', 'read:section:export'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:section:basic', 'read:section:export'])]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:section:basic'])]
private $description;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:section:basic', 'read:section:export'])]
private $age_range;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'sections')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\OneToMany(mappedBy: 'section', targetEntity: Classroom::class)]
private $classrooms;
#[ORM\OneToMany(mappedBy: 'section', targetEntity: Child::class)]
private $children;
#[ORM\OneToMany(mappedBy: 'section', targetEntity: Prechild::class)]
private $prechildren;
public function __construct()
{
$this->classrooms = new ArrayCollection();
$this->children = new ArrayCollection();
$this->prechildren = 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 getAgeRange(): ?string
{
return $this->age_range;
}
public function setAgeRange(?string $age_range): self
{
$this->age_range = $age_range;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Classroom>
*/
public function getClassrooms(): Collection
{
return $this->classrooms;
}
public function addClassroom(Classroom $classroom): self
{
if (!$this->classrooms->contains($classroom)) {
$this->classrooms[] = $classroom;
$classroom->setSection($this);
}
return $this;
}
public function removeClassroom(Classroom $classroom): self
{
if ($this->classrooms->removeElement($classroom)) {
// set the owning side to null (unless already changed)
if ($classroom->getSection() === $this) {
$classroom->setSection(null);
}
}
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;
$child->setSection($this);
}
return $this;
}
public function removeChild(Child $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getSection() === $this) {
$child->setSection(null);
}
}
return $this;
}
/**
* @return Collection<int, Prechild>
*/
public function getPrechildren(): Collection
{
return $this->prechildren;
}
public function addPrechild(Prechild $prechild): self
{
if (!$this->prechildren->contains($prechild)) {
$this->prechildren[] = $prechild;
$prechild->setSection($this);
}
return $this;
}
public function removePrechild(Prechild $prechild): self
{
if ($this->prechildren->removeElement($prechild)) {
// set the owning side to null (unless already changed)
if ($prechild->getSection() === $this) {
$prechild->setSection(null);
}
}
return $this;
}
}