<?php
namespace App\Controller;
use App\Entity\User;
use App\Repository\SeasonRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
private SeasonRepository $seasonRepository;
public function __construct(SeasonRepository $seasonRepository)
{
$this->seasonRepository = $seasonRepository;
}
/**
* @Route("/", name="app_home")
*/
public function index(): Response
{
return $this->render('home/index.html.twig', [
'page_title' => 'Fatness for Service - Corporate Health & Fitness Challenges',
'meta_description' => 'Transform your workplace with team fitness challenges. Boost morale, improve health, and build team spirit through friendly competition.',
]);
}
#[Route("/dashboard", name: "app_dashboard", methods: ["GET"])]
public function dashboard(): Response
{
/** @var User $user */
$user = $this->getUser();
if (!$user) {
return $this->redirectToRoute('app_login');
}
$company = $user->getCompany();
if (!$company) {
// This case should ideally not happen if users are always associated with a company
$this->addFlash('warning', 'You are not associated with any company.');
return $this->redirectToRoute('app_home'); // Or some other appropriate default page
}
$activeSeasons = $this->seasonRepository->findBy(['company' => $company, 'isActive' => true], ['startDate' => 'DESC']);
if (empty($activeSeasons)) {
$this->addFlash('info', 'There are no active seasons currently. You can browse available seasons to join.');
return $this->redirectToRoute('app_season_index'); // Redirect to season list
}
// Redirect to the first active season found (most recent if multiple are active)
return $this->redirectToRoute('app_season_show', ['id' => $activeSeasons[0]->getId()]);
}
}