43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
|
|
|
use DateInterval;
|
|
use DateTime;
|
|
use DateTimeInterface;
|
|
use PDO;
|
|
use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
|
|
|
|
class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepository
|
|
{
|
|
|
|
protected const SQL_SELECT = <<<SQL
|
|
select
|
|
"Woche" as "period",
|
|
"Gesamtarbeitszeit" as "totalHours",
|
|
"Arbeitstage" as "workingDays",
|
|
"Überstunden" as "overtime"
|
|
from "Arbeitszeiten - Woche"
|
|
SQL;
|
|
protected const SQL_WHERE = ' where "Woche" = ?';
|
|
|
|
protected PDO $database;
|
|
protected PeriodDesignationEnum $periodDesignation;
|
|
|
|
public function __construct(PDO $database)
|
|
{
|
|
parent::__construct($database);
|
|
$this->periodDesignation = PeriodDesignationEnum::WEEKLY();
|
|
}
|
|
|
|
protected function buildDateFromPeriod(string $period): DateTimeInterface
|
|
{
|
|
$time_array = explode('#', $period);
|
|
$year = (int)$time_array[0];
|
|
$week = (int)$time_array[1] - 1;
|
|
$date = new DateTime('first day of January ' . $year);
|
|
$date->modify('monday this week');
|
|
$date->add(new DateInterval(sprintf('P%dW', $week)));
|
|
return $date;
|
|
}
|
|
} |