mirror of
https://github.com/Karaka-Management/oms-Organization.git
synced 2026-01-11 16:18:40 +00:00
231 lines
3.9 KiB
PHP
Executable File
231 lines
3.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Karaka
|
|
*
|
|
* PHP Version 8.1
|
|
*
|
|
* @package Modules\Organization\Models
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Organization\Models;
|
|
|
|
use Modules\Admin\Models\Address;
|
|
use Modules\Admin\Models\NullAddress;
|
|
use Modules\Media\Models\Media;
|
|
use Modules\Media\Models\NullMedia;
|
|
/**
|
|
* Organization unit class.
|
|
*
|
|
* @package Modules\Organization\Models
|
|
* @license OMS License 1.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
*/
|
|
class Unit implements \JsonSerializable
|
|
{
|
|
/**
|
|
* Unit ID.
|
|
*
|
|
* @var int
|
|
* @since 1.0.0
|
|
*/
|
|
protected int $id = 0;
|
|
|
|
/**
|
|
* Name.
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $name = '';
|
|
|
|
/**
|
|
* Unit image.
|
|
*
|
|
* @var Media
|
|
* @since 1.0.0
|
|
*/
|
|
public Media $image;
|
|
|
|
/**
|
|
* Parent
|
|
*
|
|
* @var Unit
|
|
* @since 1.0.0
|
|
*/
|
|
public self $parent;
|
|
|
|
/**
|
|
* Description.
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $description = '';
|
|
|
|
/**
|
|
* Description.
|
|
*
|
|
* @var string
|
|
* @since 1.0.0
|
|
*/
|
|
public string $descriptionRaw = '';
|
|
|
|
/**
|
|
* Status
|
|
*
|
|
* @var int
|
|
* @since 1.0.0
|
|
*/
|
|
protected int $status = Status::INACTIVE;
|
|
|
|
public Address $mainAddress;
|
|
|
|
private array $address = [];
|
|
|
|
/**
|
|
* Attributes.
|
|
*
|
|
* @var UnitAttribute[]
|
|
* @since 1.0.0
|
|
*/
|
|
private array $attributes = [];
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->image = new NullMedia();
|
|
$this->parent = new NullUnit();
|
|
$this->mainAddress = new NullAddress();
|
|
}
|
|
|
|
/**
|
|
* Get id
|
|
*
|
|
* @return int
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getId() : int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Add attribute to client
|
|
*
|
|
* @param UnitAttribute $attribute Attribute
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function addAttribute(UnitAttribute $attribute) : void
|
|
{
|
|
$this->attributes[] = $attribute;
|
|
}
|
|
|
|
/**
|
|
* Get attributes
|
|
*
|
|
* @return UnitAttribute[]
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getAttributes() : array
|
|
{
|
|
return $this->attributes;
|
|
}
|
|
|
|
/**
|
|
* Get attribute
|
|
*
|
|
* @param string $attrName Attribute name
|
|
*
|
|
* @return null|UnitAttribute
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getAttribute(string $attrName) : ?UnitAttribute
|
|
{
|
|
foreach ($this->attributes as $attribute) {
|
|
if ($attribute->type->name === $attrName) {
|
|
return $attribute->value;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get status
|
|
*
|
|
* @return int
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getStatus() : int
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
/**
|
|
* Set status
|
|
*
|
|
* @param int $status Status
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setStatus(int $status) : void
|
|
{
|
|
$this->status = $status;
|
|
}
|
|
|
|
/**
|
|
* Get addresses.
|
|
*
|
|
* @return array
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getAddresses() : array
|
|
{
|
|
return $this->address;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function toArray() : array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'status' => $this->status,
|
|
'description' => $this->description,
|
|
'descriptionRaw' => $this->descriptionRaw,
|
|
'parent' => $this->parent ?? null,
|
|
'image' => $this->image,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function jsonSerialize() : mixed
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|