<?php
declare(strict_types=1);
namespace App\Model\Page\Entity\Page;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'page_page')]
class Page
{
public const STATUS_ARCHIVED = 'archived';
public const STATUS_ACTIVE = 'active';
#[ORM\Column(type: 'page_page_id')]
#[ORM\Id]
private Id $id;
#[ORM\Column(type: 'string')]
private string $name;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $name_en;
#[ORM\Column(type: 'string', unique: true)]
private string $slug;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $content;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $content_en;
#[ORM\Column(type: 'string', length: 16)]
private string $status;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $date;
#[ORM\Embedded(class: 'App\Model\Page\Entity\Page\SeoMeta', columnPrefix: 'seo_')]
private $seoMeta;
public function __construct(
Id $id,
string $name,
string $slug,
string $content,
\DateTimeImmutable $date,
?SeoMeta $seoMeta
)
{
$this->id = $id;
$this->name = $name;
$this->slug = $slug;
$this->content = $content;
$this->date = $date;
$this->status = self::STATUS_ARCHIVED;
$this->seoMeta = $seoMeta;
}
public function getId(): Id
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function getSlug(): string
{
return $this->slug;
}
public function getContent(): string
{
return $this->content;
}
public function getStatus(): string
{
return $this->status;
}
public function getDate(): \DateTimeImmutable
{
return $this->date;
}
public function setDate(\DateTimeImmutable $date): void
{
$this->date = $date;
}
/**
* @return ?SeoMeta[]
*/
public function getMeta(): ?SeoMeta
{
return $this->seoMeta;
}
public function archive(): void
{
if ($this->isArchive()) {
throw new \DomainException('Page is already archive.');
}
$this->status = self::STATUS_ARCHIVED;
}
public function active()
{
if ($this->isActive()) {
throw new \DomainException('Page is already active.');
}
$this->status = self::STATUS_ACTIVE;
}
public function isActive(): bool
{
return $this->status === self::STATUS_ACTIVE;
}
public function isArchive(): bool
{
return $this->status === self::STATUS_ARCHIVED;
}
public function edit(
string $name,
string $slug,
string $content,
SeoMeta $seoMeta
): void
{
$this->name = $name;
$this->slug = $slug;
$this->content = $content;
$this->seoMeta->editSeoMeta(
$seoMeta->getMetaTitle(),
$seoMeta->getMetaDescription(),
$seoMeta->getMetaKeywords()
);
}
/**
* @return string|null
*/
public function getNameEn(): ?string
{
return $this->name_en;
}
/**
* @param string|null $name_en
*/
public function setNameEn(?string $name_en): void
{
$this->name_en = $name_en;
}
/**
* @return string|null
*/
public function getContentEn(): ?string
{
return $this->content_en;
}
/**
* @param string|null $content_en
*/
public function setContentEn(?string $content_en): void
{
$this->content_en = $content_en;
}
}