src/Entity/Category.php line 12
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 64)]
#[Groups("shop_browse")]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $picture = null;
// mappedBy
#[ORM\ManyToMany(targetEntity: Shop::class, mappedBy: 'categories', cascade: ["persist"])]
//#[Groups("shop_browse")]
private Collection $shops;
#[ORM\Column(length: 64)]
private ?string $subtitle = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: SubCategory::class)]
private Collection $subcategories;
public function __construct()
{
$this->shops = new ArrayCollection();
$this->subcategories = new ArrayCollection();
}
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;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
/**
* @return Collection<int, Shop>
*/
public function getShops(): Collection
{
return $this->shops;
}
public function addShop(Shop $shop): self
{
if (!$this->shops->contains($shop)) {
$this->shops->add($shop);
$shop->addCategory($this);
}
return $this;
}
public function removeShop(Shop $shop): self
{
if ($this->shops->removeElement($shop)) {
$shop->removeCategory($this);
}
return $this;
}
public function getSubtitle(): ?string
{
return $this->subtitle;
}
public function setSubtitle(string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
/**
* @return Collection<int, SubCategory>
*/
public function getSubcategories(): Collection
{
return $this->subcategories;
}
public function addSubcategory(SubCategory $subcategory): self
{
if (!$this->subcategories->contains($subcategory)) {
$this->subcategories->add($subcategory);
$subcategory->setCategory($this);
}
return $this;
}
public function removeSubcategory(SubCategory $subcategory): self
{
if ($this->subcategories->removeElement($subcategory)) {
// set the owning side to null (unless already changed)
if ($subcategory->getCategory() === $this) {
$subcategory->setCategory(null);
}
}
return $this;
}
public function __toString()
{
return $this->name;
}
}