<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\AdCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: AdCategoryRepository::class)]
#[ApiResource]
class AdCategory
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups([
'read:club:collection:getAds',
'read:ad'
])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Ad::class)]
private Collection $ads;
public function __construct()
{
$this->ads = new ArrayCollection();
}
public function __toString() {
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Ad>
*/
public function getAds(): Collection
{
return $this->ads;
}
public function addAd(Ad $ad): self
{
if (!$this->ads->contains($ad)) {
$this->ads->add($ad);
$ad->setCategory($this);
}
return $this;
}
public function removeAd(Ad $ad): self
{
if ($this->ads->removeElement($ad)) {
// set the owning side to null (unless already changed)
if ($ad->getCategory() === $this) {
$ad->setCategory(null);
}
}
return $this;
}
}