src/Entity/BlogCategorie.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\BlogCategorieRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. #[ORM\Entity(repositoryClassBlogCategorieRepository::class)]
  11. class BlogCategorie implements TranslatableInterface
  12. {
  13.     use TranslatableTrait;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(nullabletrue)]
  19.     private ?bool $isActive null;
  20.     #[ORM\ManyToMany(targetEntityBlogArticle::class, mappedBy'categories')]
  21.     private Collection $blogArticles;
  22.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'blogCategories')]
  23.     private ?self $categoryParent null;
  24.     #[ORM\OneToMany(mappedBy'categoryParent'targetEntityself::class)]
  25.     private Collection $blogCategories;
  26.     public function __construct()
  27.     {
  28.         $this->blogArticles = new ArrayCollection();
  29.         $this->blogCategories = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getNom(): ?string
  36.     {
  37.         return $this->translate()->getNom();
  38.     }
  39.     public function isIsActive(): ?bool
  40.     {
  41.         return $this->isActive;
  42.     }
  43.     public function setIsActive(?bool $isActive): static
  44.     {
  45.         $this->isActive $isActive;
  46.         return $this;
  47.     }
  48.     /**
  49.      * @return Collection<int, BlogArticle>
  50.      */
  51.     public function getBlogArticles(): Collection
  52.     {
  53.         return $this->blogArticles;
  54.     }
  55.     public function addBlogArticle(BlogArticle $blogArticle): static
  56.     {
  57.         if (!$this->blogArticles->contains($blogArticle)) {
  58.             $this->blogArticles->add($blogArticle);
  59.             $blogArticle->addCategory($this);
  60.         }
  61.         return $this;
  62.     }
  63.     public function removeBlogArticle(BlogArticle $blogArticle): static
  64.     {
  65.         if ($this->blogArticles->removeElement($blogArticle)) {
  66.             $blogArticle->removeCategory($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function getCategoryParent(): ?self
  71.     {
  72.         return $this->categoryParent;
  73.     }
  74.     public function setCategoryParent(?self $categoryParent): static
  75.     {
  76.         $this->categoryParent $categoryParent;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return Collection<int, self>
  81.      */
  82.     public function getBlogCategories(): Collection
  83.     {
  84.         return $this->blogCategories;
  85.     }
  86.     public function addBlogCategory(self $blogCategory): static
  87.     {
  88.         if (!$this->blogCategories->contains($blogCategory)) {
  89.             $this->blogCategories->add($blogCategory);
  90.             $blogCategory->setCategoryParent($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeBlogCategory(self $blogCategory): static
  95.     {
  96.         if ($this->blogCategories->removeElement($blogCategory)) {
  97.             // set the owning side to null (unless already changed)
  98.             if ($blogCategory->getCategoryParent() === $this) {
  99.                 $blogCategory->setCategoryParent(null);
  100.             }
  101.         }
  102.         return $this;
  103.     }
  104. }