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 $title;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=BlogArticle::class, mappedBy="category", orphanRemoval=true)
  24.      */
  25.     private $blogArticles;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $slug;
  30.     public function __construct()
  31.     {
  32.         $this->blogArticles = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getTitle(): ?string
  39.     {
  40.         return $this->title;
  41.     }
  42.     public function setTitle(string $title): self
  43.     {
  44.         $this->title $title;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection<int, BlogArticle>
  49.      */
  50.     public function getBlogArticles(): Collection
  51.     {
  52.         return $this->blogArticles;
  53.     }
  54.     public function addBlogArticle(BlogArticle $blogArticle): self
  55.     {
  56.         if (!$this->blogArticles->contains($blogArticle)) {
  57.             $this->blogArticles[] = $blogArticle;
  58.             $blogArticle->setCategory($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeBlogArticle(BlogArticle $blogArticle): self
  63.     {
  64.         if ($this->blogArticles->removeElement($blogArticle)) {
  65.             // set the owning side to null (unless already changed)
  66.             if ($blogArticle->getCategory() === $this) {
  67.                 $blogArticle->setCategory(null);
  68.             }
  69.         }
  70.         return $this;
  71.     }
  72.     public function __toString()
  73.     {
  74.         return $this->getTitle();
  75.     }
  76.     public function getSlug(): ?string
  77.     {
  78.         return $this->slug;
  79.     }
  80.     public function setSlug(string $slug): self
  81.     {
  82.         $this->slug $slug;
  83.         return $this;
  84.     }
  85. }