Die Modelle für die Ansichten wurden definiert, einschließlich der Tests.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Models;
|
||||
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeInterface;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
|
||||
class WorkingHoursView implements ModelInterface
|
||||
{
|
||||
protected DateTimeInterface $period;
|
||||
protected PeriodDesignationEnum $periodDesignation;
|
||||
protected int $workingDays;
|
||||
protected DateInterval $totalHours;
|
||||
protected DateInterval $overtime;
|
||||
|
||||
/**
|
||||
* WorkingHoursView constructor.
|
||||
*
|
||||
* @param DateTimeInterface $period
|
||||
* @param PeriodDesignationEnum $periodDesignation
|
||||
* @param int $workingDays
|
||||
* @param DateInterval $totalHours
|
||||
* @param DateInterval $overtime
|
||||
*/
|
||||
public function __construct(
|
||||
DateTimeInterface $period,
|
||||
PeriodDesignationEnum $periodDesignation,
|
||||
int $workingDays,
|
||||
DateInterval $totalHours,
|
||||
DateInterval $overtime
|
||||
) {
|
||||
$this->period = $period;
|
||||
$this->periodDesignation = $periodDesignation;
|
||||
$this->workingDays = $workingDays;
|
||||
$this->totalHours = $totalHours;
|
||||
$this->overtime = $overtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface
|
||||
*/
|
||||
public function getPeriod(): DateTimeInterface
|
||||
{
|
||||
return $this->period;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PeriodDesignationEnum
|
||||
*/
|
||||
public function getPeriodDesignation(): PeriodDesignationEnum
|
||||
{
|
||||
return $this->periodDesignation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWorkingDays(): int
|
||||
{
|
||||
return $this->workingDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateInterval
|
||||
*/
|
||||
public function getTotalHours(): DateInterval
|
||||
{
|
||||
return $this->totalHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateInterval
|
||||
*/
|
||||
public function getOvertime(): DateInterval
|
||||
{
|
||||
return $this->overtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
#[ArrayShape(['period' => "string",
|
||||
'periodDesignation' => "string",
|
||||
'totalHours' => "string",
|
||||
'workingDays' => "int",
|
||||
'overtime' => "string"
|
||||
])] public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()),
|
||||
'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()),
|
||||
'workingDays' => $this->getWorkingDays(),
|
||||
'totalHours' => $this->getTotalHours()->format('%H:%I:%S'),
|
||||
'overtime' => $this->getOvertime()->format('%H:%I:%S')
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user