<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\BlogCategorieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
#[ORM\Entity(repositoryClass: BlogCategorieRepository::class)]
class BlogCategorie implements TranslatableInterface
{
use TranslatableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(nullable: true)]
private ?bool $isActive = null;
#[ORM\ManyToMany(targetEntity: BlogArticle::class, mappedBy: 'categories')]
private Collection $blogArticles;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'blogCategories')]
private ?self $categoryParent = null;
#[ORM\OneToMany(mappedBy: 'categoryParent', targetEntity: self::class)]
private Collection $blogCategories;
public function __construct()
{
$this->blogArticles = new ArrayCollection();
$this->blogCategories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->translate()->getNom();
}
public function isIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): static
{
$this->isActive = $isActive;
return $this;
}
/**
* @return Collection<int, BlogArticle>
*/
public function getBlogArticles(): Collection
{
return $this->blogArticles;
}
public function addBlogArticle(BlogArticle $blogArticle): static
{
if (!$this->blogArticles->contains($blogArticle)) {
$this->blogArticles->add($blogArticle);
$blogArticle->addCategory($this);
}
return $this;
}
public function removeBlogArticle(BlogArticle $blogArticle): static
{
if ($this->blogArticles->removeElement($blogArticle)) {
$blogArticle->removeCategory($this);
}
return $this;
}
public function getCategoryParent(): ?self
{
return $this->categoryParent;
}
public function setCategoryParent(?self $categoryParent): static
{
$this->categoryParent = $categoryParent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getBlogCategories(): Collection
{
return $this->blogCategories;
}
public function addBlogCategory(self $blogCategory): static
{
if (!$this->blogCategories->contains($blogCategory)) {
$this->blogCategories->add($blogCategory);
$blogCategory->setCategoryParent($this);
}
return $this;
}
public function removeBlogCategory(self $blogCategory): static
{
if ($this->blogCategories->removeElement($blogCategory)) {
// set the owning side to null (unless already changed)
if ($blogCategory->getCategoryParent() === $this) {
$blogCategory->setCategoryParent(null);
}
}
return $this;
}
}