Add unit, dep, pos. to employee

This commit is contained in:
Dennis Eichhorn 2017-09-29 22:00:15 +02:00
parent 2ad006e339
commit adbd33c630
3 changed files with 68 additions and 5 deletions

View File

@ -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(

View File

@ -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;

View File

@ -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',
],
];