src/Controller/Front/HomePageController.php line 56

Open in your IDE?
  1. <?php
  2. /******************************************************************************
  3.  * Copyright (c) Echo-numeric 2020-2023.                                      *
  4.  ******************************************************************************/
  5. namespace App\Controller\Front;
  6. use App\Entity\User;
  7. use App\Factory\PointFactory;
  8. use App\Services\Common\PlatformService;
  9. use App\Services\Common\Point\UserPointServiceInterface;
  10. use App\Services\Common\User\WorkflowUser;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Exception;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. class HomePageController extends AbstractController
  17. {
  18.     private UserPointServiceInterface $userPointService;
  19.     private EntityManagerInterface $em;
  20.     private PlatformService $platformService;
  21.     private WorkflowUser $workflowUser;
  22.     /**
  23.      * @throws Exception
  24.      */
  25.     public function __construct(
  26.         EntityManagerInterface $em,
  27.         PlatformService        $platformService,
  28.         WorkflowUser           $workflowUser,
  29.         PointFactory           $pointFactory
  30.     )
  31.     {
  32.         $this->userPointService $pointFactory->getUserPointService();
  33.         $this->em $em;
  34.         $this->platformService $platformService;
  35.         $this->workflowUser $workflowUser;
  36.     }
  37.     /**
  38.      * Page d'accueil pour les utilisateurs identifiés
  39.      *
  40.      * @param Request $request
  41.      *
  42.      * @return Response
  43.      *
  44.      * @throws Exception
  45.      */
  46.     public function show(Request $request): Response
  47.     {
  48.         if ($this->platformService->getType() === 'dtv') {
  49.             return $this->redirectToRoute('dtv_back_dashboard_show');
  50.         }
  51.         /** @var User $currentUser */
  52.         $currentUser $this->getUser();
  53.         $t $this->userPointService->getLevel($currentUser);
  54.         $totalMovement = [
  55.             "debit" => $this->userPointService->getSpendedPoints($currentUser),
  56.             "credit" => $this->userPointService->getFidelityPoints($currentUser),
  57.             'expired' => -abs($this->userPointService->getExpiredPoints($currentUser)),
  58.             'exceptional' => $this->userPointService->getExceptionalPoints($currentUser),
  59.         ];
  60.         if ($request->getMethod() === 'POST') {
  61.             $choice $request->request->get('donneesPersonnellesChoice');
  62.             $currentUser->setDonneesPersonnelles($choice);
  63.             if ($choice === FALSE) {
  64.                 $this->workflowUser->unsubscribeUser($currentUser);
  65.                 return $this->redirectToRoute('saml_logout');
  66.             }
  67.             $this->em->persist($currentUser);
  68.             $this->em->flush();
  69.         }
  70.         return $this->render('front/homepage/show.html.twig', [
  71.             'totalPoint' => $totalMovement,
  72.             't' => $t,
  73.         ]);
  74.     }
  75. }