<?php
namespace App\Controller;
use App\Entity\Image\ImageEntity;
use App\Form\CMS\CmsType;
use App\Service\AnimationLinkRetriverService;
use App\Service\EditService;
use App\Service\UserSeasonService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\StaticPage;
class ZStaticPageController extends Controller
{
/**
* @Route(
* "/page-statique/modification/{slug}/{id}",
* defaults={"slug"="", "id"=1},
* name="static_edit"
* )
*/
public function edit(
AnimationLinkRetriverService $animationService,
EditService $editService,
EntityManagerInterface $em,
Request $request,
string $slug,
int $id
){
$roles = ['ROLE_ADMIN_PLATFORM'];
$type = 'static';
$formClass = CmsType::class;
$event = $em->getRepository(StaticPage::class)->find($id);
if ($return = $editService->checkEventAuthorization($request, $id, $slug, $roles, $type, $event, true)) {
return $return;
}
$animationGroupes = $animationService->retriveAnimationGroupe($event->getAnimationGroups());
return $this->render('StaticPage/edit.html.twig',
array_merge($editService->returnForm($request, $formClass, $type, $event), [
'animationGroupes' => $animationGroupes,
'isEdit' => true,
])
);
}
/**
* @Route(
* "/page-statique/{id}/{slug}",
* defaults={"slug"="", "id"=1},
* name="static_view"
*)
*/
public function staticView(EntityManagerInterface $em, $slug, $id)
{
$static = $em->getRepository(StaticPage::class)->find($id);
if (null === $static) {
throw new NotFoundHttpException('app.error.404');
}
return $this->redirect($static->getRelativeUrl());
}
/**
* @Route("/{uri}/")
* @Route("/{uri}/{uri_Two}/")
* @Route("/{uri}/{uri_Two}/{uri_Three}/")
* @ParamConverter("staticPage", class="App\Entity\StaticPage", options={
* "repository_method" = "getStaticByUri",
* "mapping": {"uri": "uriOne", "uri_Two": "uriTwo", "uri_Three": "uriThree"},
* "map_method_signature" = true
* })
*/
public function view(
AnimationLinkRetriverService $animationService,
StaticPage $staticPage
){
$animationGroupes = $animationService->retriveAnimationGroupe($staticPage->getAnimationGroups());
$canEdit = false;
if (
$this->isGranted('ROLE_ADMIN_PLATFORM') &&
(empty($this->getUser()->getTestUserType()) || $this->getUser()->getTestUserType() === 'ADMIN')
) {
$canEdit = true;
}
return $this->render('StaticPage/view.html.twig', [
'event' => $staticPage,
'animationGroupes' => $animationGroupes,
'origine' => 'static',
'canEdit' => $canEdit
]);
}
}