src/Entity/BlogCategory.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=BlogCategoryRepository::class)
  9.  */
  10. class BlogCategory
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=Article::class, mappedBy="blogCategory")
  24.      */
  25.     private $articles;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $categorySlug;
  30.     public function __construct()
  31.     {
  32.         $this->articles = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getName(): ?string
  39.     {
  40.         return $this->name;
  41.     }
  42.     public function setName(string $name): self
  43.     {
  44.         $this->name $name;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection|Article[]
  49.      */
  50.     public function getArticles(): Collection
  51.     {
  52.         return $this->articles;
  53.     }
  54.     public function addArticle(Article $article): self
  55.     {
  56.         if (!$this->articles->contains($article)) {
  57.             $this->articles[] = $article;
  58.             $article->setBlogCategory($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeArticle(Article $article): self
  63.     {
  64.         if ($this->articles->contains($article)) {
  65.             $this->articles->removeElement($article);
  66.             // set the owning side to null (unless already changed)
  67.             if ($article->getBlogCategory() === $this) {
  68.                 $article->setBlogCategory(null);
  69.             }
  70.         }
  71.         return $this;
  72.     }
  73.     public function getCategorySlug(): ?string
  74.     {
  75.         return $this->categorySlug;
  76.     }
  77.     public function setCategorySlug(?string $categorySlug): self
  78.     {
  79.         $this->categorySlug $categorySlug;
  80.         return $this;
  81.     }
  82. }