<?php
namespace App\Controller\Front;
use App\Filter\Front\GlobalSearchExtendedType;
use App\Repository\Scholar\TrainingRepository;
use App\Service\NellappGlobalStatsService;
use Nellapp\Bundle\SDKBundle\Routing\Utils\ChannelMainDomainUtils;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
public function __construct(
private TrainingRepository $trainingRepository,
private NellappGlobalStatsService $cacheService,
private ChannelMainDomainUtils $channelMainDomainUtils,
)
{
}
#[Route(path: '/', name: 'home', methods: ['GET'])]
public function __invoke(Request $request): Response
{
$channel = $this->channelMainDomainUtils->getChannelFromRequest($request);
if ($channel !== null) {
return $this->redirectToRoute('front_channel_show', [
'channelId' => $channel->getId(),
]);
}
if ($this->getUser() !== null) {
return $this->redirectToRoute('home_connected');
}
$homeFilters = $this->createForm(GlobalSearchExtendedType::class, null, [
'totalHoursDescriptionMax' => $this->trainingRepository->findMaxHoursDescription(),
]);
$globalStats = $this->cacheService->getGlobalStats();
$popularTrainingsDTOs = $globalStats->getPopularTrainingDTOs();
return $this->render('Front/Pages/home/home.html.twig', [
'global_stats' => $globalStats,
'popular_trainings' => $popularTrainingsDTOs,
'home_filters' => $homeFilters->createView(),
]);
}
}