src/Entity/Category.php line 12

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. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
  8.  */
  9. class Category
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=255, unique=true)
  19.      */
  20.     private $name;
  21.     /**
  22.      * @ORM\Column(type="text", length=255,nullable=true)
  23.      */
  24.     private $description;
  25.     /**
  26.      * @ORM\ManyToMany(targetEntity="App\Entity\Journal", mappedBy="categories",cascade={"persist"})
  27.      */
  28.     private $journals;
  29.     /**
  30.      * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="categories",cascade={"persist"})
  31.      */
  32.     private $users;
  33.     /**
  34.      * @ORM\ManyToMany(targetEntity=Post::class, mappedBy="categories")
  35.      */
  36.     private $posts;
  37.     /**
  38.      * @ORM\ManyToMany(targetEntity=Tag::class,mappedBy="category")
  39.      */
  40.     private $tags;
  41.     public function __construct()
  42.     {
  43.         $this->journals = new ArrayCollection();
  44.         $this->followers = new ArrayCollection();
  45.         $this->posts = new ArrayCollection();
  46.         $this->tags = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getDescription(): ?string
  62.     {
  63.         return $this->description;
  64.     }
  65.     public function setDescription(string $description): self
  66.     {
  67.         $this->description $description;
  68.         return $this;
  69.     }
  70.     public function getJournals()
  71.     {
  72.         return $this->journals;
  73.     }
  74.     public function addJournal(?Journal $journal): self
  75.     {
  76.         if (!$this->journals->contains($journal)) {
  77.             $this->journals[] = $journal;
  78.             $journal->addCategory($this);
  79.         }
  80.         return $this;
  81.     }
  82.     public function removeJournal(Journal $journal): self
  83.     {
  84.         if ($this->journals->contains($journal)) {
  85.             $this->journals->removeElement($journal);
  86.             $journal->removeCategory($this);
  87.         }
  88.         return $this;
  89.     }
  90.     public function getUsers()
  91.     {
  92.         return $this->users;
  93.     }
  94.     public function addUser(User $user): self
  95.     {
  96.         if (!$this->users->contains($user)) {
  97.             $this->users[] = $user;
  98.             $user->addCategory($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeUser(User $user): self
  103.     {
  104.         if ($this->users->contains($user)) {
  105.             $this->users->removeElement($user);
  106.             $user->removeCategory($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function __toString()
  111.     {
  112.         return $this->getName();
  113.     }
  114.     /**
  115.      * @return Collection<int, Post>
  116.      */
  117.     public function getPosts(): Collection
  118.     {
  119.         return $this->posts;
  120.     }
  121.     public function addPost(Post $post): self
  122.     {
  123.         if (!$this->posts->contains($post)) {
  124.             $this->posts[] = $post;
  125.             $post->addCategory($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removePost(Post $post): self
  130.     {
  131.         if ($this->posts->removeElement($post)) {
  132.             $post->removeCategory($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function getTags(): Collection
  137.     {
  138.         return $this->tags;
  139.     }
  140.     public function addTag(Tag $tag): self
  141.     {
  142.         if (!$this->tags->contains($tag)) {
  143.             $this->tags[] = $tag;
  144.             $tag->addCategory($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeTag(Tag $tag): self
  149.     {
  150.         if ($this->tags->removeElement($tag)) {
  151.             $tag->removeCategory($this);
  152.         }
  153.         return $this;
  154.     }
  155. }