oms-Tag/Models/Tag.php
2020-08-30 20:13:11 +02:00

214 lines
3.7 KiB
PHP
Executable File

<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Tag\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Tag\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* Tag class.
*
* @package Modules\Tag\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Tag implements \JsonSerializable, ArrayableInterface
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Title.
*
* @var string|L11nTag
* @since 1.0.0
*/
private $title = '';
/**
* Color RGBA.
*
* @var string
* @since 1.0.0
*/
private string $color = '00000000';
/**
* Creator.
*
* @var null|Account
* @since 1.0.0
*/
protected ?Account $owner = null;
/**
* Tag type.
*
* @var int
* @since 1.0.0
*/
private int $type = TagType::SINGLE;
/**
* Get created by
*
* @return Account
*
* @since 1.0.0
*/
public function getOwner() : Account
{
return $this->owner ?? new NullAccount();
}
/**
* Set created by
*
* @param Account $id Created by
*
* @return void
*
* @since 1.0.0
*/
public function setOwner(Account $id) : void
{
$this->owner = $id;
}
/**
* Get type.
*
* @return int
*
* @since 1.0.0
*/
public function getType() : int
{
return $this->type;
}
/**
* Set type.
*
* @param int $type Tag type
*
* @return void
*
* @since 1.0.0
*/
public function setType(int $type = TagType::SINGLE) : void
{
$this->type = $type;
}
/**
* Get color
*
* @return string
*
* @since 1.0.0
*/
public function getColor() : string
{
return $this->color;
}
/**
* Set color
*
* @param string $color Tag article color
*
* @return void
*
* @since 1.0.0
*/
public function setColor(string $color) : void
{
$this->color = $color;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
*/
public function getTitle() : string
{
return $this->title instanceof L11nTag ? $this->title->getTitle() : $this->title;
}
/**
* Set title
*
* @param string|L11nTag $title Tag article title
*
* @return void
*
* @since 1.0.0
*/
public function setTitle($title, string $lang = ISO639x1Enum::_EN) : void
{
if ($title instanceof L11nTag) {
$this->title = new L11nTag();
} elseif ($this->title instanceof L11nTag && \is_string($title)) {
$this->title->setTitle($title);
} elseif (\is_string($title)) {
$this->title = new L11nTag();
$this->title->setTitle($title);
$this->title->setLanguage($lang);
}
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'color' => $this->color,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
}