This commit is contained in:
Dennis Eichhorn 2020-03-05 20:35:58 +01:00
parent f9c943466a
commit 01e44c0e98
7 changed files with 74 additions and 38 deletions

View File

@ -16,13 +16,16 @@ namespace Modules\Organization\Controller;
use Modules\Organization\Models\Department;
use Modules\Organization\Models\DepartmentMapper;
use Modules\Organization\Models\NullDepartment;
use Modules\Organization\Models\NullPosition;
use Modules\Organization\Models\NullUnit;
use Modules\Organization\Models\Position;
use Modules\Organization\Models\PositionMapper;
use Modules\Organization\Models\SettingsEnum;
use Modules\Organization\Models\Status;
use Modules\Organization\Models\Unit;
use Modules\Organization\Models\UnitMapper;
use phpOMS\Account\GroupStatus;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\NotificationLevel;
@ -204,7 +207,7 @@ final class ApiController extends Controller
$unit->setDescription(Markdown::parse((string) ($request->getData('description') ?? '')));
$parent = (int) $request->getData('parent');
$unit->setParent(!empty($parent) ? $parent : null);
$unit->setParent(!empty($parent) ? new NullUnit($parent) : null);
$unit->setStatus((int) $request->getData('status'));
return $unit;
@ -376,10 +379,10 @@ final class ApiController extends Controller
$position->setDescription(Markdown::parse((string) ($request->getData('description') ?? '')));
$parent = (int) $request->getData('parent');
$position->setParent(!empty($parent) ? $parent : null);
$position->setParent(!empty($parent) ? new NullPosition($parent) : null);
$department = (int) $request->getData('department');
$position->setDepartment(!empty($department) ? $department : null);
$position->setDepartment(!empty($department) ? new NullDepartment($department) : null);
return $position;
}
@ -547,8 +550,8 @@ final class ApiController extends Controller
$department->setStatus((int) $request->getData('status'));
$parent = (int) $request->getData('parent');
$department->setParent(!empty($parent) ? $parent : null);
$department->setUnit((int) ($request->getData('unit') ?? 1));
$department->setParent(!empty($parent) ? new NullDepartment($parent) : null);
$department->setUnit(new NullUnit((int) ($request->getData('unit') ?? 1)));
$department->setDescriptionRaw((string) ($request->getData('description') ?? ''));
$department->setDescription(Markdown::parse((string) ($request->getData('description') ?? '')));

View File

@ -48,7 +48,7 @@ class Department implements ArrayableInterface, \JsonSerializable
* @var mixed
* @since 1.0.0
*/
protected $parent = null;
protected ?self $parent = null;
/**
* Status
@ -61,10 +61,10 @@ class Department implements ArrayableInterface, \JsonSerializable
/**
* Unit this department belongs to
*
* @var mixed
* @var Unit
* @since 1.0.0
*/
protected $unit = 1;
protected Unit $unit;
/**
* Description.
@ -135,11 +135,11 @@ class Department implements ArrayableInterface, \JsonSerializable
/**
* Get parent
*
* @return mixed
* @return Department
*
* @since 1.0.0
*/
public function getParent()
public function getParent() : self
{
return $this->parent ?? new NullDepartment();
}
@ -147,13 +147,13 @@ class Department implements ArrayableInterface, \JsonSerializable
/**
* Set parent
*
* @param mixed $parent Parent
* @param null|self $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent($parent) : void
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
@ -187,11 +187,11 @@ class Department implements ArrayableInterface, \JsonSerializable
/**
* Get unit
*
* @return mixed
* @return Unit
*
* @since 1.0.0
*/
public function getUnit()
public function getUnit() : Unit
{
return $this->unit ?? new NullUnit();
}
@ -199,13 +199,13 @@ class Department implements ArrayableInterface, \JsonSerializable
/**
* Set unit
*
* @param mixed $unit Unit
* @param Unit $unit Unit
*
* @return void
*
* @since 1.0.0
*/
public function setUnit($unit) : void
public function setUnit(Unit $unit) : void
{
$this->unit = $unit;
}
@ -271,7 +271,7 @@ class Department implements ArrayableInterface, \JsonSerializable
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'unit' => $this->unit,
'unit' => $this->unit ?? new NullUnit(),
];
}

View File

@ -24,4 +24,15 @@ namespace Modules\Organization\Models;
*/
final class NullDepartment extends Department
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -24,4 +24,15 @@ namespace Modules\Organization\Models;
*/
final class NullPosition extends Position
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -24,4 +24,15 @@ namespace Modules\Organization\Models;
*/
final class NullUnit extends Unit
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -45,18 +45,18 @@ class Position implements ArrayableInterface, \JsonSerializable
/**
* Parent
*
* @var mixed
* @var null|Position
* @since 1.0.0
*/
private $parent = null;
private ?self $parent = null;
/**
* Department
*
* @var mixed
* @var null|Department
* @since 1.0.0
*/
private $department = null;
private ?Department $department = null;
/**
* Description.
@ -123,11 +123,11 @@ class Position implements ArrayableInterface, \JsonSerializable
/**
* Get parent
*
* @return mixed
* @return Position
*
* @since 1.0.0
*/
public function getParent()
public function getParent() : self
{
return $this->parent ?? new NullPosition();
}
@ -135,13 +135,13 @@ class Position implements ArrayableInterface, \JsonSerializable
/**
* Set parent
*
* @param mixed $parent Parent
* @param null|Position $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent($parent) : void
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
@ -149,11 +149,11 @@ class Position implements ArrayableInterface, \JsonSerializable
/**
* Get parent
*
* @return mixed
* @return Department
*
* @since 1.0.0
*/
public function getDepartment()
public function getDepartment() : Department
{
return $this->department ?? new NullDepartment();
}
@ -161,13 +161,13 @@ class Position implements ArrayableInterface, \JsonSerializable
/**
* Set department
*
* @param mixed $department Department
* @param null|Department $department Department
*
* @return void
*
* @since 1.0.0
*/
public function setDepartment($department) : void
public function setDepartment(?Department $department) : void
{
$this->department = $department;
}
@ -259,7 +259,7 @@ class Position implements ArrayableInterface, \JsonSerializable
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'department' => $this->department,
'department' => $this->department ?? new NullDepartment(),
'parent' => $this->parent,
];
}

View File

@ -32,7 +32,7 @@ class Unit implements ArrayableInterface, \JsonSerializable
* @var int
* @since 1.0.0
*/
private int $id = 0;
protected int $id = 0;
/**
* Name.
@ -45,10 +45,10 @@ class Unit implements ArrayableInterface, \JsonSerializable
/**
* Parent
*
* @var mixed
* @var null|Unit
* @since 1.0.0
*/
private $parent = null;
private ?self $parent = null;
/**
* Description.
@ -115,11 +115,11 @@ class Unit implements ArrayableInterface, \JsonSerializable
/**
* Get parent
*
* @return mixed
* @return Unit
*
* @since 1.0.0
*/
public function getParent()
public function getParent() : self
{
return $this->parent ?? new NullUnit();
}
@ -127,13 +127,13 @@ class Unit implements ArrayableInterface, \JsonSerializable
/**
* Set parent
*
* @param mixed $parent Parent
* @param null|Unit $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent($parent) : void
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}