2021-03-16 16:46:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity\Blog;
|
|
|
|
|
2021-03-20 13:41:15 +01:00
|
|
|
use App\Core\Doctrine\Timestampable;
|
2021-03-22 12:43:13 +01:00
|
|
|
use App\Core\Entity\EntityInterface;
|
2021-03-16 16:46:39 +01:00
|
|
|
use App\Repository\Blog\CategoryRepository;
|
2021-03-17 12:44:02 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2021-03-16 16:46:39 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Entity(repositoryClass=CategoryRepository::class)
|
2021-03-17 15:57:07 +01:00
|
|
|
* @ORM\HasLifecycleCallbacks
|
2021-03-16 16:46:39 +01:00
|
|
|
*/
|
2021-03-17 12:44:02 +01:00
|
|
|
class Category implements EntityInterface
|
2021-03-16 16:46:39 +01:00
|
|
|
{
|
2021-03-17 20:42:36 +01:00
|
|
|
use Timestampable;
|
|
|
|
|
2021-03-16 16:46:39 +01:00
|
|
|
/**
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=255)
|
|
|
|
*/
|
|
|
|
private $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
|
|
|
*/
|
|
|
|
private $subTitle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="text", nullable=true)
|
|
|
|
*/
|
|
|
|
private $description;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="string", length=255, nullable=true)
|
|
|
|
*/
|
|
|
|
private $slug;
|
|
|
|
|
2021-03-17 12:44:02 +01:00
|
|
|
/**
|
|
|
|
* @ORM\ManyToMany(targetEntity=Post::class, mappedBy="categories")
|
|
|
|
*/
|
|
|
|
private $posts;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->posts = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:46:39 +01:00
|
|
|
public function getId(): ?int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle(): ?string
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTitle(string $title): self
|
|
|
|
{
|
|
|
|
$this->title = $title;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSubTitle(): ?string
|
|
|
|
{
|
|
|
|
return $this->subTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubTitle(?string $subTitle): self
|
|
|
|
{
|
|
|
|
$this->subTitle = $subTitle;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription(): ?string
|
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDescription(string $description): self
|
|
|
|
{
|
|
|
|
$this->description = $description;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSlug(): ?string
|
|
|
|
{
|
|
|
|
return $this->slug;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSlug(?string $slug): self
|
|
|
|
{
|
|
|
|
$this->slug = $slug;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2021-03-17 12:44:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|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;
|
|
|
|
}
|
2021-03-16 16:46:39 +01:00
|
|
|
}
|