src/Entity/AdCategory.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\AdCategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassAdCategoryRepository::class)]
  10. #[ApiResource]
  11. class AdCategory
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length255)]
  18.     #[Groups([
  19.         'read:club:collection:getAds',
  20.         'read:ad'
  21.     ])]
  22.     private ?string $name null;
  23.     #[ORM\OneToMany(mappedBy'category'targetEntityAd::class)]
  24.     private Collection $ads;
  25.     public function __construct()
  26.     {
  27.         $this->ads = new ArrayCollection();
  28.     }
  29.     public function __toString() {
  30.         return $this->name;
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getName(): ?string
  37.     {
  38.         return $this->name;
  39.     }
  40.     public function setName(string $name): self
  41.     {
  42.         $this->name $name;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection<int, Ad>
  47.      */
  48.     public function getAds(): Collection
  49.     {
  50.         return $this->ads;
  51.     }
  52.     public function addAd(Ad $ad): self
  53.     {
  54.         if (!$this->ads->contains($ad)) {
  55.             $this->ads->add($ad);
  56.             $ad->setCategory($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeAd(Ad $ad): self
  61.     {
  62.         if ($this->ads->removeElement($ad)) {
  63.             // set the owning side to null (unless already changed)
  64.             if ($ad->getCategory() === $this) {
  65.                 $ad->setCategory(null);
  66.             }
  67.         }
  68.         return $this;
  69.     }
  70. }