Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #50 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State\Bovin;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\ApiResource\BovineInventoryStats;
|
|
use App\Repository\BovineRepository;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
|
/**
|
|
* @implements ProviderInterface<BovineInventoryStats>
|
|
*/
|
|
final class BovineInventoryStatsProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private BovineRepository $bovineRepository,
|
|
private RequestStack $requestStack,
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): BovineInventoryStats
|
|
{
|
|
$rawCaseId = $this->requestStack->getCurrentRequest()?->query->get('buildingCaseId');
|
|
$caseId = null !== $rawCaseId && ctype_digit((string) $rawCaseId) ? (int) $rawCaseId : null;
|
|
|
|
$row = $this->bovineRepository->getInventoryStats($caseId);
|
|
|
|
$stats = new BovineInventoryStats();
|
|
$stats->total = $row['total'];
|
|
$stats->over24 = $row['over24'];
|
|
$stats->between22And24 = $row['between22And24'];
|
|
$stats->between20And22 = $row['between20And22'];
|
|
|
|
return $stats;
|
|
}
|
|
}
|