You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
herbarium/src/Entity/Comment.php

120 lines
2.6 KiB

<?php
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\CommentRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CommentRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(operations: [new GetCollection()])]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['author', 'related_post'])]
class Comment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'comments')]
#[ORM\JoinColumn(nullable: false)]
private ?User $author = null;
#[ORM\ManyToOne(inversedBy: 'comments')]
private ?Post $related_post = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
#[ORM\Column]
private ?\DateTimeImmutable $edited_at = null;
#[ORM\Column(length: 255)]
private ?string $content = null;
public function getId(): ?int
{
return $this->id;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function getRelatedPost(): ?Post
{
return $this->related_post;
}
public function setRelatedPost(?Post $related_post): static
{
$this->related_post = $related_post;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function getEditedAt(): ?\DateTimeImmutable
{
return $this->edited_at;
}
public function setEditedAt(\DateTimeImmutable $edited_at): static
{
$this->edited_at = $edited_at;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): static
{
$this->content = $content;
return $this;
}
#[ORM\PrePersist]
public function setCreatedAtDate(): void
{
if ($this->created_at === null) {
$this->created_at = new \DateTimeImmutable();
$this->edited_at = $this->created_at;
}
}
#[ORM\PreUpdate]
public function setEditedAtDate(): void
{
$this->edited_at = new \DateTimeImmutable();
}
}