2026-03-30 09:10:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-09-11 16:55:12 +02:00
|
|
|
namespace Uwil\ArcadiaApiPhpClient\Service;
|
2026-03-30 09:10:44 +02:00
|
|
|
|
2026-09-11 16:55:12 +02:00
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\Employee;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PageOf;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiQueryBuilder\Direction;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\ArcadiaEmployeeId;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\EmployeeSorter;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\SiteId;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\Pagination;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Repository\EmployeeRepository;
|
2026-03-30 09:10:44 +02:00
|
|
|
|
|
|
|
|
final class EmployeeService
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly EmployeeRepository $employeeRepository
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return PageOf<Employee> */
|
|
|
|
|
public function getAllSince(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
Direction $sortDirection = Direction::DESC,
|
|
|
|
|
): PageOf {
|
|
|
|
|
return $this->employeeRepository->selectAllSince(
|
|
|
|
|
$pagination,
|
|
|
|
|
$since,
|
|
|
|
|
$sortDirection
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return PageOf<Employee> */
|
|
|
|
|
public function getAll(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): PageOf {
|
|
|
|
|
return $this->employeeRepository->selectAll(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sorter,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return PageOf<Employee>
|
|
|
|
|
*/
|
|
|
|
|
public function getAllOfSitesSince(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
Direction $sortDirection = Direction::DESC,
|
|
|
|
|
): PageOf {
|
|
|
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
|
|
|
|
|
|
|
|
|
if (count($sites) < 1) {
|
|
|
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
|
if (! ($site instanceof SiteId)) {
|
|
|
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSitesSince(
|
|
|
|
|
$pagination,
|
|
|
|
|
$since,
|
|
|
|
|
$sites,
|
|
|
|
|
$sortDirection,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return PageOf<Employee>
|
|
|
|
|
*/
|
|
|
|
|
public function getAllOfSites(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): PageOf {
|
|
|
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
|
|
|
|
|
|
|
|
|
if (count($sites) < 1) {
|
|
|
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
|
if (! ($site instanceof SiteId)) {
|
|
|
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($sorter !== null) {
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSites(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sites,
|
|
|
|
|
$sorter
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSites(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sites,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findBy(ArcadiaEmployeeId $id): ?Employee
|
|
|
|
|
{
|
|
|
|
|
return $this->employeeRepository->find($id);
|
|
|
|
|
}
|
|
|
|
|
}
|