mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-01-11 17:18:42 +00:00
210 lines
3.4 KiB
PHP
Executable File
210 lines
3.4 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 8.0
|
|
*
|
|
* @package Modules\Editor\Models
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link https://orange-management.org
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Editor\Models;
|
|
|
|
use Modules\Admin\Models\Account;
|
|
use Modules\Admin\Models\NullAccount;
|
|
use Modules\Tag\Models\Tag;
|
|
use phpOMS\Contract\ArrayableInterface;
|
|
|
|
/**
|
|
* News article class.
|
|
*
|
|
* @package Modules\Editor\Models
|
|
* @license OMS License 1.0
|
|
* @link https://orange-management.org
|
|
* @since 1.0.0
|
|
*/
|
|
class EditorDoc implements \JsonSerializable, ArrayableInterface
|
|
{
|
|
/**
|
|
* Article ID.
|
|
*
|
|
* @var int
|
|
* @since 1.0.0
|
|
*/
|
|
protected int $id = 0;
|
|
|
|
/**
|
|
* 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 = '';
|
|
|
|
/**
|
|
* Doc path for organizing.
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
private string $virtualPath = '/';
|
|
|
|
/**
|
|
* Doc is visible in editor doc list.
|
|
*
|
|
* @var bool
|
|
* @since 1.0.0
|
|
*/
|
|
public bool $isVisible = true;
|
|
|
|
/**
|
|
* Created.
|
|
*
|
|
* @var \DateTimeImmutable
|
|
* @since 1.0.0
|
|
*/
|
|
public \DateTimeImmutable $createdAt;
|
|
|
|
/**
|
|
* Creator.
|
|
*
|
|
* @var Account
|
|
* @since 1.0.0
|
|
*/
|
|
public Account $createdBy;
|
|
|
|
/**
|
|
* Tags.
|
|
*
|
|
* @var Tag[]
|
|
* @since 1.0.0
|
|
*/
|
|
private array $tags = [];
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->createdBy = new NullAccount();
|
|
$this->createdAt = new \DateTimeImmutable('now');
|
|
}
|
|
|
|
/**
|
|
* Get the id
|
|
*
|
|
* @return int
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getId() : int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Get the path
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getVirtualPath() : string
|
|
{
|
|
return $this->virtualPath;
|
|
}
|
|
|
|
/**
|
|
* Set the path if file
|
|
*
|
|
* @param string $path Path to file
|
|
*
|
|
* @return mixed
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setVirtualPath(string $path)
|
|
{
|
|
$this->virtualPath = $path;
|
|
}
|
|
|
|
/**
|
|
* Get tags
|
|
*
|
|
* @return array
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getTags() : array
|
|
{
|
|
return $this->tags;
|
|
}
|
|
|
|
/**
|
|
* Add tag
|
|
*
|
|
* @param Tag $tag Tag
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function addTag(Tag $tag) : void
|
|
{
|
|
$this->tags[] = $tag;
|
|
}
|
|
|
|
/**
|
|
* {@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()
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|