src/Entity/ArticleCategory.php line 14

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