<?php
namespace App\Entity;
use App\Entity\Traits\Timestampable;
use App\Repository\PunishCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
#[ORM\HasLifecycleCallbacks]
#[ORM\Entity(repositoryClass: PunishCategoryRepository::class)]
class PunishCategory
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['getPunish'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['getPunish'])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Punish::class)]
private Collection $punish;
#[ORM\ManyToOne(inversedBy: 'punishCategories', cascade: ["persist"])]
private ?User $author = null;
#[ORM\ManyToOne(inversedBy: 'punishCategories', cascade: ["persist"])]
private ?School $school = null;
public function __construct()
{
$this->punish = new ArrayCollection();
}
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Punish>
*/
public function getPunish(): Collection
{
return $this->punish;
}
public function addPunish(Punish $punish): static
{
if (!$this->punish->contains($punish)) {
$this->punish->add($punish);
$punish->setCategory($this);
}
return $this;
}
public function removePunish(Punish $punish): static
{
if ($this->punish->removeElement($punish)) {
// set the owning side to null (unless already changed)
if ($punish->getCategory() === $this) {
$punish->setCategory(null);
}
}
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function getSchool(): ?School
{
return $this->school;
}
public function setSchool(?School $school): static
{
$this->school = $school;
return $this;
}
}