From adbd33c6302d1c2f33e4377575ac07c3f10b5581 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Sep 2017 22:00:15 +0200 Subject: [PATCH] Add unit, dep, pos. to employee --- Admin/Installer.php | 13 +++++++++++-- Models/Employee.php | 36 ++++++++++++++++++++++++++++++++++++ Models/EmployeeMapper.php | 24 +++++++++++++++++++++--- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/Admin/Installer.php b/Admin/Installer.php index 4f91475..7c8ed27 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -44,14 +44,23 @@ class Installer extends InstallerAbstract 'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'hr_staff` ( `hr_staff_id` int(11) NOT NULL AUTO_INCREMENT, `hr_staff_account` int(11) DEFAULT NULL, + `hr_staff_unit` int(11) DEFAULT NULL, + `hr_staff_department` int(11) DEFAULT NULL, + `hr_staff_position` int(11) DEFAULT NULL, PRIMARY KEY (`hr_staff_id`), - KEY `hr_staff_account` (`hr_staff_account`) + KEY `hr_staff_account` (`hr_staff_account`), + KEY `hr_staff_unit` (`hr_staff_unit`), + KEY `hr_staff_department` (`hr_staff_department`), + KEY `hr_staff_position` (`hr_staff_position`) )ENGINE=InnoDB DEFAULT CHARSET=utf8;' )->execute(); $dbPool->get()->con->prepare( 'ALTER TABLE `' . $dbPool->get()->prefix . 'hr_staff` - ADD CONSTRAINT `' . $dbPool->get()->prefix . 'hr_staff_ibfk_1` FOREIGN KEY (`hr_staff_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);' + ADD CONSTRAINT `' . $dbPool->get()->prefix . 'hr_staff_ibfk_1` FOREIGN KEY (`hr_staff_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`), + ADD CONSTRAINT `' . $dbPool->get()->prefix . 'hr_staff_ibfk_2` FOREIGN KEY (`hr_staff_unit`) REFERENCES `' . $dbPool->get()->prefix . 'organization_unit` (`organization_unit_id`), + ADD CONSTRAINT `' . $dbPool->get()->prefix . 'hr_staff_ibfk_3` FOREIGN KEY (`hr_staff_department`) REFERENCES `' . $dbPool->get()->prefix . 'organization_department` (`organization_department_id`), + ADD CONSTRAINT `' . $dbPool->get()->prefix . 'hr_staff_ibfk_4` FOREIGN KEY (`hr_staff_position`) REFERENCES `' . $dbPool->get()->prefix . 'organization_position` (`organization_position_id`);' )->execute(); $dbPool->get()->con->prepare( diff --git a/Models/Employee.php b/Models/Employee.php index 08baba9..ae57371 100644 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -37,6 +37,12 @@ class Employee { private $account = null; + private $unit = null; + + private $department = null; + + private $position = null; + private $history = []; private $status = []; @@ -50,6 +56,36 @@ class Employee { return $this->account; } + public function setUnit($unit) + { + $this->unit = $unit; + } + + public function getUnit() + { + return $this->unit; + } + + public function setDepartment($department) + { + $this->department = $department; + } + + public function getDepartment() + { + return $this->department; + } + + public function setPosition($position) + { + $this->position = $position; + } + + public function getPosition() + { + return $this->position; + } + public function getId() : int { return $this->id; diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index a955f89..0afb47b 100644 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -15,6 +15,9 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\Models; use Modules\Admin\Models\AccountMapper; +use Modules\Organization\Models\UnitMapper; +use Modules\Organization\Models\DepartmentMapper; +use Modules\Organization\Models\PositionMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; class EmployeeMapper extends DataMapperAbstract @@ -29,12 +32,27 @@ class EmployeeMapper extends DataMapperAbstract protected static $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_unit' => ['name' => 'hr_staff_unit', 'type' => 'int', 'internal' => 'unit'], + 'hr_staff_department' => ['name' => 'hr_staff_department', 'type' => 'int', 'internal' => 'department'], + 'hr_staff_position' => ['name' => 'hr_staff_position', 'type' => 'int', 'internal' => 'position'], ]; - protected static $ownsOne = [ + static protected $belongsTo = [ 'account' => [ - 'mapper' => AccountMapper::class, - 'src' => 'hr_staff_account', + 'mapper' => AccountMapper::class, + 'src' => 'hr_staff_account', + ], + 'unit' => [ + 'mapper' => UnitMapper::class, + 'src' => 'hr_staff_unit', + ], + 'department' => [ + 'mapper' => DepartmentMapper::class, + 'src' => 'hr_staff_department', + ], + 'position' => [ + 'mapper' => PositionMapper::class, + 'src' => 'hr_staff_position', ], ];