From d55ccb853abaec1361b832af0391d5f441ce01dd Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 6 Oct 2019 17:50:44 +0200 Subject: [PATCH] prepare for timerecording module --- Admin/Install/db.json | 21 +- Controller/ApiController.php | 11 +- Models/Employee.php | 41 +++- Models/EmployeeHistory.php | 31 ++- Models/EmployeeMapper.php | 9 +- Theme/Backend/Lang/en.lang.php | 4 +- Theme/Backend/department-list.tpl.php | 4 +- Theme/Backend/staff-create.tpl.php | 4 +- Theme/Backend/staff-list.tpl.php | 27 ++- Theme/Backend/staff-single.tpl.php | 280 ++++++++++++++++++-------- info.json | 6 +- 11 files changed, 313 insertions(+), 125 deletions(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 95b8eda..d6037bb 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -9,17 +9,28 @@ "primary": true, "autoincrement": true }, - "hr_staff_account": { - "name": "hr_staff_account", + "hr_staff_profile": { + "name": "hr_staff_profile", "type": "INT", "null": false, - "foreignTable": "account", - "foreignKey": "account_id" + "foreignTable": "profile_account", + "foreignKey": "profile_account_id" }, "hr_staff_smiPHash": { "name": "hr_staff_smiPHash", - "type": "VARCHAR(256)", + "type": "VARBINARY(255)", "null": false + }, + "hr_staff_image": { + "name": "hr_staff_image", + "type": "INT", + "default": null, + "null": true, + "foreignTable": "media", + "foreignKey": "media_id", + "annotations": { + "gdpr": true + } } } }, diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c3e4f52..46ce083 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -19,7 +19,6 @@ use Modules\HumanResourceManagement\Models\EmployeeMapper; use Modules\HumanResourceManagement\Models\EmployeeHistory; use Modules\HumanResourceManagement\Models\EmployeeHistoryMapper; -use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -53,7 +52,7 @@ final class ApiController extends Controller */ public function apiEmployeeCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { - if ($request->getData('accounts') !== null) { + if ($request->getData('profiles') !== null) { $this->apiEmployeeFromAccountCreate($request, $response, $data); } @@ -87,7 +86,7 @@ final class ApiController extends Controller } /** - * Validate employee from account create request + * Validate employee from profile create request * * @param RequestAbstract $request Request * @@ -98,7 +97,7 @@ final class ApiController extends Controller private function validateEmployeeFromAccountCreate(RequestAbstract $request) : array { $val = []; - if (($val['account'] = empty($request->getData('account')))) { + if (($val['profile'] = empty($request->getData('profiles')))) { return $val; } @@ -106,7 +105,7 @@ final class ApiController extends Controller } /** - * Method to create employee from account from request. + * Method to create employee from profile from request. * * @param RequestAbstract $request Request * @@ -116,7 +115,7 @@ final class ApiController extends Controller */ private function createEmployeeFromAccountFromRequest(RequestAbstract $request) : array { - $accounts = $request->getData('cc') ?? []; + $accounts = $request->getData('profiles') ?? []; if (!\is_array($accounts)) { $accounts = [$accounts]; } diff --git a/Models/Employee.php b/Models/Employee.php index 93a222e..4d67f01 100644 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; +use Modules\Media\Models\NullMedia; use phpOMS\Contract\ArrayableInterface; /** @@ -43,6 +44,14 @@ class Employee implements ArrayableInterface, \JsonSerializable */ private $profile = null; + /** + * Employee image. + * + * @var null|int|Media + * @since 1.0.0 + */ + private $image = null; + /** * Employee department/position history. * @@ -88,7 +97,7 @@ class Employee implements ArrayableInterface, \JsonSerializable /** * Constructor. * - * @param null|Profile $profile Account profile to initialize this employee with + * @param null|int|Profile $profile Account profile to initialize this employee with * * @since 1.0.0 */ @@ -99,9 +108,9 @@ class Employee implements ArrayableInterface, \JsonSerializable } /** - * Get account id. + * Get id. * - * @return int Account id + * @return int Employee id * * @since 1.0.0 */ @@ -122,6 +131,32 @@ class Employee implements ArrayableInterface, \JsonSerializable 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/EmployeeHistory.php b/Models/EmployeeHistory.php index dc1f725..7d43b47 100644 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -33,20 +33,43 @@ use phpOMS\Contract\ArrayableInterface; */ class EmployeeHistory implements ArrayableInterface, \JsonSerializable { - private $id = 0; + /** + * ID. + * + * @var int + * @since 1.0.0 + */ + protected int $id = 0; private $employee = null; - private $unit = null; + private $unit = 0; - private $department = null; + private $department = 0; - private $position = null; + private $position = 0; private $start = null; private $end = null; + /** + * Constructor. + * + * @since 1.0.0 + */ + public function __construct() + { + $this->start = new \DateTime('now'); + } + + /** + * Get id. + * + * @return int Model id + * + * @since 1.0.0 + */ public function getId() : int { return $this->id; diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index 932fb3d..c1d2694 100644 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -37,8 +37,9 @@ final class EmployeeMapper extends DataMapperAbstract */ protected static array $columns = [ 'hr_staff_id' => ['name' => 'hr_staff_id', 'type' => 'int', 'internal' => 'id'], - 'hr_staff_account' => ['name' => 'hr_staff_account', 'type' => 'int', 'internal' => 'account'], + 'hr_staff_profile' => ['name' => 'hr_staff_profile', 'type' => 'int', 'internal' => 'profile'], 'hr_staff_smiPHash' => ['name' => 'hr_staff_smiPHash', 'type' => 'string', 'internal' => 'semiPrivateHash'], + 'hr_staff_image' => ['name' => 'hr_staff_image', 'type' => 'int', 'internal' => 'image', 'annotations' => ['gdpr' => true]], ]; /** @@ -48,9 +49,9 @@ final class EmployeeMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $belongsTo = [ - 'account' => [ + 'profile' => [ 'mapper' => ProfileMapper::class, - 'src' => 'hr_staff_account', + 'src' => 'hr_staff_profile', ], ]; @@ -61,7 +62,7 @@ final class EmployeeMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $hasMany = [ - 'company' => [ + 'companyHistory' => [ 'mapper' => EmployeeHistoryMapper::class, 'table' => 'hr_staff_history', 'dst' => 'hr_staff_history_staff', diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 6f0547c..f987994 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -1,4 +1,4 @@ - [ 'Account' => 'Account', 'Active' => 'Active', diff --git a/Theme/Backend/department-list.tpl.php b/Theme/Backend/department-list.tpl.php index 553b0a1..2e3e1fd 100644 --- a/Theme/Backend/department-list.tpl.php +++ b/Theme/Backend/department-list.tpl.php @@ -1,4 +1,4 @@ -getData('nav')->render(); ?>
- +
- - $value) : ++$c; $url = \phpOMS\Uri\UriFactory::build('{/prefix}humanresource/staff/profile?{?}&id=' . $value->getId()); ?>
getHtml('Staff') ?>
getHtml('ID', '0', '0'); ?> - getHtml('Name') ?> - getHtml('Unit') ?> - getHtml('Position') ?> - getHtml('Department') ?> - getHtml('Status') ?> + getHtml('ID', '0', '0'); ?> + getHtml('Name') ?> + getHtml('Unit') ?> + getHtml('Position') ?> + getHtml('Department') ?> + getHtml('Status') ?>
+
printHtml($value->getId()); ?> - printHtml($value->getAccount()->getName1()); ?> + printHtml($value->getProfile()->getAccount()->getName1()); ?> + getNewestHistory()->getUnit()->getName(); ?> + getNewestHistory()->getPosition()->getName(); ?> + getNewestHistory()->getDepartment()->getName(); ?> + getNewestHistory() instanceof NullEmployeeHistory) ? $this->getHtml('Active') : $this->getHtml('Inactive'); ?> -
getHtml('Empty', '0', '0'); ?> +
getHtml('Empty', '0', '0'); ?>
diff --git a/Theme/Backend/staff-single.tpl.php b/Theme/Backend/staff-single.tpl.php index beeee6d..98307a5 100644 --- a/Theme/Backend/staff-single.tpl.php +++ b/Theme/Backend/staff-single.tpl.php @@ -1,4 +1,4 @@ -getData('employee'); $history = $employee->getHistorY(); @@ -17,96 +22,195 @@ $recentHistory = $employee->getNewestHistory(); echo $this->getData('nav')->render(); ?> -
-
-
-

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

-
- - - - - - - - - - - - - - - -
getHtml('Position') ?> - printHtml($recentHistory->getPosition()->getName()); ?> -
getHtml('Department') ?> - printHtml($recentHistory->getDepartment()->getName()); ?> -
getHtml('Unit') ?> - printHtml($recentHistory->getUnit()->getName()); ?> -
getHtml('Birthday') ?> - 06.09.1934 -
getHtml('Email') ?> - printHtml($employee->getAccount()->getEmail()); ?> -
Address - -
Private - SMALLSYS INC
795 E DRAGRAM
TUCSON AZ 85705
USA -
Work - SMALLSYS INC
795 E DRAGRAM
TUCSON AZ 85705
USA -
getHtml('Phone') ?> - -
Private - +01 12345-4567 -
Mobile - +01 12345-4567 -
Work - +01 12345-4567 -
getHtml('Status') ?> - printHtml($employee->getAccount()->getStatus()); ?> +
+
+ +
+
+ +
+
+
+
+

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

+
+ + + <?= $this->getHtml('ProfileImage'); ?> + + + + + + + + + + + + + + + +
getHtml('Position') ?> + printHtml($recentHistory->getPosition()->getName()); ?> +
getHtml('Department') ?> + printHtml($recentHistory->getDepartment()->getName()); ?> +
getHtml('Unit') ?> + printHtml($recentHistory->getUnit()->getName()); ?> +
getHtml('Birthday') ?> + 06.09.1934 +
getHtml('Email') ?> + printHtml($employee->getProfile()->getAccount()->getEmail()); ?> +
Address + +
Private + SMALLSYS INC
795 E DRAGRAM
TUCSON AZ 85705
USA +
Work + SMALLSYS INC
795 E DRAGRAM
TUCSON AZ 85705
USA +
getHtml('Phone') ?> + +
Private + +01 12345-4567 +
Mobile + +01 12345-4567 +
Work + +01 12345-4567 +
getHtml('Status') ?> + getHtml('Active') : $this->getHtml('Inactive'); ?> +
+ +
+
+
+
+ +
+
+
+ + + + + + +
getHtml('History') ?>
getHtml('Start') ?> + getHtml('End') ?> + getHtml('Unit') ?> + getHtml('Department') ?> + getHtml('Position') ?> +
getStart()->format('Y-m-d'); ?> + getEnd() === null ? '' : $hist->getEnd()->format('Y-m-d'); ?> + printHtml($hist->getUnit()->getName()); ?> + printHtml($hist->getDepartment()->getName()); ?> + printHtml($hist->getPosition()->getName()); ?> +
- +
+
- -
- -
-
-

getHtml('Clocking') ?>

-
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
-
-
-
- -
-
-
-

getHtml('Clocking') ?>

-
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
+
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
+
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
+
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
+
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
+
+
+ +
+
+
+
+

getHtml('Clocking') ?>

+
+
+
+
-
-
- -
-
- - - - - - -
getHtml('History') ?>
getHtml('Start') ?> - getHtml('End') ?> - getHtml('Unit') ?> - getHtml('Department') ?> - getHtml('Position') ?> -
getStart()->format('Y-m-d'); ?> - getEnd() === null ? '' : $hist->getEnd()->format('Y-m-d'); ?> - printHtml($hist->getUnit()->getName()); ?> - printHtml($hist->getDepartment()->getName()); ?> - printHtml($hist->getPosition()->getName()); ?> - -
-
+
\ No newline at end of file diff --git a/info.json b/info.json index 2760d0e..8c1178c 100644 --- a/info.json +++ b/info.json @@ -18,10 +18,12 @@ "directory": "HumanResourceManagement", "dependencies": { "Admin": "1.0.0", - "Organization": "1.0.0" + "Organization": "1.0.0", + "Media": "1.0.0" }, "providing": { - "Navigation": "*" + "Navigation": "*", + "Media": "1.0.0" }, "load": [ {