src/Controller/HomeController.php line 23
<?php
namespace App\Controller;
use App\Repository\UserRepository;
use App\Services\FunnelConversionService;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
private $funnelConversionService;
public function __construct(FunnelConversionService $funnelConversionService)
{
$this->funnelConversionService = $funnelConversionService;
}
#[Route('/', name: 'app_home')]
public function myObjectifs(): Response
{
$user = $this->getUser();
if ($user) {
return $this->redirectToRoute('app_me', [
'userName' => $user->getUserName(),
]);
} else {
return $this->render('landing_pages/landing_V1.html.twig');
}
}
#[Route('/={userName}', name: 'app_me')]
public function me($userName, UserRepository $userRepo): Response
{
$connectedUser = $this->getUser() ? true : false;
$connectedUserName = null;
$connectedUserId = null;
$messageOnSite = null;
$remainingDays = null;
$lockedApp = false;
if ($connectedUser) {
$objectUser = $this->getUser();
$connectedUserName = $this->getUser()->getUserName();
$connectedUserId = $this->getUser()->getId();
/* Vérifier si l'abonnement est toujours actif */
if ($objectUser->getSubscription()) {
if ($objectUser->getSubscription()->getStatus() != "active") {
$lockedApp = true;
}
}
/* Vérifier la période d'essai est terminée */
if (!$objectUser->getSubscription()) {
$remainingDays = 0;
/* $remainingDays = $this->funnelConversionService->checkRemainingDays($objectUser); */
$messageOnSite = $this->funnelConversionService->getDailyMessageAfterRegistration($remainingDays);
if ($remainingDays <= 0) {
$lockedApp = true;
}
}
}
$user = $userRepo->findOneByUserName($userName);
if ($user) {
$usersObjectifs = $user->getObjectifs();
$actionsDone = 0;
$isPrivateProfil = $user->isIsPrivate();
if ($usersObjectifs) {
foreach ($usersObjectifs as $objo) {
foreach ($objo->getDates() as $done) {
$actionsDone++;
}
}
}
return $this->render('home/home.html.twig', [
'user' => $user,
'actionsDone' => $actionsDone,
'connectedUser' => $connectedUser,
'isPrivateProfil' => $isPrivateProfil,
'connectedUserName' => $connectedUserName,
'userNamePageProfil' => $userName,
'connectedUserId' => $connectedUserId,
'RemainingDaysMessage' => $messageOnSite,
'lockedApp' => $lockedApp
]);
} else {
return $this->render('landing_pages/landing_V1.html.twig');
}
}
}