From 93e6d2175c757f1b12c9a9d6c689fffb9b2e7388 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Nov 2020 17:31:20 +0100 Subject: [PATCH] remove some getter/setter --- Controller/ApiController.php | 22 ++++++------ Models/Employee.php | 43 ++---------------------- Models/EmployeeMapper.php | 14 ++++++++ Theme/Backend/department-list.tpl.php | 4 +-- Theme/Backend/planning-dashboard.tpl.php | 12 +++---- Theme/Backend/staff-list.tpl.php | 2 +- Theme/Backend/staff-single.tpl.php | 29 ++++++++-------- tests/Models/EmployeeMapperTest.php | 6 ++-- tests/Models/EmployeeTest.php | 2 +- 9 files changed, 56 insertions(+), 78 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index a30d2fe..e972905 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -77,13 +77,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateEmployeeFromAccountCreate($request))) { $response->set('employee_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $employees = $this->createEmployeeFromAccountFromRequest($request); - $this->createModels($request->getHeader()->getAccount(), $employees, EmployeeMapper::class, 'employee', $request->getOrigin()); + $this->createModels($request->header->account, $employees, EmployeeMapper::class, 'employee', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Employee', 'Employee(s) successfully created', $employees); } @@ -144,13 +144,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateEmployeeNewCreate($request))) { $response->set('employee_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $employee = $this->createEmployeeNewFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $employee, EmployeeMapper::class, 'employee', $request->getOrigin()); + $this->createModel($request->header->account, $employee, EmployeeMapper::class, 'employee', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Employee', 'Employee successfully created', $employee); } @@ -185,13 +185,13 @@ final class ApiController extends Controller private function createEmployeeNewFromRequest(RequestAbstract $request) : Employee { $account = new Account(); - $account->setName1((string) ($request->getData('name1') ?? '')); - $account->setName2((string) ($request->getData('name2') ?? '')); - $account->setName3((string) ($request->getData('name3') ?? '')); - $account->setName3((string) ($request->getData('email') ?? '')); + $account->name1 = (string) ($request->getData('name1') ?? ''); + $account->name2 = (string) ($request->getData('name2') ?? ''); + $account->name3 = (string) ($request->getData('name3') ?? ''); + $account->name3 = (string) ($request->getData('email') ?? ''); $profile = new Profile($account); - $profile->setBirthday(new \DateTime((string) ($request->getData('birthday') ?? 'now'))); + $profile->birthday = new \DateTime((string) ($request->getData('birthday') ?? 'now')); $employee = new Employee($profile); @@ -215,13 +215,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateEmployeeHistoryCreate($request))) { $response->set('history_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $history = $this->createEmployeeHistoryFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $history, EmployeeHistoryMapper::class, 'history', $request->getOrigin()); + $this->createModel($request->header->account, $history, EmployeeHistoryMapper::class, 'history', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'History', 'History successfully created', $history); } diff --git a/Models/Employee.php b/Models/Employee.php index c6f313c..ec923eb 100755 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -43,7 +43,7 @@ class Employee implements \JsonSerializable, ArrayableInterface * @var null|int|Profile * @since 1.0.0 */ - private $profile = null; + public $profile = null; /** * Employee image. @@ -51,7 +51,7 @@ class Employee implements \JsonSerializable, ArrayableInterface * @var null|int|Media * @since 1.0.0 */ - private $image = null; + public $image = null; /** * Employee department/position history. @@ -110,6 +110,7 @@ class Employee implements \JsonSerializable, ArrayableInterface { $this->profile = $profile; $this->semiPrivateHash = \random_bytes(self::SEMI_PRIVATE_HASH_LENGTH); + $this->image = new NullMedia(); } /** @@ -124,44 +125,6 @@ class Employee implements \JsonSerializable, ArrayableInterface return $this->id; } - /** - * Get profile. - * - * @return null|int|Profile - * - * @since 1.0.0 - */ - public function getProfile() - { - return $this->profile; - } - - /** - * Get image. - * - * @return int|Media - * - * @since 1.0.0 - */ - public function getImage() - { - return $this->image ?? new NullMedia(); - } - - /** - * Set image. - * - * @param null|int|Media $image Employee image - * - * @return void - * - * @since 1.0.0 - */ - public function setImage($image) : void - { - $this->image = $image; - } - /** * Update semi private hash. * diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index cc9298a..eb33215 100755 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -18,6 +18,7 @@ use Modules\Admin\Models\AccountMapper; use Modules\Profile\Models\ProfileMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Query\Builder; +use Modules\Media\Models\MediaMapper; /** * Employe mapper class. @@ -55,6 +56,19 @@ final class EmployeeMapper extends DataMapperAbstract ], ]; + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $ownsOne = [ + 'image' => [ + 'mapper' => MediaMapper::class, + 'external' => 'hr_staff_image', + ], + ]; + /** * Has many relation. * diff --git a/Theme/Backend/department-list.tpl.php b/Theme/Backend/department-list.tpl.php index a6fe11c..9fa08a2 100755 --- a/Theme/Backend/department-list.tpl.php +++ b/Theme/Backend/department-list.tpl.php @@ -43,9 +43,9 @@ echo $this->getData('nav')->render(); ?> $url = \phpOMS\Uri\UriFactory::build('{/prefix}hr/department/single?{?}&id=' . $value->getId()); ?> printHtml($value->getId()); ?> - printHtml($value->getName()); ?> + printHtml($value->name); ?> - printHtml($value->getParent()->getName()); ?> + printHtml($value->parent->getName()); ?> getHtml('Empty', '0', '0'); ?> diff --git a/Theme/Backend/planning-dashboard.tpl.php b/Theme/Backend/planning-dashboard.tpl.php index 6651cca..3cdc584 100755 --- a/Theme/Backend/planning-dashboard.tpl.php +++ b/Theme/Backend/planning-dashboard.tpl.php @@ -1,5 +1,5 @@
-

printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang['HumanResourceManagement']['Vacation']); ?>

+

printHtml($this->app->accountManager->get($request->header->account)->l11n->lang['HumanResourceManagement']['Vacation']); ?>

@@ -26,13 +26,13 @@
printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang[0]['More']); ?> + class="button">printHtml($this->app->accountManager->get($request->header->account)->l11n->lang[0]['More']); ?>
-

printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang['HumanResourceManagement']['Shifts']); ?>

+

printHtml($this->app->accountManager->get($request->header->account)->l11n->lang['HumanResourceManagement']['Shifts']); ?>

@@ -59,13 +59,13 @@
printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang[0]['More']); ?> + class="button">printHtml($this->app->accountManager->get($request->header->account)->l11n->lang[0]['More']); ?>
-

printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang['HumanResourceManagement']['Personnel']); ?>

+

printHtml($this->app->accountManager->get($request->header->account)->l11n->lang['HumanResourceManagement']['Personnel']); ?>

@@ -92,7 +92,7 @@
printHtml($this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->lang[0]['More']); ?> + class="button">printHtml($this->app->accountManager->get($request->header->account)->l11n->lang[0]['More']); ?>
diff --git a/Theme/Backend/staff-list.tpl.php b/Theme/Backend/staff-list.tpl.php index d16f1f2..2e2c93f 100755 --- a/Theme/Backend/staff-list.tpl.php +++ b/Theme/Backend/staff-list.tpl.php @@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); ?> printHtml($value->getId()); ?> printHtml( - \sprintf('%3$s %2$s %1$s', $value->getProfile()->getAccount()->getName1(), $value->getProfile()->getAccount()->getName2(), $value->getProfile()->getAccount()->getName3()) + \sprintf('%3$s %2$s %1$s', $value->profile->account->name1, $value->profile->account->name2, $value->profile->account->name3) ); ?> printHtml($value->getNewestHistory()->getUnit()->getName()); ?> printHtml($value->getNewestHistory()->getPosition()->getName()); ?> diff --git a/Theme/Backend/staff-single.tpl.php b/Theme/Backend/staff-single.tpl.php index e3509bd..7cbdae3 100755 --- a/Theme/Backend/staff-single.tpl.php +++ b/Theme/Backend/staff-single.tpl.php @@ -14,6 +14,7 @@ declare(strict_types=1); use Modules\Media\Models\NullMedia; use phpOMS\Uri\UriFactory; +use Modules\HumanResourceManagement\Models\NullEmployeeHistory; $employee = $this->getData('employee'); $history = $employee->getHistorY(); @@ -35,12 +36,12 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-1' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-1' ? ' checked' : ''; ?>>
-

