<?php
/******************************************************************************
* Copyright (c) Echo-numeric 2020-2023. *
******************************************************************************/
namespace App\Controller\Front;
use App\Entity\User;
use App\Factory\PointFactory;
use App\Services\Common\PlatformService;
use App\Services\Common\Point\UserPointServiceInterface;
use App\Services\Common\User\WorkflowUser;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class HomePageController extends AbstractController
{
private UserPointServiceInterface $userPointService;
private EntityManagerInterface $em;
private PlatformService $platformService;
private WorkflowUser $workflowUser;
/**
* @throws Exception
*/
public function __construct(
EntityManagerInterface $em,
PlatformService $platformService,
WorkflowUser $workflowUser,
PointFactory $pointFactory
)
{
$this->userPointService = $pointFactory->getUserPointService();
$this->em = $em;
$this->platformService = $platformService;
$this->workflowUser = $workflowUser;
}
/**
* Page d'accueil pour les utilisateurs identifiés
*
* @param Request $request
*
* @return Response
*
* @throws Exception
*/
public function show(Request $request): Response
{
if ($this->platformService->getType() === 'dtv') {
return $this->redirectToRoute('dtv_back_dashboard_show');
}
/** @var User $currentUser */
$currentUser = $this->getUser();
$t = $this->userPointService->getLevel($currentUser);
$totalMovement = [
"debit" => $this->userPointService->getSpendedPoints($currentUser),
"credit" => $this->userPointService->getFidelityPoints($currentUser),
'expired' => -abs($this->userPointService->getExpiredPoints($currentUser)),
'exceptional' => $this->userPointService->getExceptionalPoints($currentUser),
];
if ($request->getMethod() === 'POST') {
$choice = $request->request->get('donneesPersonnellesChoice');
$currentUser->setDonneesPersonnelles($choice);
if ($choice === FALSE) {
$this->workflowUser->unsubscribeUser($currentUser);
return $this->redirectToRoute('saml_logout');
}
$this->em->persist($currentUser);
$this->em->flush();
}
return $this->render('front/homepage/show.html.twig', [
'totalPoint' => $totalMovement,
't' => $t,
]);
}
}