src/Controller/ClientHomepageController.php line 25

Open in your IDE?
  1. <?php
  2.     namespace App\Controller;
  3.     use App\Entity\Customer;
  4.     use Symfony\Component\HttpFoundation\RedirectResponse;
  5.     use Symfony\Component\HttpFoundation\Response;
  6.     use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7.     use Symfony\Component\Routing\RouterInterface;
  8.     use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9.     use Symfony\Contracts\Translation\TranslatorInterface;
  10.     use Twig\Environment;
  11.     class ClientHomepageController extends MainController  {
  12.         private $router;
  13.         public function __construct(Environment $twigTranslatorInterface $translator,
  14.                                     AuthenticationUtils $authenticationUtilsSessionInterface $session,
  15.                                     RouterInterface $router
  16.         ) {
  17.             parent::__construct($twig$translator$authenticationUtils$session);
  18.             $this->router $router;
  19.         }
  20.         public function index() : Response
  21.         {
  22.             $user $this->get('security.token_storage')->getToken()->getUser();
  23.             if ($user instanceof Customer) {
  24.                 if ($user->getIsRecipient()) {
  25.                     $targetPath $this->router->generate('client_inquiry_active');
  26.                 } elseif ($user->getIsSupplier()) {
  27.                     $targetPath $this->router->generate('supplier_inquiry_latest');
  28.                 } else {
  29.                     $targetPath $this->router->generate('client_inquiry_active');
  30.                 }
  31.                 return new RedirectResponse($targetPath);
  32.             }
  33.             return new Response(
  34.                 $this->getTwig()->render(
  35.                     'ClientHomepage/clientHomepage.html.twig'
  36.                 )
  37.             );
  38.         }
  39.     }