diff --git a/Admin/Install/db.json b/Admin/Install/db.json index d6037bb..2b145b6 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -54,21 +54,24 @@ "hr_staff_history_unit": { "name": "hr_staff_history_unit", "type": "INT", - "null": false, + "null": true, + "default": null, "foreignTable": "organization_unit", "foreignKey": "organization_unit_id" }, "hr_staff_history_department": { "name": "hr_staff_history_department", "type": "INT", - "null": false, + "null": true, + "default": null, "foreignTable": "organization_department", "foreignKey": "organization_department_id" }, "hr_staff_history_position": { "name": "hr_staff_history_position", "type": "INT", - "null": false, + "null": true, + "default": null, "foreignTable": "organization_position", "foreignKey": "organization_position_id" }, diff --git a/Models/Employee.php b/Models/Employee.php index 4d67f01..0f5ff2b 100644 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -205,6 +205,20 @@ class Employee implements ArrayableInterface, \JsonSerializable return $this->companyHistory; } + /** + * Add company history to employee + * + * @param mixed $history Company history + * + * @return void + * + * @since 1.0.0 + */ + public function addHistory($history) : void + { + $this->companyHistory[] = $history; + } + /** * Get newest company history. * diff --git a/Models/EmployeeHistory.php b/Models/EmployeeHistory.php index 7d43b47..cdef6c0 100644 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -41,17 +41,53 @@ class EmployeeHistory implements ArrayableInterface, \JsonSerializable */ protected int $id = 0; - private $employee = null; + /** + * Employee + * + * @var int|Employee + * @since 1.0.0 + */ + private $employee = 0; - private $unit = 0; + /** + * Unit + * + * @var null|int|Unit + * @since 1.0.0 + */ + private $unit = null; - private $department = 0; + /** + * Department + * + * @var null|int|Department + * @since 1.0.0 + */ + private $department = null; - private $position = 0; + /** + * Position + * + * @var null|int|Position + * @since 1.0.0 + */ + private $position = null; - private $start = null; + /** + * Start date + * + * @var \DateTime + * @since 1.0.0 + */ + private \DateTime $start; - private $end = null; + /** + * End date + * + * @var null|\DateTime + * @since 1.0.0 + */ + private ?\DateTime $end = null; /** * Constructor. @@ -75,61 +111,159 @@ class EmployeeHistory implements ArrayableInterface, \JsonSerializable return $this->id; } + /** + * Get the employee this history belongs to + * + * @return int|Employee + * + * @since 1.0.0 + */ public function getEmployee() { - return $this->employee ?? new NullEmployee(); + return empty($this->employee) ? new NullEmployee() : $this->employee; } + /** + * Set the employee + * + * @param int|Employee $employee Employee + * + * @return void + * + * @todo maybe only do this in the constructor + * + * @since 1.0.0 + */ public function setEmployee($employee) : void { $this->employee = $employee; } - public function getPosition() : Position + /** + * Get the position + * + * @return int|Position + * + * @since 1.0.0 + */ + public function getPosition() { - return $this->position ?? new NullPosition(); + return empty($this->position) ? new NullPosition() : $this->position; } + /** + * Set the position + * + * @param int|Position $position Position + * + * @return void + * + * @since 1.0.0 + */ public function setPosition($position) : void { $this->position = $position; } - public function getUnit() : Unit + /** + * Get the unit + * + * @return int|Unit + * + * @since 1.0.0 + */ + public function getUnit() { - return $this->unit ?? new NullUnit(); + return empty($this->unit) ? new NullUnit() : $this->unit; } + /** + * Set the unit + * + * @param int|Unit $unit Unit + * + * @return void + * + * @since 1.0.0 + */ public function setUnit($unit) : void { $this->unit = $unit; } - public function getDepartment() : Department + /** + * Get the department + * + * @return int|Department + * + * @since 1.0.0 + */ + public function getDepartment() { - return $this->department ?? new NullDepartment(); + return empty($this->department) ? new NullDepartment() : $this->department; } + /** + * Set the department + * + * @param int|Department $department Department + * + * @return void + * + * @since 1.0.0 + */ public function setDepartment($department) : void { $this->department = $department; } - public function getStart() : ?\DateTime + /** + * Get start date + * + * @return \DateTime + * + * @since 1.0.0 + */ + public function getStart() : \DateTime { return $this->start; } + /** + * Set start date + * + * @param \DateTime $start Start date + * + * @return void + * + * @since 1.0.0 + */ public function setStart(\DateTime $start) : void { $this->start = $start; } + /** + * Get end date + * + * @return null|\DateTime + * + * @since 1.0.0 + */ public function getEnd() : ?\DateTime { return $this->end; } + /** + * Set end date + * + * @param \DateTime $end End date + * + * @return void + * + * @since 1.0.0 + */ public function setEnd(\DateTime $end) : void { $this->end = $end; diff --git a/Models/EmployeeHistoryMapper.php b/Models/EmployeeHistoryMapper.php index 3eecd74..f0e66c0 100644 --- a/Models/EmployeeHistoryMapper.php +++ b/Models/EmployeeHistoryMapper.php @@ -64,6 +64,10 @@ final class EmployeeHistoryMapper extends DataMapperAbstract 'mapper' => PositionMapper::class, 'src' => 'hr_staff_history_position', ], + 'employee' => [ + 'mapper' => EmployeeMapper::class, + 'src' => 'hr_staff_history_staff', + ], ]; /** diff --git a/Theme/Backend/staff-list.tpl.php b/Theme/Backend/staff-list.tpl.php index 8f84f51..c27001b 100644 --- a/Theme/Backend/staff-list.tpl.php +++ b/Theme/Backend/staff-list.tpl.php @@ -42,9 +42,9 @@ echo $this->getData('nav')->render(); ?> printHtml($value->getId()); ?> printHtml($value->getProfile()->getAccount()->getName1()); ?> - getNewestHistory()->getUnit()->getName(); ?> - getNewestHistory()->getPosition()->getName(); ?> - getNewestHistory()->getDepartment()->getName(); ?> + printHtml($value->getNewestHistory()->getUnit()->getName()); ?> + printHtml($value->getNewestHistory()->getPosition()->getName()); ?> + printHtml($value->getNewestHistory()->getDepartment()->getName()); ?> getNewestHistory() instanceof NullEmployeeHistory) ? $this->getHtml('Active') : $this->getHtml('Inactive'); ?>