<?php
namespace App\Controller;
use App\Entity\User;
use App\Service\formation\FormationService;
use App\Service\notification\NotificationService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class HomeController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function index()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
return $this->redirectToRoute('user_dashboard');
}
public function showLoginHeader(NotificationService $notificationService, $context=null)
{
/* @var $user User */
$user = $this->getUser();
$notifications = $notificationService->filterUnreadNotification($user);
return $this->render('blocks/header.login.html.twig', [
'notifications' => $notifications,
'context' => $context
]);
}
public function showFormationsRequired(FormationService $formationService, $context=null)
{
/* @var $user User */
$user = $this->getUser();
$formationsRequired = $formationService->getFormationRequiredNotViewed($user);
return $this->render('blocks/counter.formation.html.twig', [
'formationsCounter' => sizeof($formationsRequired),
'context' => $context
]);
}
/**
* @Route ("/getIntro", name="getIntro", methods={"GET"})
*/
public function getIntro(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = null;
$intro = null;
if ($request->isXmlHttpRequest()) {
$user = $this->getUser();
$intro = $user->isIntro();;
if ($intro == false) {
$em = $this->getDoctrine()->getManager();
$user->setIntro(true);
$em->persist($user);
$em->flush();
}
}
return new JsonResponse(["intro"=>$intro,"roles"=>$user ? $user->getRoles() : null]);
}
/**
* @Security("is_granted('ROLE_USER_ACTIF') or is_granted('ROLE_USER_INACTIF')")
* @Route ("/how-it-works", name="how_it_works")
*/
public function howItWorks(TranslatorInterface $translator){
return $this->render('pages/dashboard/howitworks/show.html.twig',[
'title_page' => $translator->trans('Comment ça marche ?'),
]);
}
// /**
// * @Security("is_granted('ROLE_USER_ACTIF') or is_granted('ROLE_USER_INACTIF')")
// * @Route ("/test", name="test")
// */
// public function test(JwpHttp $jwpHttp, WPHttp $WPHttp,EventDispatcherInterface $eventDispatcher){
//
//
// try {
//// $response = $jwpHttp->call("/channels/list", [], false);
// $response = $WPHttp->get('posts',[],false,false);
//
// /*Notify user by email*/
//// $event = new GenericEvent($this->getUser());
//// $eventDispatcher->dispatch($event, Events::EMAIL_NEW_ACCOUNT);
// }
// catch (\Exception $e){
//
// dump($e->getMessage());
// die;
// }
//
// return new JsonResponse($response);
//
// }
}