<?php
namespace App\Controller;
use App\Entity\User;
use App\Repository\PageRepository;
use App\Service\StudentService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MainController extends AbstractController
{
private StudentService $studentService;
private PageRepository $pageRepository;
public function __construct(StudentService $studentService, PageRepository $pageRepository)
{
$this->studentService = $studentService;
$this->pageRepository = $pageRepository;
}
/**
* @Route("/", name="main")
*/
public function index(): Response
{
/** @var User $user */
$user = $this->getUser();
if ($user) {
$courses = $this->studentService->getInProgressCourses($user);
return $this->render('main/index_logged_in.html.twig', [
'inProgressCourses' => $courses
]);
}
$page = $this->pageRepository->findOneByName('main');
return $this->render('main/index.html.twig', [
'content' => $page->getContent()
]);
}
}