src/Controller/HomeController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Repository\SeasonRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class HomeController extends AbstractController
  9. {
  10.     private SeasonRepository $seasonRepository;
  11.     public function __construct(SeasonRepository $seasonRepository)
  12.     {
  13.         $this->seasonRepository $seasonRepository;
  14.     }
  15.     /**
  16.      * @Route("/", name="app_home")
  17.      */
  18.     public function index(): Response
  19.     {
  20.         return $this->render('home/index.html.twig', [
  21.             'page_title' => 'Fatness for Service - Corporate Health & Fitness Challenges',
  22.             'meta_description' => 'Transform your workplace with team fitness challenges. Boost morale, improve health, and build team spirit through friendly competition.',
  23.         ]);
  24.     }
  25.     #[Route("/dashboard"name"app_dashboard"methods: ["GET"])]
  26.     public function dashboard(): Response
  27.     {
  28.         /** @var User $user */
  29.         $user $this->getUser();
  30.         if (!$user) {
  31.             return $this->redirectToRoute('app_login');
  32.         }
  33.         $company $user->getCompany();
  34.         if (!$company) {
  35.             // This case should ideally not happen if users are always associated with a company
  36.             $this->addFlash('warning''You are not associated with any company.');
  37.             return $this->redirectToRoute('app_home'); // Or some other appropriate default page
  38.         }
  39.         $activeSeasons $this->seasonRepository->findBy(['company' => $company'isActive' => true], ['startDate' => 'DESC']);
  40.         if (empty($activeSeasons)) {
  41.             $this->addFlash('info''There are no active seasons currently. You can browse available seasons to join.');
  42.             return $this->redirectToRoute('app_season_index'); // Redirect to season list
  43.         }
  44.         // Redirect to the first active season found (most recent if multiple are active)
  45.         return $this->redirectToRoute('app_season_show', ['id' => $activeSeasons[0]->getId()]);
  46.     }
  47. }