oms-Editor/Models/EditorDocHistory.php
Dennis Eichhorn a764d818fb
Some checks failed
Image optimization / general_image_workflow (push) Has been cancelled
CI / general_module_workflow_php (push) Has been cancelled
CI / general_module_workflow_js (push) Has been cancelled
fix version and bugs
2024-05-21 00:09:09 +02:00

158 lines
2.7 KiB
PHP
Executable File

<?php
/**
* Jingga
*
* PHP Version 8.2
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.2
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/**
* News article class.
*
* @package Modules\Editor\Models
* @license OMS License 2.2
* @link https://jingga.app
* @since 1.0.0
*/
class EditorDocHistory implements \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
public int $id = 0;
/**
* Doc ID.
*
* @var int
* @since 1.0.0
*/
public int $doc = 0;
/**
* Version.
*
* @var string
* @since 1.0.0
*/
public string $version = '';
/**
* Title.
*
* @var string
* @since 1.0.0
*/
public string $title = '';
/**
* Content.
*
* @var string
* @since 1.0.0
*/
public string $content = '';
/**
* Unparsed.
*
* @var string
* @since 1.0.0
*/
public string $plain = '';
/**
* Created.
*
* @var \DateTimeImmutable
* @since 1.0.0
*/
public \DateTimeImmutable $createdAt;
/**
* Creator.
*
* @var Account
* @since 1.0.0
*/
public Account $createdBy;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->createdBy = new NullAccount();
$this->createdAt = new \DateTimeImmutable('now');
}
/**
* Create history form model
*
* @param EditorDoc $doc Document
*
* @return self
*
* @since 1.0.0
*/
public static function createFromDoc(EditorDoc $doc) : self
{
$hist = new self();
$hist->doc = $doc->id;
$hist->createdBy = $doc->createdBy;
$hist->title = $doc->title;
$hist->plain = $doc->plain;
$hist->content = $doc->content;
$hist->version = $doc->version;
return $hist;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'plain' => $this->plain,
'content' => $this->content,
'createdAt' => $this->createdAt,
'createdBy' => $this->createdBy,
];
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}