<?php
namespace App\Controller;
use App\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashController extends AbstractController
{
private $entityManager;
public function __construct( EntityManagerInterface $entityManager )
{
$this->entityManager = $entityManager;
}
/**
* @Route("/", name="app_dash")
*/
public function index(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$em = $this->entityManager;
$user = $this->getUser();
$member = $em->getRepository(Person::class)->find($user->getPerson()->getId());
if( $member->isActive() == 0 ){
$this->addFlash(
'error',
'Su cuenta fue desactivada'
);
return $this->redirectToRoute('app_login');
}
if ($member->getUser()->getIsSuperAdmin()) {
return $this->redirectToRoute('admin_dash');
}
if ($member->getUser()->getIsCorporation()) {
return $this->redirectToRoute('corporation_dash');
}
if ($member->getUser()->getIsManager()) {
return $this->redirectToRoute('manager_dash');
}
return $this->redirectToRoute('admin_student');
}
}