36 lines
837 B
PHP
36 lines
837 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\Entity\TimeEntry;
|
|
use App\Repository\TimeEntryRepository;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
/**
|
|
* @implements ProviderInterface<TimeEntry>
|
|
*/
|
|
final readonly class ActiveTimeEntryProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private Security $security,
|
|
private TimeEntryRepository $timeEntryRepository,
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
|
{
|
|
$user = $this->security->getUser();
|
|
|
|
if (!$user) {
|
|
return [];
|
|
}
|
|
|
|
$entry = $this->timeEntryRepository->findActiveByUser($user);
|
|
|
|
return $entry ? [$entry] : [];
|
|
}
|
|
}
|