src/Controller/HomeController.php line 21

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