src/Model/Page/Entity/Page/Page.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model\Page\Entity\Page;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity]
  6. #[ORM\Table(name'page_page')]
  7. class Page
  8. {
  9.     public const STATUS_ARCHIVED 'archived';
  10.     public const STATUS_ACTIVE 'active';
  11.     #[ORM\Column(type'page_page_id')]
  12.     #[ORM\Id]
  13.     private Id $id;
  14.     #[ORM\Column(type'string')]
  15.     private string $name;
  16.     #[ORM\Column(type'string'nullabletrue)]
  17.     private ?string $name_en;
  18.     #[ORM\Column(type'string'uniquetrue)]
  19.     private string $slug;
  20.     #[ORM\Column(type'text'nullabletrue)]
  21.     private ?string $content;
  22.     #[ORM\Column(type'text'nullabletrue)]
  23.     private ?string $content_en;
  24.     #[ORM\Column(type'string'length16)]
  25.     private string $status;
  26.     #[ORM\Column(type'datetime_immutable')]
  27.     private \DateTimeImmutable $date;
  28.     #[ORM\Embedded(class: 'App\Model\Page\Entity\Page\SeoMeta'columnPrefix'seo_')]
  29.     private $seoMeta;
  30.     public function __construct(
  31.         Id                 $id,
  32.         string             $name,
  33.         string             $slug,
  34.         string             $content,
  35.         \DateTimeImmutable $date,
  36.         ?SeoMeta           $seoMeta
  37.     )
  38.     {
  39.         $this->id $id;
  40.         $this->name $name;
  41.         $this->slug $slug;
  42.         $this->content $content;
  43.         $this->date $date;
  44.         $this->status self::STATUS_ARCHIVED;
  45.         $this->seoMeta $seoMeta;
  46.     }
  47.     public function getId(): Id
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getName(): string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function getSlug(): string
  56.     {
  57.         return $this->slug;
  58.     }
  59.     public function getContent(): string
  60.     {
  61.         return $this->content;
  62.     }
  63.     public function getStatus(): string
  64.     {
  65.         return $this->status;
  66.     }
  67.     public function getDate(): \DateTimeImmutable
  68.     {
  69.         return $this->date;
  70.     }
  71.     public function setDate(\DateTimeImmutable $date): void
  72.     {
  73.         $this->date $date;
  74.     }
  75.     /**
  76.      * @return ?SeoMeta[]
  77.      */
  78.     public function getMeta(): ?SeoMeta
  79.     {
  80.         return $this->seoMeta;
  81.     }
  82.     public function archive(): void
  83.     {
  84.         if ($this->isArchive()) {
  85.             throw new \DomainException('Page is already archive.');
  86.         }
  87.         $this->status self::STATUS_ARCHIVED;
  88.     }
  89.     public function active()
  90.     {
  91.         if ($this->isActive()) {
  92.             throw new \DomainException('Page is already active.');
  93.         }
  94.         $this->status self::STATUS_ACTIVE;
  95.     }
  96.     public function isActive(): bool
  97.     {
  98.         return $this->status === self::STATUS_ACTIVE;
  99.     }
  100.     public function isArchive(): bool
  101.     {
  102.         return $this->status === self::STATUS_ARCHIVED;
  103.     }
  104.     public function edit(
  105.         string  $name,
  106.         string  $slug,
  107.         string  $content,
  108.         SeoMeta $seoMeta
  109.     ): void
  110.     {
  111.         $this->name $name;
  112.         $this->slug $slug;
  113.         $this->content $content;
  114.         $this->seoMeta->editSeoMeta(
  115.             $seoMeta->getMetaTitle(),
  116.             $seoMeta->getMetaDescription(),
  117.             $seoMeta->getMetaKeywords()
  118.         );
  119.     }
  120.     /**
  121.      * @return string|null
  122.      */
  123.     public function getNameEn(): ?string
  124.     {
  125.         return $this->name_en;
  126.     }
  127.     /**
  128.      * @param string|null $name_en
  129.      */
  130.     public function setNameEn(?string $name_en): void
  131.     {
  132.         $this->name_en $name_en;
  133.     }
  134.     /**
  135.      * @return string|null
  136.      */
  137.     public function getContentEn(): ?string
  138.     {
  139.         return $this->content_en;
  140.     }
  141.     /**
  142.      * @param string|null $content_en
  143.      */
  144.     public function setContentEn(?string $content_en): void
  145.     {
  146.         $this->content_en $content_en;
  147.     }
  148. }