<?php
namespace App\Controller;
use App\Entity\Absence;
use App\Entity\Deplacement;
use App\Entity\ExpenseReportMonth;
use App\Entity\NightDescription;
use App\Entity\Rtt;
use App\Entity\Sessions;
use App\Entity\User;
use App\Service\CalculHoursService;
use App\Service\FileService;
use App\Service\UserService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
class indexController extends AbstractController
{
private $calculHoursService;
private $fileService;
public function __construct(CalculHoursService $calculHoursService, FileService $fileService){
$this->calculHoursService = $calculHoursService;
$this->fileService = $fileService;
}
/**
* @Route("/app_homepage", name="app_homepage")
*/
public function indexAction(){
$fullname = $this->getUser()->getFullname();
$roles = $this->getUser()->getRoles();
$totalConnexions = $this->getUser()->getActive();
$expUser = false;
if($totalConnexions === 0){
// Si la date de fin de contrat est dépassée,je renvoie sur page accueil
$expDate = $this->getUser()->getDatesortie();
if($expDate && $expDate < new \DateTime()){
$expUser = true;
}else{
// Si je suis sur une première connexion
return $this->render('security/firstConnexion.html.twig');
}
}
if($expUser === false) {
$role = 'ROLE_UTILISATEUR';
foreach ($roles as $value) {
if ($value == 'ROLE_ADMIN') {
$role = $value;
break;
}
}
// Suppression des sessions inférieures à une semaine
return $this->render('homepage/homepage.html.twig', ['role' => $role, 'fullname' => $fullname]);
}
session_destroy();
return $this->redirectToRoute('app_login');
}
/**
* @Route("/deconnexion", name="deconnexion")
*/
public function deconnexionAction(){
session_destroy();
return $this->redirectToRoute('app_login');
}
/**
* @Route("/calculhour", name="calculhour")
*/
public function testcalculhour(){
$time = "-105";
}
/**
* @Route("/visualiser_pdf/{pdf}", name="visualiser_pdf")
*/
public function visualiserPDF($pdf): \Symfony\Component\HttpFoundation\BinaryFileResponse
{
$root = $this->getParameter('kernel.project_dir');
return $this->file($root . 'public/Formulaire_Renonciation.pdf', null, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/getNotifications", name="getNotifications")
*/
public function getNotifications(){
if($this->getUser()){
$respUserId = $this->getUser()->getId();
$hoursToValidate = [];
$absences = [];
$aDeplacements = [];
$aNightHours = [];
$aExpenseReport = [];
if(in_array('ROLE_ADMIN', $this->getUser()->getRoles(), true)){
$hoursToValidate = $this->getDoctrine()->getRepository('App:Dailyhour')->getAllHoursToValidate();
$absences = $this->getDoctrine()->getRepository(Absence::class)->getAbsencesToValidate('null');
$aDeplacements = $this->getDoctrine()->getRepository(Deplacement::class)->getDeplacementsToValidate('null',null);
$aNightHours = $this->getDoctrine()->getRepository(NightDescription::class)->getNightHoursToValidate();
$aExpenseReport = $this->getDoctrine()->getRepository(ExpenseReportMonth::class)->getAllExpenseReportMonthToValidate('ADMIN');
}elseif(in_array('ROLE_RESPONSABLE', $this->getUser()->getRoles(), true)){
$hoursToValidate = $this->getDoctrine()->getRepository('App:Dailyhour')->getHoursToValidateByResp($respUserId);
$absences = $this->getDoctrine()->getRepository(Absence::class)->getAbsencesToValidate($respUserId);
$aDeplacements = $this->getDoctrine()->getRepository(Deplacement::class)->getDeplacementsToValidate('respId', $this->getUser()->getId());
$aNightHours = $this->getDoctrine()->getRepository(NightDescription::class)->getNightHoursToValidate();
}elseif(in_array('ROLE_COMPTA', $this->getUser()->getRoles(), true)){
// Si comptabilité pour les frais
$aExpenseReport = $this->getDoctrine()->getRepository(ExpenseReportMonth::class)->getAllExpenseReportMonthToValidate('COMPTA');
}
// Pour tous, on récupère certaines données
$aFilesToSign = $this->fileService->getFilesToSign();
return new JsonResponse(array(count($hoursToValidate), count($absences), count($aDeplacements), count($aNightHours), count($aFilesToSign), count($aExpenseReport)));
}
return new JsonResponse('FALSE');
}
/**
* @Route("/simulate-error", name="simulate_error")
*/
public function simulateError(): Response
{
throw new \Exception('This is a simulated error 500!');
}
}