82 lines
1.9 KiB
PHP
82 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use App\Enum\Status;
|
|
use App\Repository\PostRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: PostRepository::class)]
|
|
#[ApiResource]
|
|
class Post
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $title = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
|
|
private ?string $price = null;
|
|
|
|
#[ORM\Column(enumType: Status::class)]
|
|
private ?Status $status = null;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'posts')]
|
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
|
private ?User $author = null;
|
|
|
|
/**
|
|
* @var Collection<int, Tag>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'posts')]
|
|
#[ORM\JoinTable(name: 'post_tags')]
|
|
private Collection $tags;
|
|
|
|
/**
|
|
* @var Collection<int, Comment>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'post', cascade: ['persist'], orphanRemoval: true)]
|
|
#[ORM\OrderBy(['id' => 'DESC'])]
|
|
private Collection $comments;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'posts')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?Category $category = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->tags = new ArrayCollection();
|
|
$this->comments = new ArrayCollection();
|
|
}
|
|
|
|
public function getTitle(): ?string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(string $title): static
|
|
{
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCategory(): ?Category
|
|
{
|
|
return $this->category;
|
|
}
|
|
|
|
public function setCategory(Category $category): static
|
|
{
|
|
$this->category = $category;
|
|
|
|
return $this;
|
|
}
|
|
}
|