remove some getter/setter

This commit is contained in:
Dennis Eichhorn 2020-11-24 17:31:20 +01:00
parent d50116d884
commit 447b702672
28 changed files with 302 additions and 711 deletions

View File

@ -51,7 +51,7 @@ final class Installer extends InstallerAbstract
private static function installDefaultUnit() : void
{
$unit = new Unit();
$unit->setName('Orange Management');
$unit->name = 'Orange Management';
UnitMapper::create($unit);
}

View File

@ -111,7 +111,7 @@ final class ApiController extends Controller
/** @var Unit $old */
$old = clone UnitMapper::get((int) $request->getData('id'));
$new = $this->updateUnitFromRequest($request);
$this->updateModel($request->getHeader()->getAccount(), $old, $new, UnitMapper::class, 'unit', $request->getOrigin());
$this->updateModel($request->header->account, $old, $new, UnitMapper::class, 'unit', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit successfully updated.', $new);
}
@ -128,12 +128,12 @@ final class ApiController extends Controller
{
/** @var Unit $unit */
$unit = UnitMapper::get((int) $request->getData('id'));
$unit->setName((string) ($request->getData('name') ?? $unit->getName()));
$unit->setDescriptionRaw((string) ($request->getData('description') ?? $unit->getDescriptionRaw()));
$unit->setDescription(Markdown::parse((string) ($request->getData('description') ?? $unit->getDescriptionRaw())));
$unit->name = (string) ($request->getData('name') ?? $unit->name);
$unit->descriptionRaw = (string) ($request->getData('description') ?? $unit->descriptionRaw);
$unit->description = Markdown::parse((string) ($request->getData('description') ?? $unit->descriptionRaw));
$parent = (int) $request->getData('parent');
$unit->setParent(!empty($parent) ? new NullUnit($parent) : $unit->getParent());
$unit->parent = !empty($parent) ? new NullUnit($parent) : $unit->parent;
$unit->setStatus((int) ($request->getData('status') ?? $unit->getStatus()));
return $unit;
@ -156,7 +156,7 @@ final class ApiController extends Controller
{
/** @var Unit $unit */
$unit = UnitMapper::get((int) $request->getData('id'));
$this->deleteModel($request->getHeader()->getAccount(), $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->deleteModel($request->header->account, $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit successfully deleted.', $unit);
}
@ -177,17 +177,17 @@ final class ApiController extends Controller
{
if (!empty($val = $this->validateUnitCreate($request))) {
$response->set('unit_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
$unit = $this->createUnitFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->createModel($request->header->account, $unit, UnitMapper::class, 'unit', $request->getOrigin());
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_UNIT)['content'] === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:unit:' . \strtolower($unit->getName()));
$newRequest->setData('name', 'org:unit:' . \strtolower($unit->name));
$newRequest->setData('status', GroupStatus::ACTIVE);
$this->app->moduleManager->get('Admin')->apiGroupCreate($newRequest, $response, $data);
}
@ -207,12 +207,12 @@ final class ApiController extends Controller
private function createUnitFromRequest(RequestAbstract $request) : Unit
{
$unit = new Unit();
$unit->setName((string) $request->getData('name'));
$unit->setDescriptionRaw((string) ($request->getData('description') ?? ''));
$unit->setDescription(Markdown::parse((string) ($request->getData('description') ?? '')));
$unit->name = (string) $request->getData('name');
$unit->descriptionRaw = (string) ($request->getData('description') ?? '');
$unit->description = Markdown::parse((string) ($request->getData('description') ?? ''));
$parent = (int) $request->getData('parent');
$unit->setParent(!empty($parent) ? new NullUnit($parent) : null);
$unit->parent = new NullUnit($parent);
$unit->setStatus((int) $request->getData('status'));
return $unit;
@ -236,7 +236,7 @@ final class ApiController extends Controller
$uploadedFiles = $request->getFiles() ?? [];
if (empty($uploadedFiles)) {
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Unit', 'Invalid unit image', $uploadedFiles);
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
@ -248,14 +248,14 @@ final class ApiController extends Controller
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
$request->getData('name') ?? '',
$uploadedFiles,
$request->getHeader()->getAccount(),
$request->header->account,
'Modules/Media/Files',
'/Modules/Organization'
);
$unit->setImage(\reset($uploaded));
$unit->image = \reset($uploaded);
$this->updateModel($request->getHeader()->getAccount(), $old, $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->updateModel($request->header->account, $old, $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit image successfully updated', $unit);
}
@ -324,7 +324,7 @@ final class ApiController extends Controller
{
/** @var Position $position */
$position = PositionMapper::get((int) $request->getData('id'));
$this->deleteModel($request->getHeader()->getAccount(), $position, PositionMapper::class, 'position', $request->getOrigin());
$this->deleteModel($request->header->account, $position, PositionMapper::class, 'position', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Position', 'Position successfully deleted.', $position);
}
@ -346,7 +346,7 @@ final class ApiController extends Controller
/** @var Position $old */
$old = clone PositionMapper::get((int) $request->getData('id'));
$new = $this->updatePositionFromRequest($request);
$this->updateModel($request->getHeader()->getAccount(), $old, $new, PositionMapper::class, 'position', $request->getOrigin());
$this->updateModel($request->header->account, $old, $new, PositionMapper::class, 'position', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Position', 'Position successfully updated.', $new);
}
@ -363,15 +363,15 @@ final class ApiController extends Controller
{
/** @var Position $position */
$position = PositionMapper::get((int) $request->getData('id'));
$position->setName((string) ($request->getData('name') ?? $position->getName()));
$position->setDescriptionRaw((string) ($request->getData('description') ?? $position->getDescriptionRaw()));
$position->setDescription(Markdown::parse((string) ($request->getData('description') ?? $position->getDescriptionRaw())));
$position->name = (string) ($request->getData('name') ?? $position->name);
$position->descriptionRaw = (string) ($request->getData('description') ?? $position->descriptionRaw);
$position->description = Markdown::parse((string) ($request->getData('description') ?? $position->descriptionRaw));
$parent = (int) $request->getData('parent');
$position->setParent(!empty($parent) ? new NullPosition($parent) : $position->getParent());
$position->parent = !empty($parent) ? new NullPosition($parent) : $position->parent;
$department = (int) $request->getData('department');
$position->setDepartment(!empty($department) ? new NullDepartment($department) : $position->getDepartment());
$position->department = !empty($department) ? new NullDepartment($department) : $position->department;
$position->setStatus((int) ($request->getData('status') ?? $position->getStatus()));
return $position;
@ -394,17 +394,17 @@ final class ApiController extends Controller
{
if (!empty($val = $this->validatePositionCreate($request))) {
$response->set('position_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
$position = $this->createPositionFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $position, PositionMapper::class, 'position', $request->getOrigin());
$this->createModel($request->header->account, $position, PositionMapper::class, 'position', $request->getOrigin());
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_POSITION)['content'] === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:pos:' . \strtolower($position->getName()));
$newRequest->setData('name', 'org:pos:' . \strtolower($position->name));
$newRequest->setData('status', GroupStatus::ACTIVE);
$this->app->moduleManager->get('Admin')->apiGroupCreate($newRequest, $response, $data);
}
@ -424,16 +424,16 @@ final class ApiController extends Controller
private function createPositionFromRequest(RequestAbstract $request) : Position
{
$position = new Position();
$position->setName((string) ($request->getData('name')));
$position->name = (string) ($request->getData('name'));
$position->setStatus((int) $request->getData('status'));
$position->setDescriptionRaw((string) ($request->getData('description') ?? ''));
$position->setDescription(Markdown::parse((string) ($request->getData('description') ?? '')));
$position->descriptionRaw = (string) ($request->getData('description') ?? '');
$position->description = Markdown::parse((string) ($request->getData('description') ?? ''));
$parent = (int) $request->getData('parent');
$position->setParent(!empty($parent) ? new NullPosition($parent) : null);
$position->parent = new NullPosition($parent);
$department = (int) $request->getData('department');
$position->setDepartment(!empty($department) ? new NullDepartment($department) : null);
$position->department = new NullDepartment($department);
return $position;
}
@ -503,7 +503,7 @@ final class ApiController extends Controller
/** @var Department $old */
$old = clone DepartmentMapper::get((int) $request->getData('id'));
$new = $this->updateDepartmentFromRequest($request);
$this->updateModel($request->getHeader()->getAccount(), $old, $new, DepartmentMapper::class, 'department', $request->getOrigin());
$this->updateModel($request->header->account, $old, $new, DepartmentMapper::class, 'department', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Department', 'Department successfully updated.', $new);
}
@ -520,16 +520,16 @@ final class ApiController extends Controller
{
/** @var Department $department */
$department = DepartmentMapper::get((int) $request->getData('id'));
$department->setName((string) ($request->getData('name') ?? $department->getName()));
$department->setDescriptionRaw((string) ($request->getData('description') ?? $department->getDescriptionRaw()));
$department->setDescription(Markdown::parse((string) ($request->getData('description') ?? $department->getDescriptionRaw())));
$department->name = (string) ($request->getData('name') ?? $department->name);
$department->descriptionRaw = (string) ($request->getData('description') ?? $department->descriptionRaw);
$department->description = Markdown::parse((string) ($request->getData('description') ?? $department->descriptionRaw));
$parent = (int) $request->getData('parent');
$department->setParent(!empty($parent) ? new NullDepartment($parent) : $department->getParent());
$department->parent = !empty($parent) ? new NullDepartment($parent) : $department->parent;
$department->setStatus((int) ($request->getData('status') ?? $department->getStatus()));
$unit = (int) $request->getData('unit');
$department->setUnit(!empty($unit) ? new NullUnit($unit) : $department->getUnit());
$department->unit = !empty($unit) ? new NullUnit($unit) : $department->unit;
return $department;
}
@ -551,7 +551,7 @@ final class ApiController extends Controller
{
/** @var Department $department */
$department = DepartmentMapper::get((int) $request->getData('id'));
$this->deleteModel($request->getHeader()->getAccount(), $department, DepartmentMapper::class, 'department', $request->getOrigin());
$this->deleteModel($request->header->account, $department, DepartmentMapper::class, 'department', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Department', 'Department successfully deleted.', $department);
}
@ -572,17 +572,17 @@ final class ApiController extends Controller
{
if (!empty($val = $this->validateDepartmentCreate($request))) {
$response->set('department_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
$department = $this->createDepartmentFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $department, DepartmentMapper::class, 'department', $request->getOrigin());
$this->createModel($request->header->account, $department, DepartmentMapper::class, 'department', $request->getOrigin());
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT)['content'] === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:dep:' . \strtolower($department->getName()));
$newRequest->setData('name', 'org:dep:' . \strtolower($department->name));
$newRequest->setData('status', GroupStatus::ACTIVE);
$this->app->moduleManager->get('Admin')->apiGroupCreate($newRequest, $response, $data);
}
@ -602,14 +602,14 @@ final class ApiController extends Controller
private function createDepartmentFromRequest(RequestAbstract $request) : Department
{
$department = new Department();
$department->setName((string) $request->getData('name'));
$department->name = (string) $request->getData('name');
$department->setStatus((int) $request->getData('status'));
$parent = (int) $request->getData('parent');
$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') ?? '')));
$department->parent = new NullDepartment($parent);
$department->unit = new NullUnit((int) ($request->getData('unit') ?? 1));
$department->descriptionRaw = (string) ($request->getData('description') ?? '');
$department->description = Markdown::parse((string) ($request->getData('description') ?? ''));
return $department;
}
@ -629,9 +629,9 @@ final class ApiController extends Controller
*/
public function apiUnitFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
$response->header->set('Content-Type', MimeType::M_JSON, true);
$response->set(
$request->getUri()->__toString(),
$request->uri->__toString(),
\array_values(
UnitMapper::find((string) ($request->getData('search') ?? ''))
)
@ -653,9 +653,9 @@ final class ApiController extends Controller
*/
public function apiDepartmentFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
$response->header->set('Content-Type', MimeType::M_JSON, true);
$response->set(
$request->getUri()->__toString(),
$request->uri->__toString(),
\array_values(
DepartmentMapper::find((string) ($request->getData('search') ?? ''))
)
@ -677,9 +677,9 @@ final class ApiController extends Controller
*/
public function apiPositionFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
$response->header->set('Content-Type', MimeType::M_JSON, true);
$response->set(
$request->getUri()->__toString(),
$request->uri->__toString(),
\array_values(
PositionMapper::find((string) ($request->getData('search') ?? ''))
)

View File

@ -151,9 +151,9 @@ final class BackendController extends Controller
foreach ($components as $component) {
$ref = null;
if ($component instanceof Department) {
$ref = $component->getUnit()->getId();
$ref = $component->unit->getId();
} elseif ($component instanceof Position) {
$ref = $component->getDepartment()->getId();
$ref = $component->department->getId();
}
if (!isset($tree[$ref])) {
@ -166,9 +166,9 @@ final class BackendController extends Controller
$tree[$ref][$component->getId()]['obj'] = $component;
$parent = $component->getParent()->getId();
$parent = $component->parent->getId();
if (!($component instanceof Position) // parent could be in different department then ignore
|| $component->getParent()->getDepartment()->getId() === $component->getDepartment()->getId()
|| $component->parent->department->getId() === $component->department->getId()
) {
if (!isset($tree[$ref][$parent])) {
$tree[$ref][$parent] = ['obj' => null, 'children' => [], 'index' => 0];

View File

@ -40,15 +40,15 @@ class Department implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
protected string $name = '';
public string $name = '';
/**
* Parent
*
* @var null|self
* @var self
* @since 1.0.0
*/
protected ?self $parent = null;
public self $parent;
/**
* Status
@ -64,7 +64,7 @@ class Department implements \JsonSerializable, ArrayableInterface
* @var Unit
* @since 1.0.0
*/
protected Unit $unit;
public Unit $unit;
/**
* Description.
@ -72,7 +72,7 @@ class Department implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
protected string $description = '';
public string $description = '';
/**
* Description.
@ -80,7 +80,7 @@ class Department implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
protected string $descriptionRaw = '';
public string $descriptionRaw = '';
/**
* Constructor
@ -91,7 +91,9 @@ class Department implements \JsonSerializable, ArrayableInterface
*/
public function __construct(string $name = '')
{
$this->setName($name);
$this->name = $name;
$this->parent = new NullDepartment();
$this->unit = new NullUnit();
}
/**
@ -106,58 +108,6 @@ class Department implements \JsonSerializable, ArrayableInterface
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Set name
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
/**
* Get parent
*
* @return Department
*
* @since 1.0.0
*/
public function getParent() : self
{
return $this->parent ?? new NullDepartment();
}
/**
* Set parent
*
* @param null|self $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
/**
* Get status
*
@ -184,84 +134,6 @@ class Department implements \JsonSerializable, ArrayableInterface
$this->status = $status;
}
/**
* Get unit
*
* @return Unit
*
* @since 1.0.0
*/
public function getUnit() : Unit
{
return $this->unit ?? new NullUnit();
}
/**
* Set unit
*
* @param Unit $unit Unit
*
* @return void
*
* @since 1.0.0
*/
public function setUnit(Unit $unit) : void
{
$this->unit = $unit;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescription() : string
{
return $this->description;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescription(string $desc) : void
{
$this->description = $desc;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescriptionRaw() : string
{
return $this->descriptionRaw;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescriptionRaw(string $desc) : void
{
$this->descriptionRaw = $desc;
}
/**
* {@inheritdoc}
*/

View File

@ -34,6 +34,6 @@ final class NullDepartment extends Department
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
$this->unit = new NullUnit();
}
}

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\Organization\Models;
use Modules\Media\Models\NullMedia;
/**
* Organization null class.
*
@ -34,6 +36,6 @@ final class NullUnit extends Unit
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
$this->image = new NullMedia();
}
}

View File

@ -40,23 +40,23 @@ class Position implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $name = '';
public string $name = '';
/**
* Parent
*
* @var null|Position
* @var Position
* @since 1.0.0
*/
private ?self $parent = null;
public self $parent;
/**
* Department
*
* @var null|Department
* @var Department
* @since 1.0.0
*/
private ?Department $department = null;
public Department $department;
/**
* Description.
@ -64,7 +64,7 @@ class Position implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $description = '';
public string $description = '';
/**
* Description.
@ -72,7 +72,7 @@ class Position implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $descriptionRaw = '';
public string $descriptionRaw = '';
/**
* Status
@ -82,6 +82,17 @@ class Position implements \JsonSerializable, ArrayableInterface
*/
protected int $status = Status::INACTIVE;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->parent = new NullPosition();
$this->department = new NullDepartment();
}
/**
* Get id
*
@ -94,84 +105,6 @@ class Position implements \JsonSerializable, ArrayableInterface
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Set name
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
/**
* Get parent
*
* @return Position
*
* @since 1.0.0
*/
public function getParent() : self
{
return $this->parent ?? new NullPosition();
}
/**
* Set parent
*
* @param null|Position $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
/**
* Get parent
*
* @return Department
*
* @since 1.0.0
*/
public function getDepartment() : Department
{
return $this->department ?? new NullDepartment();
}
/**
* Set department
*
* @param null|Department $department Department
*
* @return void
*
* @since 1.0.0
*/
public function setDepartment(?Department $department) : void
{
$this->department = $department;
}
/**
* Get status
*
@ -198,58 +131,6 @@ class Position implements \JsonSerializable, ArrayableInterface
$this->status = $status;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescription() : string
{
return $this->description;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescription(string $desc) : void
{
$this->description = $desc;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescriptionRaw() : string
{
return $this->descriptionRaw;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescriptionRaw(string $desc) : void
{
$this->descriptionRaw = $desc;
}
/**
* {@inheritdoc}
*/

View File

@ -42,7 +42,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $name = '';
public string $name = '';
/**
* Unit image.
@ -50,7 +50,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
* @var Media
* @since 1.0.0
*/
protected Media $image;
public Media $image;
/**
* Parent
@ -58,7 +58,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
* @var null|Unit
* @since 1.0.0
*/
private ?self $parent = null;
public ?self $parent = null;
/**
* Description.
@ -66,7 +66,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $description = '';
public string $description = '';
/**
* Description.
@ -74,7 +74,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
protected string $descriptionRaw = '';
public string $descriptionRaw = '';
/**
* Status
@ -92,6 +92,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
public function __construct()
{
$this->image = new NullMedia();
$this->parent = new NullUnit();
}
/**
@ -106,84 +107,6 @@ class Unit implements \JsonSerializable, ArrayableInterface
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Set name
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
/**
* Get unit image.
*
* @return Media
*
* @since 1.0.0
*/
public function getImage() : Media
{
return $this->image ?? new NullMedia();
}
/**
* Set unit image.
*
* @param Media $image Profile image
*
* @return void
*
* @since 1.0.0
*/
public function setImage(Media $image) : void
{
$this->image = $image;
}
/**
* Get parent
*
* @return Unit
*
* @since 1.0.0
*/
public function getParent() : self
{
return $this->parent ?? new NullUnit();
}
/**
* Set parent
*
* @param null|Unit $parent Parent
*
* @return void
*
* @since 1.0.0
*/
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
/**
* Get status
*
@ -210,58 +133,6 @@ class Unit implements \JsonSerializable, ArrayableInterface
$this->status = $status;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescription() : string
{
return $this->description;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescription(string $desc) : void
{
$this->description = $desc;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescriptionRaw() : string
{
return $this->descriptionRaw;
}
/**
* Set description
*
* @param string $desc Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescriptionRaw(string $desc) : void
{
$this->descriptionRaw = $desc;
}
/**
* {@inheritdoc}
*/

View File

@ -44,7 +44,7 @@ class DepartmentTagSelectorView extends View
* @var string
* @since 1.0.0
*/
private string $name = '';
public string $name = '';
/**
* Is required
@ -78,18 +78,6 @@ class DepartmentTagSelectorView extends View
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Is required?
*

View File

@ -40,7 +40,7 @@
</div>
<div class="box" id="<?= $this->printHtml($this->getId()); ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->printHtml($this->getId()); ?>-tagTemplate">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->getName()); ?>">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->name); ?>">
<i class="fa fa-times"></i>
<span data-tpl-text="/id" data-name="id" data-tpl-value="/id" data-value=""></span>
<span data-tpl-text="/name" data-tpl-value="/name" data-value=""></span>

View File

@ -44,7 +44,7 @@ class PositionTagSelectorView extends View
* @var string
* @since 1.0.0
*/
private string $name = '';
public string $name = '';
/**
* Is required
@ -78,18 +78,6 @@ class PositionTagSelectorView extends View
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Is required?
*

View File

@ -40,7 +40,7 @@
</div>
<div class="box" id="<?= $this->printHtml($this->getId()); ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->printHtml($this->getId()); ?>-tagTemplate">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->getName()); ?>">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->name); ?>">
<i class="fa fa-times"></i>
<span data-tpl-text="/id" data-name="id" data-tpl-value="/id" data-value=""></span>
<span data-tpl-text="/name" data-tpl-value="/name" data-value=""></span>

View File

@ -44,7 +44,7 @@ class UnitTagSelectorView extends View
* @var string
* @since 1.0.0
*/
private string $name = '';
public string $name = '';
/**
* Is required
@ -90,18 +90,6 @@ class UnitTagSelectorView extends View
return $this->isRequired;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* {@inheritdoc}
*/

View File

@ -40,7 +40,7 @@
</div>
<div class="box" id="<?= $this->printHtml($this->getId()); ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->printHtml($this->getId()); ?>-tagTemplate">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->getName()); ?>">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->name); ?>">
<i class="fa fa-times"></i>
<span data-tpl-text="/id" data-name="id" data-tpl-value="/id" data-value=""></span>
<span data-tpl-text="/name" data-tpl-value="/name" data-value=""></span>

View File

@ -38,12 +38,12 @@ echo $this->getData('nav')->render(); ?>
<td><?= $this->getHtml('Unit'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<?php $c = 0; foreach ($departments as $key => $value) : ++$c;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}organization/department/profile?{?}&id=' . $value->getId()); ?>
$url = UriFactory::build('{/prefix}organization/department/profile?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getParent()->getName()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getUnit()->getName()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->parent->name); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->unit->name); ?></a>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr>

View File

@ -30,7 +30,7 @@ echo $this->getData('nav')->render(); ?>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($department->getName()); ?>">
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($department->name); ?>">
<tr><td><label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<tr><td><?= $this->getData('department-selector')->render('iParent', 'parent', false); ?>
<tr><td><label for="iUnit"><?= $this->getHtml('Unit'); ?></label>
@ -45,8 +45,8 @@ echo $this->getData('nav')->render(); ?>
'department-editor',
'description',
'iDepartment',
$department->getDescriptionRaw(),
$department->getDescription()
$department->descriptionRaw,
$department->description
); ?>
</table>
</div>

View File

@ -28,7 +28,7 @@ $unitRoot = $unitTree[null][0]['children'];
<?php foreach ($unitRoot as $unitEle) : ?>
<div class="row">
<?php while (!empty($unitEle) && $unitEle['obj'] !== null) {
$unitTree[null][$unitEle['obj']->getParent()->getId()]['index'] = $unitTree[null][$unitEle['obj']->getParent()->getId()]['index'] + 1;
$unitTree[null][$unitEle['obj']->parent->getId()]['index'] = $unitTree[null][$unitEle['obj']->parent->getId()]['index'] + 1;
?>
<?php while (!empty($unitEle)) {
$unitId = $unitEle['obj']->getId(); ?>
@ -42,7 +42,7 @@ $unitRoot = $unitTree[null][0]['children'];
$depRoot = $depTree[$unitId][0]['children'] ?? []; foreach ($depRoot as $depEle) : ?>
<div class="row" style="margin: 0 auto;">
<?php while (!empty($depEle) && $depEle['obj'] !== null) {
$depTree[$unitId][$depEle['obj']->getParent()->getId()]['index'] = $depTree[$unitId][$depEle['obj']->getParent()->getId()]['index'] + 1;
$depTree[$unitId][$depEle['obj']->parent->getId()]['index'] = $depTree[$unitId][$depEle['obj']->parent->getId()]['index'] + 1;
?>
<?php while (!empty($depEle)) { ?>
<div class="departments">
@ -58,9 +58,9 @@ $unitRoot = $unitTree[null][0]['children'];
foreach ($posRoot as $posEle) : ?>
<?php while (!empty($posEle) && $posEle['obj'] !== null) {
if (isset($posTree[$depId][$posEle['obj']->getParent()->getId()])) {
if (isset($posTree[$depId][$posEle['obj']->parent->getId()])) {
// here is a bug or somewhere else... the index is not moved correctly $c is always 0
$posTree[$depId][$posEle['obj']->getParent()->getId()]['index'] = $posTree[$depId][$posEle['obj']->getParent()->getId()]['index'] + $c + 1;
$posTree[$depId][$posEle['obj']->parent->getId()]['index'] = $posTree[$depId][$posEle['obj']->parent->getId()]['index'] + $c + 1;
}
$c = 0; while (!empty($posEle)) { ?>
@ -87,7 +87,7 @@ $unitRoot = $unitTree[null][0]['children'];
do {
++$toCloseDep;
$parentDep = $parentDep->getParent();
$parentDep = $parentDep->parent;
$parentDepId = $parentDep->getId();
} while ($parentDepId !== 0
&& !isset($depTree[$unitId][$parentDepId]['children'][($depTree[$unitId][$parentDepId]['index'] ?? 0) + 1])
@ -115,7 +115,7 @@ $unitRoot = $unitTree[null][0]['children'];
do {
++$toCloseUnit;
$parentUnit = $parentUnit->getParent();
$parentUnit = $parentUnit->parent;
$parentUnitId = $parentUnit->getId();
} while ($parentUnitId !== 0
&& !isset($unitTree[null][$parentUnitId]['children'][($unitTree[null][$parentUnitId]['index'] ?? 0) + 1])

View File

@ -41,9 +41,9 @@ echo $this->getData('nav')->render(); ?>
$url = \phpOMS\Uri\UriFactory::build('{/prefix}organization/position/profile?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getParent()->getName()); ?></a>
<td data-label="<?= $this->getHtml('Department'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getDepartment()->getName()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->parent->name); ?></a>
<td data-label="<?= $this->getHtml('Department'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->department->name); ?></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>

View File

@ -30,7 +30,7 @@ echo $this->getData('nav')->render(); ?>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($position->getName()); ?>">
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($position->name); ?>">
<tr><td><label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<tr><td><?= $this->getData('position-selector')->render('iParent', 'parent', false); ?>
<tr><td><label for="iDepartment"><?= $this->getHtml('Department'); ?></label>
@ -45,8 +45,8 @@ echo $this->getData('nav')->render(); ?>
'position-editor',
'description',
'iPosition',
$position->getDescriptionRaw(),
$position->getDescription()
$position->descriptionRaw,
$position->description
); ?>
</table>
</div>

View File

@ -42,11 +42,11 @@ echo $this->getData('nav')->render(); ?>
$url = UriFactory::build('{/prefix}organization/unit/profile?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a>
<td><a href="<?= $url; ?>"><img class="profile-image" src="<?= $value->getImage() instanceof NullMedia ?
<td><a href="<?= $url; ?>"><img class="profile-image" src="<?= $value->image instanceof NullMedia ?
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
UriFactory::build('{/prefix}' . $value->getImage()->getPath()); ?>"></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getParent()->getName()); ?></a>
UriFactory::build('{/prefix}' . $value->image->getPath()); ?>"></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<td data-label="<?= $this->getHtml('Parent'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->parent->name); ?></a>
<?php endforeach; ?>
</table>
<div class="portlet-foot">

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
use Modules\Media\Models\NullMedia;
use phpOMS\Uri\UriFactory;
use Modules\Organization\Models\Status;
/**
* @var \phpOMS\Views\View $this
@ -36,9 +37,9 @@ echo $this->getData('nav')->render(); ?>
alt="<?= $this->getHtml('Logo'); ?>"
itemprop="logo" loading="lazy"
src="<?=
$unit->getImage() instanceof NullMedia ?
$unit->image instanceof NullMedia ?
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
UriFactory::build('{/prefix}' . $unit->getImage()->getPath()); ?>"
UriFactory::build('{/prefix}' . $unit->image->getPath()); ?>"
width="40x">
</a>
</div>
@ -47,21 +48,21 @@ echo $this->getData('nav')->render(); ?>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($unit->getName()); ?>">
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($unit->name); ?>">
<tr><td><label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<tr><td><?= $this->getData('unit-selector')->render('iParent', 'parent', false); ?>
<tr><td><label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<tr><td><select name="status" id="iStatus">
<option value="<?= $this->printHtml(\Modules\Organization\Models\Status::ACTIVE); ?>"<?= \Modules\Organization\Models\Status::ACTIVE === $unit->getStatus() ? ' selected' : ''; ?>><?= $this->getHtml('Active'); ?>
<option value="<?= $this->printHtml(\Modules\Organization\Models\Status::INACTIVE); ?>"<?= \Modules\Organization\Models\Status::INACTIVE === $unit->getStatus() ? ' selected' : ''; ?>><?= $this->getHtml('Inactive'); ?>
<option value="<?= $this->printHtml(Status::ACTIVE); ?>"<?= Status::ACTIVE === $unit->getStatus() ? ' selected' : ''; ?>><?= $this->getHtml('Active'); ?>
<option value="<?= $this->printHtml(Status::INACTIVE); ?>"<?= Status::INACTIVE === $unit->getStatus() ? ' selected' : ''; ?>><?= $this->getHtml('Inactive'); ?>
</select>
<tr><td><?= $this->getData('editor')->render('unit-editor'); ?>
<tr><td><?= $this->getData('editor')->getData('text')->render(
'unit-editor',
'description',
'iUnit',
$unit->getDescriptionRaw(),
$unit->getDescription()
$unit->descriptionRaw,
$unit->description
); ?>
</table>
</div>

View File

@ -91,12 +91,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', '1');
$this->module->apiUnitGet($request, $response);
self::assertEquals('Orange-Management', $response->get('')['response']->getName());
self::assertEquals('Orange-Management', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
}
@ -109,14 +109,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', '1');
$request->setData('name', 'OMS');
$this->module->apiUnitSet($request, $response);
$this->module->apiUnitGet($request, $response);
self::assertEquals('OMS', $response->get('')['response']->getName());
self::assertEquals('OMS', $response->get('')['response']->name);
}
/**
@ -128,12 +128,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('search', 'OMS');
$this->module->apiUnitFind($request, $response);
self::assertEquals('OMS', $response->get('')[0]->getName());
self::assertEquals('OMS', $response->get('')[0]->name);
self::assertGreaterThan(0, $response->get('')[0]->getId());
}
@ -146,14 +146,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('name', 'test');
$request->setData('status', Status::INACTIVE);
$request->setData('description', 'test description');
$this->module->apiUnitCreate($request, $response);
self::assertEquals('test', $response->get('')['response']->getName());
self::assertEquals('test', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
// test delete
@ -172,11 +172,11 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$this->module->apiUnitCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode());
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
protected static $departmentId = 0;
@ -190,7 +190,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('name', 'test');
$request->setData('status', Status::INACTIVE);
$request->setData('unit', 1);
@ -198,7 +198,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$this->module->apiDepartmentCreate($request, $response);
self::assertEquals('test', $response->get('')['response']->getName());
self::assertEquals('test', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
self::$departmentId = $response->get('')['response']->getId();
@ -213,12 +213,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('search', 'test');
$this->module->apiDepartmentFind($request, $response);
self::assertEquals('test', $response->get('')[0]->getName());
self::assertEquals('test', $response->get('')[0]->name);
self::assertGreaterThan(0, $response->get('')[0]->getId());
}
@ -231,11 +231,11 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$this->module->apiDepartmentCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode());
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
/**
@ -247,12 +247,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$departmentId);
$this->module->apiDepartmentGet($request, $response);
self::assertEquals('test', $response->get('')['response']->getName());
self::assertEquals('test', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
}
@ -265,14 +265,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$departmentId);
$request->setData('name', 'Production');
$this->module->apiDepartmentSet($request, $response);
$this->module->apiDepartmentGet($request, $response);
self::assertEquals('Production', $response->get('')['response']->getName());
self::assertEquals('Production', $response->get('')['response']->name);
}
/**
@ -284,7 +284,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$departmentId);
$this->module->apiDepartmentDelete($request, $response);
@ -302,14 +302,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('name', 'test');
$request->setData('status', Status::INACTIVE);
$request->setData('description', 'test description');
$this->module->apiPositionCreate($request, $response);
self::assertEquals('test', $response->get('')['response']->getName());
self::assertEquals('test', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
self::$positionId = $response->get('')['response']->getId();
}
@ -323,12 +323,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('search', 'test');
$this->module->apiPositionFind($request, $response);
self::assertEquals('test', $response->get('')[0]->getName());
self::assertEquals('test', $response->get('')[0]->name);
self::assertGreaterThan(0, $response->get('')[0]->getId());
}
@ -341,11 +341,11 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$this->module->apiPositionCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode());
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
/**
@ -357,12 +357,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$positionId);
$this->module->apiPositionGet($request, $response);
self::assertEquals('test', $response->get('')['response']->getName());
self::assertEquals('test', $response->get('')['response']->name);
self::assertGreaterThan(0, $response->get('')['response']->getId());
}
@ -375,14 +375,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$positionId);
$request->setData('name', 'Test');
$this->module->apiPositionSet($request, $response);
$this->module->apiPositionGet($request, $response);
self::assertEquals('Test', $response->get('')['response']->getName());
self::assertEquals('Test', $response->get('')['response']->name);
}
/**
@ -394,7 +394,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('id', self::$positionId);
$this->module->apiPositionDelete($request, $response);
@ -412,7 +412,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->getHeader()->setAccount(1);
$request->header->account = 1;
$request->setData('name', 'Organization Logo');
$request->setData('id', 1);
@ -427,8 +427,8 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
]);
$this->module->apiUnitImageSet($request, $response);
$image = UnitMapper::get(1)->getImage();
self::assertEquals('Organization Logo', $image->getName());
$image = UnitMapper::get(1)->image;
self::assertEquals('Organization Logo', $image->name);
}
/**
@ -442,6 +442,6 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
$this->module->apiUnitImageSet($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode());
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
}

View File

@ -31,18 +31,18 @@ class DepartmentMapperTest extends \PHPUnit\Framework\TestCase
public function testCRUD() : void
{
$department = new Department();
$department->setName('Management');
$department->setDescription('Description');
$department->setUnit(new NullUnit(1));
$department->name = 'Management';
$department->description = 'Description';
$department->unit = new NullUnit(1);
$id = DepartmentMapper::create($department);
$departmentR = DepartmentMapper::get($id);
self::assertEquals($id, $departmentR->getId());
self::assertEquals($department->getName(), $departmentR->getName());
self::assertEquals($department->getDescription(), $departmentR->getDescription());
self::assertInstanceOf('Modules\Organization\Models\NullDepartment', $departmentR->getParent());
self::assertEquals($department->getUnit()->getId(), $departmentR->getUnit()->getId());
self::assertEquals($department->name, $departmentR->name);
self::assertEquals($department->description, $departmentR->description);
self::assertInstanceOf('Modules\Organization\Models\NullDepartment', $departmentR->parent);
self::assertEquals($department->unit->getId(), $departmentR->unit->getId());
}
/**
@ -57,66 +57,66 @@ class DepartmentMapperTest extends \PHPUnit\Framework\TestCase
/* 2 */
$department = new Department();
$department->setName('HR');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'HR';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 3 */
$department = new Department();
$department->setName('QM');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'QM';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 4 */
$department = new Department();
$department->setName('Sales');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'Sales';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 5 */
$department = new Department();
$department->setName('Shipping');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first + 3));
$department->setUnit(new NullUnit(1));
$department->name = 'Shipping';
$department->description = 'Description';
$department->parent = new NullDepartment($first + 3);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 6 */
$department = new Department();
$department->setName('Purchase');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'Purchase';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 7 */
$department = new Department();
$department->setName('Arrival');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first + 5));
$department->setUnit(new NullUnit(1));
$department->name = 'Arrival';
$department->description = 'Description';
$department->parent = new NullDepartment($first + 5);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 8 */
$department = new Department();
$department->setName('Accounting');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'Accounting';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
/* 9 */
$department = new Department();
$department->setName('Production');
$department->setDescription('Description');
$department->setParent(new NullDepartment($first));
$department->setUnit(new NullUnit(1));
$department->name = 'Production';
$department->description = 'Description';
$department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1);
DepartmentMapper::create($department);
}
}

View File

@ -38,11 +38,11 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertEquals(0, $this->department->getId());
self::assertEquals('', $this->department->getName());
self::assertEquals('', $this->department->getDescription());
self::assertEquals('', $this->department->getDescriptionRaw());
self::assertInstanceOf(NullDepartment::class, $this->department->getParent());
self::assertEquals(0, $this->department->getUnit()->getId());
self::assertEquals('', $this->department->name);
self::assertEquals('', $this->department->description);
self::assertEquals('', $this->department->descriptionRaw);
self::assertInstanceOf(NullDepartment::class, $this->department->parent);
self::assertEquals(0, $this->department->unit->getId());
self::assertEquals(Status::INACTIVE, $this->department->getStatus());
}
@ -52,8 +52,8 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testNameInputOutput() : void
{
$this->department->setName('Name');
self::assertEquals('Name', $this->department->getName());
$this->department->name = 'Name';
self::assertEquals('Name', $this->department->name);
}
/**
@ -62,8 +62,8 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionInputOutput() : void
{
$this->department->setDescription('Description');
self::assertEquals('Description', $this->department->getDescription());
$this->department->description = 'Description';
self::assertEquals('Description', $this->department->description);
}
/**
@ -72,8 +72,8 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionRawInputOutput() : void
{
$this->department->setDescriptionRaw('DescriptionRaw');
self::assertEquals('DescriptionRaw', $this->department->getDescriptionRaw());
$this->department->descriptionRaw = 'DescriptionRaw';
self::assertEquals('DescriptionRaw', $this->department->descriptionRaw);
}
/**
@ -92,8 +92,8 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testParentInputOutput() : void
{
$this->department->setParent(new NullDepartment(1));
self::assertEquals(1, $this->department->getParent()->getId());
$this->department->parent = new NullDepartment(1);
self::assertEquals(1, $this->department->parent->getId());
}
/**
@ -102,8 +102,8 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testUnitInputOutput() : void
{
$this->department->setUnit(new NullUnit(1));
self::assertEquals(1, $this->department->getUnit()->getId());
$this->department->unit = new NullUnit(1);
self::assertEquals(1, $this->department->unit->getId());
}
/**
@ -112,12 +112,12 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->department->setName('Name');
$this->department->setDescription('Description');
$this->department->setDescriptionRaw('DescriptionRaw');
$this->department->name = 'Name';
$this->department->description = 'Description';
$this->department->descriptionRaw = 'DescriptionRaw';
$this->department->setStatus(Status::ACTIVE);
$this->department->setParent($p = new NullDepartment(1));
$this->department->setUnit($u = new NullUnit(1));
$this->department->parent = ($p = new NullDepartment(1));
$this->department->unit = ($u = new NullUnit(1));
self::assertEquals($this->department->toArray(), $this->department->jsonSerialize());
self::assertEquals(

View File

@ -30,16 +30,16 @@ class PositionMapperTest extends \PHPUnit\Framework\TestCase
public function testCRUD() : void
{
$position = new Position();
$position->setName('CEO');
$position->setDescription('Description');
$position->name = 'CEO';
$position->description = 'Description';
$id = PositionMapper::create($position);
$positionR = PositionMapper::get($id);
self::assertEquals($id, $positionR->getId());
self::assertEquals($position->getName(), $positionR->getName());
self::assertEquals($position->getDescription(), $positionR->getDescription());
self::assertInstanceOf('Modules\Organization\Models\NullPosition', $positionR->getParent());
self::assertEquals($position->name, $positionR->name);
self::assertEquals($position->description, $positionR->description);
self::assertInstanceOf('Modules\Organization\Models\NullPosition', $positionR->parent);
}
/**
@ -54,58 +54,58 @@ class PositionMapperTest extends \PHPUnit\Framework\TestCase
/* 4 */
$position = new Position();
$position->setName('CFO');
$position->setDescription('Description');
$position->setParent(new NullPosition($first));
$position->name = 'CFO';
$position->description = 'Description';
$position->parent = new NullPosition($first);
$id = PositionMapper::create($position);
/* 5 */
$position = new Position();
$position->setName('Accountant');
$position->setDescription('Description');
$position->setParent(new NullPosition($id));
$position->name = 'Accountant';
$position->description = 'Description';
$position->parent = new NullPosition($id);
PositionMapper::create($position);
/* 6 */
$position = new Position();
$position->setName('Controller');
$position->setDescription('Description');
$position->setParent(new NullPosition($id));
$position->name = 'Controller';
$position->description = 'Description';
$position->parent = new NullPosition($id);
PositionMapper::create($position);
/* 7 */
$position = new Position();
$position->setName('Sales Director');
$position->setDescription('Description');
$position->setParent(new NullPosition($first));
$position->name = 'Sales Director';
$position->description = 'Description';
$position->parent = new NullPosition($first);
PositionMapper::create($position);
/* 8 */
$position = new Position();
$position->setName('Purchase Director');
$position->setDescription('Description');
$position->setParent(new NullPosition($first));
$position->name = 'Purchase Director';
$position->description = 'Description';
$position->parent = new NullPosition($first);
PositionMapper::create($position);
/* 9 */
$position = new Position();
$position->setName('Territory Manager');
$position->setDescription('Description');
$position->setParent(new NullPosition($first + 4));
$position->name = 'Territory Manager';
$position->description = 'Description';
$position->parent = new NullPosition($first + 4);
PositionMapper::create($position);
/* 10 */
$position = new Position();
$position->setName('Territory Sales Assistant');
$position->setDescription('Description');
$position->setParent(new NullPosition($first + 6));
$position->name = 'Territory Sales Assistant';
$position->description = 'Description';
$position->parent = new NullPosition($first + 6);
PositionMapper::create($position);
/* 11 */
$position = new Position();
$position->setName('Domestic Sales Manager');
$position->setDescription('Description');
$position->setParent(new NullPosition($first + 4));
$position->name = 'Domestic Sales Manager';
$position->description = 'Description';
$position->parent = new NullPosition($first + 4);
PositionMapper::create($position);
}
}

View File

@ -38,11 +38,11 @@ class PositionTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertEquals(0, $this->position->getId());
self::assertEquals('', $this->position->getName());
self::assertEquals('', $this->position->getDescription());
self::assertEquals('', $this->position->getDescriptionRaw());
self::assertInstanceOf(NullPosition::class, $this->position->getParent());
self::assertEquals(0, $this->position->getDepartment()->getId());
self::assertEquals('', $this->position->name);
self::assertEquals('', $this->position->description);
self::assertEquals('', $this->position->descriptionRaw);
self::assertInstanceOf(NullPosition::class, $this->position->parent);
self::assertEquals(0, $this->position->department->getId());
self::assertEquals(Status::INACTIVE, $this->position->getStatus());
}
@ -52,8 +52,8 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testNameInputOutput() : void
{
$this->position->setName('Name');
self::assertEquals('Name', $this->position->getName());
$this->position->name = 'Name';
self::assertEquals('Name', $this->position->name);
}
/**
@ -62,8 +62,8 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionInputOutput() : void
{
$this->position->setDescription('Description');
self::assertEquals('Description', $this->position->getDescription());
$this->position->description = 'Description';
self::assertEquals('Description', $this->position->description);
}
/**
@ -72,8 +72,8 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionRawInputOutput() : void
{
$this->position->setDescriptionRaw('DescriptionRaw');
self::assertEquals('DescriptionRaw', $this->position->getDescriptionRaw());
$this->position->descriptionRaw = 'DescriptionRaw';
self::assertEquals('DescriptionRaw', $this->position->descriptionRaw);
}
/**
@ -92,8 +92,8 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testParentInputOutput() : void
{
$this->position->setParent(new NullPosition(1));
self::assertEquals(1, $this->position->getParent()->getId());
$this->position->parent = new NullPosition(1);
self::assertEquals(1, $this->position->parent->getId());
}
/**
@ -102,8 +102,8 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testDepartmentInputOutput() : void
{
$this->position->setDepartment(new NullDepartment(1));
self::assertEquals(1, $this->position->getDepartment()->getId());
$this->position->department = new NullDepartment(1);
self::assertEquals(1, $this->position->department->getId());
}
/**
@ -112,12 +112,12 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->position->setName('Name');
$this->position->setDescription('Description');
$this->position->setDescriptionRaw('DescriptionRaw');
$this->position->name = 'Name';
$this->position->description = 'Description';
$this->position->descriptionRaw = 'DescriptionRaw';
$this->position->setStatus(Status::ACTIVE);
$this->position->setParent($p = new NullPosition(1));
$this->position->setDepartment($d = new NullDepartment(1));
$this->position->parent = ($p = new NullPosition(1));
$this->position->department = ($d = new NullDepartment(1));
self::assertEquals($this->position->toArray(), $this->position->jsonSerialize());
self::assertEquals(

View File

@ -30,16 +30,16 @@ class UnitMapperTest extends \PHPUnit\Framework\TestCase
public function testCRUD() : void
{
$unit = new Unit();
$unit->setName('Scrooge Inc.');
$unit->setDescription('Description');
$unit->setParent(new NullUnit(1));
$unit->name = 'Scrooge Inc.';
$unit->description = 'Description';
$unit->parent = new NullUnit(1);
$id = UnitMapper::create($unit);
$unitR = UnitMapper::get($id);
self::assertEquals($id, $unitR->getId());
self::assertEquals($unit->getName(), $unitR->getName());
self::assertEquals($unit->getDescription(), $unitR->getDescription());
self::assertEquals($unit->getParent()->getId(), $unitR->getParent()->getId());
self::assertEquals($unit->name, $unitR->name);
self::assertEquals($unit->description, $unitR->description);
self::assertEquals($unit->parent->getId(), $unitR->parent->getId());
}
}

View File

@ -38,11 +38,11 @@ class UnitTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertEquals(0, $this->unit->getId());
self::assertEquals('', $this->unit->getName());
self::assertEquals('', $this->unit->getDescription());
self::assertEquals('', $this->unit->getDescriptionRaw());
self::assertInstanceOf('Modules\Organization\Models\NullUnit', $this->unit->getParent());
self::assertInstanceOf('Modules\Media\Models\NullMedia', $this->unit->getImage());
self::assertEquals('', $this->unit->name);
self::assertEquals('', $this->unit->description);
self::assertEquals('', $this->unit->descriptionRaw);
self::assertInstanceOf('Modules\Organization\Models\NullUnit', $this->unit->parent);
self::assertInstanceOf('Modules\Media\Models\NullMedia', $this->unit->image);
self::assertEquals(Status::INACTIVE, $this->unit->getStatus());
}
@ -52,8 +52,8 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testNameInputOutput() : void
{
$this->unit->setName('Name');
self::assertEquals('Name', $this->unit->getName());
$this->unit->name = 'Name';
self::assertEquals('Name', $this->unit->name);
}
/**
@ -72,8 +72,8 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionInputOutput() : void
{
$this->unit->setDescription('Description');
self::assertEquals('Description', $this->unit->getDescription());
$this->unit->description = 'Description';
self::assertEquals('Description', $this->unit->description);
}
/**
@ -82,8 +82,8 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testDescriptionRawInputOutput() : void
{
$this->unit->setDescriptionRaw('DescriptionRaw');
self::assertEquals('DescriptionRaw', $this->unit->getDescriptionRaw());
$this->unit->descriptionRaw = 'DescriptionRaw';
self::assertEquals('DescriptionRaw', $this->unit->descriptionRaw);
}
/**
@ -92,8 +92,8 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testParentInputOutput() : void
{
$this->unit->setParent(new NullUnit(1));
self::assertEquals(1, $this->unit->getParent()->getId());
$this->unit->parent = new NullUnit(1);
self::assertEquals(1, $this->unit->parent->getId());
}
/**
@ -102,8 +102,8 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testImageInputOutput() : void
{
$this->unit->setImage(new NullMedia(1));
self::assertEquals(1, $this->unit->getImage()->getId());
$this->unit->image = new NullMedia(1);
self::assertEquals(1, $this->unit->image->getId());
}
/**
@ -112,12 +112,12 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->unit->setName('Name');
$this->unit->setDescription('Description');
$this->unit->setDescriptionRaw('DescriptionRaw');
$this->unit->name = 'Name';
$this->unit->description = 'Description';
$this->unit->descriptionRaw = 'DescriptionRaw';
$this->unit->setStatus(Status::ACTIVE);
$this->unit->setParent($p = new NullUnit(1));
$this->unit->setImage($i = new NullMedia(1));
$this->unit->parent = ($p = new NullUnit(1));
$this->unit->image = ($i = new NullMedia(1));
self::assertEquals($this->unit->toArray(), $this->unit->jsonSerialize());
self::assertEquals(