added Comment entity

This commit is contained in:
2021-05-30 18:24:32 +02:00
parent 32e8e11882
commit 55dca7b8ce
7 changed files with 359 additions and 11 deletions

View File

@@ -70,9 +70,15 @@ class Blog
*/
private $editReason;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="blog")
*/
private $comments;
public function __construct()
{
$this->section = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getId(): ?int
@@ -211,4 +217,34 @@ class Blog
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->setBlog($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->getBlog() === $this) {
$comment->setBlog(null);
}
}
return $this;
}
}

162
src/Entity/Comment.php Normal file
View File

@@ -0,0 +1,162 @@
<?php
namespace App\Entity;
use App\Repository\CommentRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CommentRepository::class)
*/
class Comment
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Blog::class, inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $blog;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $author;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $editedBy;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $editReason;
public function getId(): ?int
{
return $this->id;
}
public function getBlog(): ?Blog
{
return $this->blog;
}
public function setBlog(?Blog $blog): self
{
$this->blog = $blog;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): self
{
$this->author = $author;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getEditedAt(): ?\DateTimeInterface
{
return $this->editedAt;
}
public function setEditedAt(?\DateTimeInterface $editedAt): self
{
$this->editedAt = $editedAt;
return $this;
}
public function getEditedBy(): ?User
{
return $this->editedBy;
}
public function setEditedBy(?User $editedBy): self
{
$this->editedBy = $editedBy;
return $this;
}
public function getEditReason(): ?string
{
return $this->editReason;
}
public function setEditReason(?string $editReason): self
{
$this->editReason = $editReason;
return $this;
}
}

View File

@@ -66,9 +66,15 @@ class User implements UserInterface
*/
private $blogs;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="author")
*/
private $comments;
public function __construct()
{
$this->blogs = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getId(): ?int
@@ -236,4 +242,34 @@ class User implements UserInterface
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->setAuthor($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->getAuthor() === $this) {
$comment->setAuthor(null);
}
}
return $this;
}
}