src/Controller/DashboardController.php line 20

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