<?php
namespace App\Controller;
use App\Entity\CMS\CmsContent;
use App\Entity\Company\Brand;
use App\Form\CMS\CmsType;
use App\Service\EditService;
use App\Service\NavService;
use App\Service\UserSeasonService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class HomePageController extends Controller
{
/**
* @Route(
* "/accueil/modification/{slug}/{id}",
* defaults={"slug"="", "id"=1},
* name="index_edit"
* )
*/
public function edit(
EditService $editService,
UserSeasonService $userSeasonService,
Request $request,
string $slug,
int $id
){
$roles = ['ROLE_ADMIN_COMPANY'];
$type = 'index';
$formClass = CmsType::class;
$event = $userSeasonService->getBrand($this->getUser());
if ($return = $editService->checkEventAuthorization($request, $id, $slug, $roles, $type, $event)) {
return $return;
}
return $this->render('index_edit.html.twig', $editService->returnForm($request, $formClass, $type, $event));
}
/**
* @Route("/", name="index")
*/
public function index(UserSeasonService $userSeasonServicee)
{
$canEdit = false;
if (
$this->isGranted('ROLE_ADMIN_COMPANY') &&
(empty($this->getUser()->getTestUserType()) || $this->getUser()->getTestUserType() === 'ADMIN')
) {
$canEdit = true;
}
if ($this->getUser()) {
$index = 'index.html.twig';
} else {
$index = 'index_default.html.twig';
}
$brand = $userSeasonServicee->getBrand($this->getUser());
return $this->render($index, ['brand' => $brand, 'canEdit' => $canEdit]);
}
/**
* @Route(
* "/accueil/{slug}/{id}",
* defaults={"slug"="", "id"=1},
* name="index_view"
*)
*/
public function indexView($slug, $id)
{
return $this->redirectToRoute('index');
}
/**
* @Route(
* "/homepage/season-change",
* name="season_change"
* )
*/
public function seasonChange(Request $request, UserSeasonService $userSeasonService)
{
$seasonChange = $request->request->get('season_change');
if (!empty($seasonChange) && !empty($seasonChange['season'])) {
$user = $this->getUser();
$seasons = $userSeasonService->getAllSeasonByUser($user);
foreach ($seasons as $season) {
if ($season->getId() === intval($seasonChange['season'])) {
$userSeasonService->setSeasonByUser($user, $season);
return $this->redirect($request->headers->get('referer'));
}
}
}
throw new NotFoundHttpException('app.error.404');
}
}