<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
*/
class Category
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $name;
/**
* @ORM\Column(type="text", length=255,nullable=true)
*/
private $description;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Journal", mappedBy="categories",cascade={"persist"})
*/
private $journals;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="categories",cascade={"persist"})
*/
private $users;
/**
* @ORM\ManyToMany(targetEntity=Post::class, mappedBy="categories")
*/
private $posts;
/**
* @ORM\ManyToMany(targetEntity=Tag::class,mappedBy="category")
*/
private $tags;
public function __construct()
{
$this->journals = new ArrayCollection();
$this->followers = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->tags = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getJournals()
{
return $this->journals;
}
public function addJournal(?Journal $journal): self
{
if (!$this->journals->contains($journal)) {
$this->journals[] = $journal;
$journal->addCategory($this);
}
return $this;
}
public function removeJournal(Journal $journal): self
{
if ($this->journals->contains($journal)) {
$this->journals->removeElement($journal);
$journal->removeCategory($this);
}
return $this;
}
public function getUsers()
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addCategory($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
$user->removeCategory($this);
}
return $this;
}
public function __toString()
{
return $this->getName();
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->addCategory($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
$post->removeCategory($this);
}
return $this;
}
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
$tag->addCategory($this);
}
return $this;
}
public function removeTag(Tag $tag): self
{
if ($this->tags->removeElement($tag)) {
$tag->removeCategory($this);
}
return $this;
}
}