src/Entity/Blog/BlogCategories.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Blog;
  3. use App\Annotations\AppTranslationField;
  4. use App\Repository\Blog\BlogCategoriesRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  11. #[ORM\Entity(repositoryClassBlogCategoriesRepository::class)]
  12. class BlogCategories implements TranslatableInterface
  13. {
  14.     use TimestampableEntity;
  15.     use TranslatableTrait;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private ?int $id null;
  20.     #[AppTranslationField]
  21.     private ?string $title "";
  22.     #[ORM\Column(type'boolean')]
  23.     private bool $isActive true;
  24.     #[ORM\ManyToMany(targetEntityBlog::class, mappedBy'categories')]
  25.     private $blogs;
  26.     public function __construct()
  27.     {
  28.         $this->createdAt = new \DateTime();
  29.         $this->updatedAt = new \DateTime();
  30.         $this->blogs = new ArrayCollection();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function isIsActive(): ?bool
  37.     {
  38.         return $this->isActive;
  39.     }
  40.     public function setIsActive(bool $isActive): self
  41.     {
  42.         $this->isActive $isActive;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return string|null
  47.      */
  48.     public function getTitle(): ?string
  49.     {
  50.         return $this->title;
  51.     }
  52.     /**
  53.      * @param string|null $title
  54.      * @return BlogCategories
  55.      */
  56.     public function setTitle(?string $title): BlogCategories
  57.     {
  58.         $this->title $title;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, Blog>
  63.      */
  64.     public function getBlogs(): Collection
  65.     {
  66.         return $this->blogs;
  67.     }
  68.     public function addBlog(Blog $blog): self
  69.     {
  70.         if (!$this->blogs->contains($blog)) {
  71.             $this->blogs[] = $blog;
  72.             $blog->addCategory($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeBlog(Blog $blog): self
  77.     {
  78.         if ($this->blogs->removeElement($blog)) {
  79.             $blog->removeCategory($this);
  80.         }
  81.         return $this;
  82.     }
  83. }