src/Controller/indexController.php line 95

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Absence;
  4. use App\Entity\Deplacement;
  5. use App\Entity\ExpenseReportMonth;
  6. use App\Entity\NightDescription;
  7. use App\Entity\Rtt;
  8. use App\Entity\Sessions;
  9. use App\Entity\User;
  10. use App\Service\CalculHoursService;
  11. use App\Service\FileService;
  12. use App\Service\UserService;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  17. use Symfony\Component\HttpFoundation\Session\Session;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class indexController extends AbstractController
  20. {
  21.     private $calculHoursService;
  22.     private $fileService;
  23.     public function __construct(CalculHoursService $calculHoursServiceFileService $fileService){
  24.         $this->calculHoursService $calculHoursService;
  25.         $this->fileService $fileService;
  26.     }
  27.     /**
  28.      * @Route("/app_homepage", name="app_homepage")
  29.      */
  30.     public function indexAction(){
  31.         $fullname $this->getUser()->getFullname();
  32.         $roles $this->getUser()->getRoles();
  33.         $totalConnexions $this->getUser()->getActive();
  34.         $expUser false;
  35.         if($totalConnexions === 0){
  36.             // Si la date de fin de contrat est dépassée,je renvoie sur page accueil
  37.             $expDate $this->getUser()->getDatesortie();
  38.             if($expDate && $expDate < new \DateTime()){
  39.                 $expUser true;
  40.             }else{
  41.                 // Si je suis sur une première connexion
  42.                 return $this->render('security/firstConnexion.html.twig');
  43.             }
  44.         }
  45.         if($expUser === false) {
  46.             $role 'ROLE_UTILISATEUR';
  47.             foreach ($roles as $value) {
  48.                 if ($value == 'ROLE_ADMIN') {
  49.                     $role $value;
  50.                     break;
  51.                 }
  52.             }
  53.             // Suppression des sessions inférieures à une semaine
  54.             return $this->render('homepage/homepage.html.twig', ['role' => $role'fullname' => $fullname]);
  55.         }
  56.         session_destroy();
  57.         return $this->redirectToRoute('app_login');
  58.     }
  59.     /**
  60.      * @Route("/deconnexion", name="deconnexion")
  61.      */
  62.     public function deconnexionAction(){
  63.         session_destroy();
  64.         return $this->redirectToRoute('app_login');
  65.     }
  66.     /**
  67.      * @Route("/calculhour", name="calculhour")
  68.      */
  69.     public function testcalculhour(){
  70.         $time "-105";
  71.     }
  72.     /**
  73.      * @Route("/visualiser_pdf/{pdf}", name="visualiser_pdf")
  74.      */
  75.     public function visualiserPDF($pdf): \Symfony\Component\HttpFoundation\BinaryFileResponse
  76.     {
  77.         $root $this->getParameter('kernel.project_dir');
  78.         return $this->file($root 'public/Formulaire_Renonciation.pdf'nullResponseHeaderBag::DISPOSITION_INLINE);
  79.     }
  80.     /**
  81.      * @Route("/getNotifications", name="getNotifications")
  82.      */
  83.     public function getNotifications(){
  84.         if($this->getUser()){
  85.             $respUserId $this->getUser()->getId();
  86.             $hoursToValidate = [];
  87.             $absences = [];
  88.             $aDeplacements = [];
  89.             $aNightHours = [];
  90.             $aExpenseReport = [];
  91.             if(in_array('ROLE_ADMIN'$this->getUser()->getRoles(), true)){
  92.                 $hoursToValidate $this->getDoctrine()->getRepository('App:Dailyhour')->getAllHoursToValidate();
  93.                 $absences $this->getDoctrine()->getRepository(Absence::class)->getAbsencesToValidate('null');
  94.                 $aDeplacements $this->getDoctrine()->getRepository(Deplacement::class)->getDeplacementsToValidate('null',null);
  95.                 $aNightHours $this->getDoctrine()->getRepository(NightDescription::class)->getNightHoursToValidate();
  96.                 $aExpenseReport $this->getDoctrine()->getRepository(ExpenseReportMonth::class)->getAllExpenseReportMonthToValidate('ADMIN');
  97.             }elseif(in_array('ROLE_RESPONSABLE'$this->getUser()->getRoles(), true)){
  98.                 $hoursToValidate $this->getDoctrine()->getRepository('App:Dailyhour')->getHoursToValidateByResp($respUserId);
  99.                 $absences $this->getDoctrine()->getRepository(Absence::class)->getAbsencesToValidate($respUserId);
  100.                 $aDeplacements $this->getDoctrine()->getRepository(Deplacement::class)->getDeplacementsToValidate('respId'$this->getUser()->getId());
  101.                 $aNightHours $this->getDoctrine()->getRepository(NightDescription::class)->getNightHoursToValidate();
  102.             }elseif(in_array('ROLE_COMPTA'$this->getUser()->getRoles(), true)){
  103.                 // Si comptabilité pour les frais
  104.                 $aExpenseReport $this->getDoctrine()->getRepository(ExpenseReportMonth::class)->getAllExpenseReportMonthToValidate('COMPTA');
  105.             }
  106.             // Pour tous, on récupère certaines données
  107.             $aFilesToSign $this->fileService->getFilesToSign();
  108.             return new JsonResponse(array(count($hoursToValidate), count($absences), count($aDeplacements), count($aNightHours), count($aFilesToSign), count($aExpenseReport)));
  109.         }
  110.         return new JsonResponse('FALSE');
  111.     }
  112.     /**
  113.      * @Route("/simulate-error", name="simulate_error")
  114.      */
  115.     public function simulateError(): Response
  116.     {
  117.         throw new \Exception('This is a simulated error 500!');
  118.     }
  119. }