printHtml($employee->getProfile()->getAccount()->getName2()); ?>, printHtml($employee->getProfile()->getAccount()->getName1()); ?>

+

printHtml($employee->profile->account->name2); ?>, printHtml($employee->profile->account->name1); ?>

@@ -48,11 +49,11 @@ echo $this->getData('nav')->render(); ?> alt="getHtml('ProfileImage'); ?>" itemprop="logo" loading="lazy" src="getImage() instanceof NullMedia ? - $employee->getProfile()->getImage() instanceof NullMedia ? + $employee->image instanceof NullMedia ? + $employee->profile->image instanceof NullMedia ? UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') : - UriFactory::build('{/prefix}' . $employee->getProfile()->getImage()->getPath()) : - UriFactory::build('{/prefix}' . $employee->getImage()->getPath()); ?>" + UriFactory::build('{/prefix}' . $employee->profile->image->getPath()) : + UriFactory::build('{/prefix}' . $employee->image->getPath()); ?>" > @@ -70,7 +71,7 @@ echo $this->getData('nav')->render(); ?>
06.09.1934
getHtml('Email'); ?> - printHtml($employee->getProfile()->getAccount()->getEmail()); ?> + printHtml($employee->profile->account->getEmail()); ?>
Address @@ -127,7 +128,7 @@ echo $this->getData('nav')->render(); ?> - request->getUri()->getFragment() === 'c-tab-2' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-2' ? ' checked' : ''; ?>>
@@ -139,7 +140,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-3' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-3' ? ' checked' : ''; ?>>
@@ -151,7 +152,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-4' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-4' ? ' checked' : ''; ?>>
@@ -163,7 +164,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-5' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-5' ? ' checked' : ''; ?>>
@@ -175,7 +176,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-6' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-6' ? ' checked' : ''; ?>>
@@ -187,7 +188,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-7' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-7' ? ' checked' : ''; ?>>
@@ -199,7 +200,7 @@ echo $this->getData('nav')->render(); ?>
- request->getUri()->getFragment() === 'c-tab-8' ? ' checked' : ''; ?>> + request->uri->fragment === 'c-tab-8' ? ' checked' : ''; ?>>
diff --git a/tests/Models/EmployeeMapperTest.php b/tests/Models/EmployeeMapperTest.php index 204c370..df5f457 100755 --- a/tests/Models/EmployeeMapperTest.php +++ b/tests/Models/EmployeeMapperTest.php @@ -34,8 +34,8 @@ class EmployeeMapperTest extends \PHPUnit\Framework\TestCase if (($profile = ProfileMapper::getFor(1, 'account'))->getId() === 0) { $profile = new Profile(); - $profile->setAccount(AccountMapper::get(1)); - $profile->setBirthday($date = new \DateTime('now')); + $profile->account = AccountMapper::get(1); + $profile->birthday = ($date = new \DateTime('now')); $id = ProfileMapper::create($profile); } @@ -47,6 +47,6 @@ class EmployeeMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($id, $employee->getId()); $employeeR = EmployeeMapper::get($employee->getId()); - self::assertEquals($employee->getProfile()->getId(), $employeeR->getProfile()->getId()); + self::assertEquals($employee->profile->getId(), $employeeR->profile->getId()); } } diff --git a/tests/Models/EmployeeTest.php b/tests/Models/EmployeeTest.php index c6dea8e..195d138 100755 --- a/tests/Models/EmployeeTest.php +++ b/tests/Models/EmployeeTest.php @@ -32,7 +32,7 @@ class EmployeeTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $employee->getId()); self::assertGreaterThan(0, \strlen($employee->getSemiPrivateHash())); self::assertFalse($employee->compareSemiPrivateHash('123')); - self::assertInstanceOf('\Modules\Media\Models\NullMedia', $employee->getImage()); + self::assertInstanceOf('\Modules\Media\Models\NullMedia', $employee->image); self::assertInstanceOf('\Modules\HumanResourceManagement\Models\NullEmployeeHistory', $employee->getNewestHistory()); self::assertEquals([], $employee->getHistory()); self::assertEquals([], $employee->getEducationHistory());