src/Controller/DashboardController.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Application;
  5. use App\Entity;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Contracts\Cache;
  9. class DashboardController extends AbstractController
  10. {
  11.     public function __construct(
  12.         private Application\DashboardService $dashboardService,
  13.     ) {}
  14.     public function home(Cache\CacheInterface $cache): Response
  15.     {
  16.         /** @var Entity\Agent */
  17.         $user $this->getUser();
  18.         $cachePrefix "{$user->getId()}::dashboard";
  19.         $waitingToPay $cache->get("{$cachePrefix}::waiting_to_pay", function (Cache\ItemInterface $item) use ($user) {
  20.             $item->expiresAfter(60);
  21.             return $this->dashboardService->waitingToPaySummary($user);
  22.         });
  23.         $productionTotals $cache->get("{$cachePrefix}::monthlyProduction", function (Cache\ItemInterface $item) use ($user) {
  24.             $item->expiresAfter(60);
  25.             return $this->dashboardService->monthlyProductionSummary($user);
  26.         });
  27.         $callbacks $this->dashboardService->callbacksForAgents($user);
  28.         return $this->render(
  29.             'dashboard/home.html.twig',
  30.             [
  31.                 'bulletins' => $this->dashboardService->bulletinSummary(4),
  32.                 'production' => [
  33.                     'monthly' => $productionTotals,
  34.                     'total' => array_sum(array_column($productionTotals'value')),
  35.                 ],
  36.                 'waitingToPay' => [
  37.                     ['label' => 'Advanced''value' => $waitingToPay['advanced']],
  38.                     ['label' => 'As Earned''value' => $waitingToPay['asEarned']],
  39.                 ],
  40.                 'callbacks' => $callbacks,
  41.             ]
  42.         );
  43.     }
  44. }