Files
Ferme/src/State/Bovin/BovineInventoryStatsProvider.php
tristan 569d3b373f feat : refonte de l'affichage des âges et restriction des prix aux admins
- Repository BovineRepository avec getInventoryStats en DQL
- Sécurité ApiProperty ROLE_ADMIN sur pricePerKg et finalPrice
- Endpoint inventory-export passe en ROLE_ADMIN
- Composable useBovineColumns mutualisé entre inventory et case (admin/user séparés)
- Stats par tranche d'âge filtrables par buildingCaseId
- Légende avec cartes colorées pleines + texte blanc
- Coloration de la cellule Age (badge) au lieu de toute la ligne
- Décalage couleurs : red ≥ 24, orange 22-24, yellow 20-22

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 17:09:13 +02:00

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;
}
}