<?php namespace App\Entity; use App\Repository\PostRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=PostRepository::class) */ class Post { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\Column(type="text") */ private $description; /** * @ORM\Column(type="text") */ private $content; /** * @ORM\Column(type="string", length=255, unique=true) */ private $slug; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="datetime") */ private $updatedAt; /** * @ORM\Column(type="datetime") */ private $publishedAt; /** * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="post", orphanRemoval=true) */ private $comments; /** * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="posts") */ private $categories; public function __construct() { $this->comments = new ArrayCollection(); $this->categories = 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 getDescription(): ?string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function getContent(): ?string { return $this->content; } public function setContent(string $content): self { $this->content = $content; return $this; } public function getSlug(): ?string { return $this->slug; } public function setSlug(string $slug): self { $this->slug = $slug; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(\DateTimeInterface $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } public function getPublishedAt(): ?\DateTimeInterface { return $this->publishedAt; } public function setPublishedAt(\DateTimeInterface $publishedAt): self { $this->publishedAt = $publishedAt; 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; } /** * @return Collection|Category[] */ public function getCategories(): Collection { return $this->categories; } public function addCategory(Category $category): self { if (!$this->categories->contains($category)) { $this->categories[] = $category; $category->addPost($this); } return $this; } public function removeCategory(Category $category): self { if ($this->categories->removeElement($category)) { $category->removePost($this); } return $this; } }