src/Controller/HomeController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use App\Service\formation\FormationService;
  6. use App\Service\notification\NotificationService;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. class HomeController extends AbstractController
  14. {
  15.     private ManagerRegistry $managerRegistry;
  16.     public function __construct(ManagerRegistry $managerRegistry)
  17.     {
  18.         $this->managerRegistry $managerRegistry;
  19.     }
  20.     /**
  21.      * @Route("/", name="homepage")
  22.      */
  23.     public function index()
  24.     {
  25.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  26.         return $this->redirectToRoute('user_dashboard');
  27.     }
  28.     public function showLoginHeader(NotificationService $notificationService$context=null)
  29.     {
  30.         /* @var $user User */
  31.         $user $this->getUser();
  32.         $notifications $notificationService->filterUnreadNotification($user);
  33.         return $this->render('blocks/header.login.html.twig', [
  34.             'notifications' => $notifications,
  35.             'context' => $context
  36.         ]);
  37.     }
  38.     public function showFormationsNotViewed(FormationService $formationService$context=null)
  39.     {
  40.         /* @var $user User */
  41.         $user $this->getUser();
  42.         $formationsNotViewed $formationService->getFormationNotViewed($user);
  43.         return $this->render('blocks/counter.formation.html.twig', [
  44.             'formationsCounter' => sizeof($formationsNotViewed),
  45.             'context' => $context
  46.         ]);
  47.     }
  48.     public function showFormationsRequired(FormationService $formationService$context=null)
  49.     {
  50.         /* @var $user User */
  51.         $user $this->getUser();
  52.         $formationsRequired $formationService->getFormationRequiredNotViewed($user);
  53.         return $this->render('blocks/counter.formation.html.twig', [
  54.             'formationsCounter' => sizeof($formationsRequired),
  55.             'context' => $context
  56.         ]);
  57.     }
  58.     /**
  59.      * @Route ("/getIntro", name="getIntro", methods={"GET"})
  60.      */
  61.     public function getIntro(Request $request)
  62.     {
  63.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  64.         $user null;
  65.         $intro null;
  66.         if ($request->isXmlHttpRequest()) {
  67.             $user $this->getUser();
  68.             $intro $user->isIntro();;
  69.             if ($intro == false) {
  70.                 $em $this->managerRegistry->getManager();
  71.                 $user->setIntro(true);
  72.                 $em->persist($user);
  73.                 $em->flush();
  74.             }
  75.         }
  76.         return new JsonResponse(["intro"=>$intro,"roles"=>$user $user->getRoles() : []]);
  77.     }
  78.     /**
  79.      * @Security("is_granted('ROLE_USER_ACTIF') or is_granted('ROLE_USER_INACTIF')")
  80.      * @Route ("/how-it-works", name="how_it_works")
  81.      */
  82.     public function howItWorks(TranslatorInterface $translator){
  83.         return $this->render('pages/dashboard/howitworks/show.html.twig',[
  84.             'title_page' => $translator->trans("Guide d'utilisation"),
  85.         ]);
  86.     }
  87. //    /**
  88. //     * @Security("is_granted('ROLE_USER_ACTIF') or is_granted('ROLE_USER_INACTIF')")
  89. //     * @Route ("/test", name="test")
  90. //     */
  91. //    public function test(JwpHttp $jwpHttp, WPHttp $WPHttp,EventDispatcherInterface $eventDispatcher){
  92. //
  93. //
  94. //        try {
  95. ////            $response = $jwpHttp->call("/channels/list", [], false);
  96. //            $response = $WPHttp->get('posts',[],false,false);
  97. //
  98. //            /*Notify user by email*/
  99. ////            $event = new GenericEvent($this->getUser());
  100. ////            $eventDispatcher->dispatch($event, Events::EMAIL_NEW_ACCOUNT);
  101. //        }
  102. //        catch (\Exception $e){
  103. //
  104. //            dump($e->getMessage());
  105. //            die;
  106. //        }
  107. //
  108. //        return new JsonResponse($response);
  109. //
  110. //    }
  111. }