src/Entity/ArticleType.php line 16

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