src/Controller/HomePageController.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CMS\CmsContent;
  4. use App\Entity\Company\Brand;
  5. use App\Form\CMS\CmsType;
  6. use App\Service\EditService;
  7. use App\Service\NavService;
  8. use App\Service\UserSeasonService;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
  14. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  15. class HomePageController extends Controller
  16. {
  17.     /**
  18.      * @Route(
  19.      *     "/accueil/modification/{slug}/{id}",
  20.      *     defaults={"slug"="", "id"=1},
  21.      *     name="index_edit"
  22.      * )
  23.      */
  24.     public function edit(
  25.         EditService $editService,
  26.         UserSeasonService $userSeasonService,
  27.         Request $request,
  28.         string $slug,
  29.         int $id
  30.     ){
  31.         $roles = ['ROLE_ADMIN_COMPANY'];
  32.         $type 'index';
  33.         $formClass CmsType::class;
  34.         $event $userSeasonService->getBrand($this->getUser());
  35.         if ($return $editService->checkEventAuthorization($request$id$slug$roles$type$event)) {
  36.             return $return;
  37.         }
  38.         return $this->render('index_edit.html.twig'$editService->returnForm($request$formClass$type$event));
  39.     }
  40.     /**
  41.      * @Route("/", name="index")
  42.      */
  43.     public function index(UserSeasonService $userSeasonServicee)
  44.     {
  45.         $canEdit false;
  46.         if (
  47.             $this->isGranted('ROLE_ADMIN_COMPANY') &&
  48.             (empty($this->getUser()->getTestUserType()) || $this->getUser()->getTestUserType() === 'ADMIN')
  49.         ) {
  50.             $canEdit true;
  51.         }
  52.         if ($this->getUser()) {
  53.             $index 'index.html.twig';
  54.         } else {
  55.             $index 'index_default.html.twig';
  56.         }
  57.         $brand $userSeasonServicee->getBrand($this->getUser());
  58.         return $this->render($index, ['brand' => $brand'canEdit' => $canEdit]);
  59.     }
  60.     /**
  61.      * @Route(
  62.      *     "/accueil/{slug}/{id}",
  63.      *     defaults={"slug"="", "id"=1},
  64.      *     name="index_view"
  65.      *)
  66.      */
  67.     public function indexView($slug$id)
  68.     {
  69.         return $this->redirectToRoute('index');
  70.     }
  71.     /**
  72.      * @Route(
  73.      *   "/homepage/season-change",
  74.      *   name="season_change"
  75.      * )
  76.      */
  77.     public function seasonChange(Request $requestUserSeasonService $userSeasonService)
  78.     {
  79.         $seasonChange $request->request->get('season_change');
  80.         if (!empty($seasonChange) && !empty($seasonChange['season'])) {
  81.             $user $this->getUser();
  82.             $seasons $userSeasonService->getAllSeasonByUser($user);
  83.             foreach ($seasons as $season) {
  84.                 if ($season->getId() === intval($seasonChange['season'])) {
  85.                     $userSeasonService->setSeasonByUser($user$season);
  86.                     return $this->redirect($request->headers->get('referer'));
  87.                 }
  88.             }
  89.         }
  90.         throw new NotFoundHttpException('app.error.404');
  91.     }
  92. }