<?php
namespace App\Entity\Shop\Blog;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Blog\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
class Category extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\ManyToOne(inversedBy: 'categories')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Article::class, inversedBy: 'categories')]
private Collection $articles;
public function __construct()
{
parent::__construct();
$this->articles = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Article>
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): static
{
if (!$this->articles->contains($article)) {
$this->articles->add($article);
}
return $this;
}
public function removeArticle(Article $article): static
{
$this->articles->removeElement($article);
return $this;
}
}