src/Controller/Front/HomeController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Filter\Front\GlobalSearchExtendedType;
  4. use App\Repository\Scholar\TrainingRepository;
  5. use App\Service\NellappGlobalStatsService;
  6. use Nellapp\Bundle\SDKBundle\Routing\Utils\ChannelMainDomainUtils;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class HomeController extends AbstractController
  12. {
  13. public function __construct(
  14. private TrainingRepository $trainingRepository,
  15. private NellappGlobalStatsService $cacheService,
  16. private ChannelMainDomainUtils $channelMainDomainUtils,
  17. )
  18. {
  19. }
  20. #[Route(path: '/', name: 'home', methods: ['GET'])]
  21. public function __invoke(Request $request): Response
  22. {
  23. $channel = $this->channelMainDomainUtils->getChannelFromRequest($request);
  24. if ($channel !== null) {
  25. return $this->redirectToRoute('front_channel_show', [
  26. 'channelId' => $channel->getId(),
  27. ]);
  28. }
  29. if ($this->getUser() !== null) {
  30. return $this->redirectToRoute('home_connected');
  31. }
  32. $homeFilters = $this->createForm(GlobalSearchExtendedType::class, null, [
  33. 'totalHoursDescriptionMax' => $this->trainingRepository->findMaxHoursDescription(),
  34. ]);
  35. $globalStats = $this->cacheService->getGlobalStats();
  36. $popularTrainingsDTOs = $globalStats->getPopularTrainingDTOs();
  37. return $this->render('Front/Pages/home/home.html.twig', [
  38. 'global_stats' => $globalStats,
  39. 'popular_trainings' => $popularTrainingsDTOs,
  40. 'home_filters' => $homeFilters->createView(),
  41. ]);
  42. }
  43. }