<?php
namespace App\Controller;
use App\Entity\Customer;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class ClientHomepageController extends MainController {
private $router;
public function __construct(Environment $twig, TranslatorInterface $translator,
AuthenticationUtils $authenticationUtils, SessionInterface $session,
RouterInterface $router
) {
parent::__construct($twig, $translator, $authenticationUtils, $session);
$this->router = $router;
}
public function index() : Response
{
$user = $this->get('security.token_storage')->getToken()->getUser();
if ($user instanceof Customer) {
if ($user->getIsRecipient()) {
$targetPath = $this->router->generate('client_inquiry_active');
} elseif ($user->getIsSupplier()) {
$targetPath = $this->router->generate('supplier_inquiry_latest');
} else {
$targetPath = $this->router->generate('client_inquiry_active');
}
return new RedirectResponse($targetPath);
}
return new Response(
$this->getTwig()->render(
'ClientHomepage/clientHomepage.html.twig'
)
);
}
}