mirror of
https://github.com/Karaka-Management/oms-Comments.git
synced 2026-01-11 16:18:41 +00:00
203 lines
3.3 KiB
PHP
Executable File
203 lines
3.3 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Karaka
|
|
*
|
|
* PHP Version 8.1
|
|
*
|
|
* @package Modules\Comments\Models
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Comments\Models;
|
|
|
|
use Modules\Admin\Models\Account;
|
|
use Modules\Admin\Models\NullAccount;
|
|
use Modules\Media\Models\Media;
|
|
|
|
/**
|
|
* Comment class.
|
|
*
|
|
* @package Modules\Comments\Models
|
|
* @license OMS License 2.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
*/
|
|
class Comment implements \JsonSerializable
|
|
{
|
|
/**
|
|
* ID.
|
|
*
|
|
* @var int
|
|
* @since 1.0.0
|
|
*/
|
|
protected int $id = 0;
|
|
|
|
/**
|
|
* Account.
|
|
*
|
|
* @var Account
|
|
* @since 1.0.0
|
|
*/
|
|
public Account $createdBy;
|
|
|
|
/**
|
|
* Created at
|
|
*
|
|
* @var \DateTimeImmutable
|
|
* @since 1.0.0
|
|
*/
|
|
public \DateTimeImmutable $createdAt;
|
|
|
|
/**
|
|
* Comment list this comment belongs to
|
|
*
|
|
* @var int|CommentList
|
|
* @since 1.0.0
|
|
*/
|
|
public $list = 0;
|
|
|
|
/**
|
|
* Title
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $title = '';
|
|
|
|
/**
|
|
* Comment status
|
|
*
|
|
* @var int
|
|
* @since 1.0.0
|
|
*/
|
|
private int $status = CommentStatus::VISIBLE;
|
|
|
|
/**
|
|
* Content
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $content = '';
|
|
|
|
/**
|
|
* Content raw
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $contentRaw = '';
|
|
|
|
/**
|
|
* Comment this is refering to
|
|
*
|
|
* @var null|int|self
|
|
* @since 1.0.0
|
|
*/
|
|
public $ref = null;
|
|
|
|
/**
|
|
* Media files
|
|
*
|
|
* @var Media[]
|
|
* @since 1.0.0
|
|
*/
|
|
protected array $media = [];
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->createdBy = new NullAccount();
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
/**
|
|
* Get id.
|
|
*
|
|
* @return int Model id
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getId() : int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Set the status
|
|
*
|
|
* @param int $status Status
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setStatus(int $status) : void
|
|
{
|
|
$this->status = $status;
|
|
}
|
|
|
|
/**
|
|
* Get the status
|
|
*
|
|
* @return int
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getStatus() : int
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function jsonSerialize() : mixed
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'content' => $this->content,
|
|
'list' => $this->list,
|
|
'ref' => $this->ref,
|
|
'status' => $this->status,
|
|
'createdAt' => $this->createdAt,
|
|
'createdBy' => $this->createdBy,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get all media
|
|
*
|
|
* @return Media[]
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getMedia() : array
|
|
{
|
|
return $this->media;
|
|
}
|
|
|
|
/**
|
|
* Add media
|
|
*
|
|
* @param Media $media Media to add
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function addMedia(Media $media) : void
|
|
{
|
|
$this->media[] = $media;
|
|
}
|
|
}
|