<?php
namespace App\Entity;
use App\Entity\SuperClass\BaseEntity;
use App\Repository\PostRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=PostRepository::class)
*/
class Post extends BaseEntity
{
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="json")
*/
private $content = [];
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="text")
*/
private $metadata;
/**
* @ORM\Column(type="array")
*/
private $tags = [];
/**
* @ORM\ManyToMany(targetEntity=Category::class, inversedBy="posts")
*/
private $categories;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="posts")
* @ORM\JoinColumn(nullable=false)
*/
private $created_by;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
private $published_at;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="post")
*/
private $comments;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->comments = new ArrayCollection();
}
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 getContent(): ?array
{
return $this->content;
}
public function setContent(array $content): self
{
$this->content = $content;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function getMetadata(): ?string
{
return $this->metadata;
}
public function setMetadata(string $metadata): self
{
$this->metadata = $metadata;
return $this;
}
public function getTags(): ?array
{
return $this->tags;
}
public function setTags(array $tags): self
{
$this->tags = $tags;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
}
return $this;
}
public function removeCategory(Category $category): self
{
$this->categories->removeElement($category);
return $this;
}
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getPublishedAt(): ?\DateTimeInterface
{
return $this->published_at;
}
public function setPublishedAt(?\DateTimeInterface $published_at): self
{
$this->published_at = $published_at;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setPost($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getPost() === $this) {
$comment->setPost(null);
}
}
return $this;
}
}