<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\PortalConsejoService;
use App\Form\PersonaType;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\SsoSistema;
use App\Repository\SsoSistemaRepository;
use App\Entity\Auditoria\Registro;
use App\Repository\Escuela\EgresadoRepository;
use App\Service\AuditoriaService;
#[Route('/portal/consejo')]
class PortalConsejoController extends AbstractController
{
#[Route('/', name: 'portal_consejo')]
public function index(SsoSistemaRepository $sistemaRepository): Response
{
// Tomo los sistemas asignados al usuario y que se encuentren activos
$sistemas = $this->getUser()->getSsoUsuarioSistemas()->map(
function ($relacion) {
return $relacion->getSistema();
})->filter(
function ($sistema) {
return $sistema->getClienteOauth2()->isActive();
});
return $this->render('portal_consejo/index.html.twig', [
'sistemas' => $sistemas,
]);
}
#[Route('/{id}/sistema', name: 'portal_ir_sistema')]
public function irSistema(
Request $request,
SsoSistema $sistema,
AuditoriaService $auditoriaService,
EgresadoRepository $egresadoRepository
): Response
{
// Validar si es egresado en el caso de seleccionar ria
// if ($sistema->getClienteOauth2()->getIdentifier() == 'ria_consejo') {
// $egresado = $egresadoRepository->findEgresadoByDNI(
// $this->getUser()->getPersona()->getDni()
// );
// if ($this->getUser()->getPersona()->getDni() <> 30281944) {
// if (!$egresado) {
// $request->getSession()->getFlashBag()->add(
// 'error', // notice / warning / error
// 'Para ingresar al RIA debe ser Egresado de la Escuela Judicial.'
// );
// return $this->redirectToRoute('portal_aspirante', [],
// Response::HTTP_SEE_OTHER);
// }
// }
// }
$auditoriaService->auditarEvento(Registro::EVENTO_MODULO_INGRESO, null, $sistema);
$url = $sistema->getUrl();
return $this->redirect($url, Response::HTTP_SEE_OTHER);
}
#[Route('/perfil', name: 'perfil')]
public function perfil(Request $request,
PortalConsejoService $portalService): Response
{
$form = $this->createForm(
PersonaType::class,
$this->getUser()->getPersona(),
['disabled' => true]
);
$formPassword = $portalService->procesarCambioPassword($request, $this->getUser());
$formEmail = $portalService->procesarCambioEmail($request, $this->getUser());
return $this->renderForm('portal_consejo/perfil.html.twig', [
'form' => $form,
'formPassword' => $formPassword,
'formEmail' => $formEmail,
]);
}
#[Route('/conf_correo/{mail}/{token}', name: 'confirma_correo')]
public function confirmaCorreo(
Request $request,
PortalConsejoService $portalService,
String $mail,
String $token): Response
{
$portalService->procesarConfirmacionCambioEmail($request, $mail, $token);
if (in_array('ROLE_CONSEJO', $this->getUser()->getRoles()))
return $this->redirectToRoute('perfil', [
// 'id' => $ultimaSesion->getId(),
], Response::HTTP_SEE_OTHER);
else
return $this->redirectToRoute('portal_aspirante_perfil', [
// 'id' => $ultimaSesion->getId(),
], Response::HTTP_SEE_OTHER);
}
#[Route('/help', name: 'ayuda')]
public function ayuda(): Response
{
return $this->render('portal_consejo/index.html.twig', [
'controller_name' => 'PortalConsejoController',
]);
}
}