From 379e9c62e94697384a2d572d8221af07f9c83893 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 4 Oct 2018 20:48:12 +0200 Subject: [PATCH] Implemented routing for law show --- .../Controller/AbstractEntityController.php | 8 +++++ application/src/Controller/NodeController.php | 10 ++++++ .../src/Controller/SourceController.php | 32 ++++++++++++------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/application/src/Controller/AbstractEntityController.php b/application/src/Controller/AbstractEntityController.php index 617785f..7278006 100644 --- a/application/src/Controller/AbstractEntityController.php +++ b/application/src/Controller/AbstractEntityController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\EntityInterface; use FOS\RestBundle\Controller\FOSRestController; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * @@ -32,4 +33,11 @@ abstract class AbstractEntityController extends FOSRestController } return $entity; } + + protected function redirectToRouteById(string $route, int $id): RedirectResponse + { + return $this->redirectToRoute($route, [ + 'id' => $id + ]); + } } \ No newline at end of file diff --git a/application/src/Controller/NodeController.php b/application/src/Controller/NodeController.php index fb5f75b..47a73c6 100644 --- a/application/src/Controller/NodeController.php +++ b/application/src/Controller/NodeController.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use App\Entity\NodeInterface; use App\Entity\Node; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * @todo IMPLEMENT SECURITY! @@ -30,6 +31,15 @@ class NodeController extends AbstractEntityController return $this->handleView($view); } + /** + * @Route("/node/{id}/law.{_format}", defaults={"_format"="html"}) + */ + public function law(int $id): RedirectResponse + { + $lawId = $this->loadEntityById($id)->getLaw()->getId(); + return $this->redirectToRouteById('app_law_show',$lawId); + } + protected function setEntityName(): void { $this->entityName = Node::class; diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index 5791acf..0945f15 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -1,5 +1,4 @@ loadEntityById($id); - #$assembler = $this->get(SourceDTOAssember::class); - #$dto = $assembler->build($source, $this->getUser()); + // $assembler = $this->get(SourceDTOAssember::class); + // $dto = $assembler->build($source, $this->getUser()); $view = $this->view($source, 200) ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) ->setTemplateVar('source'); - + return $this->handleView($view); } /** + * * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) */ public function edit(Request $request, int $id): Response @@ -48,19 +52,24 @@ class SourceController extends AbstractEntityController $source = $form->getData(); $this->saveSource($source); } - + return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ - 'form' => $form->createView(), + 'form' => $form->createView() ]); } /** + * * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"}) */ - public function node(Request $request, int $id): RedirectResponse + public function node(int $id): RedirectResponse { - $source = $this->loadEntityById($id); - return $this->redirectToRoute('app_node_show', ['id' => $source->getNode()->getId()]); + $nodeId = $this->loadNodeById($id)->getId(); + return $this->redirectToRouteById('app_node_show',$nodeId); + } + + private function loadNodeById(int $id):NodeInterface{ + return $this->loadEntityById($id)->getNode(); } private function saveSource(SourceInterface $source): void @@ -69,10 +78,9 @@ class SourceController extends AbstractEntityController $entityManager->persist($source); $entityManager->flush(); } - + protected function setEntityName(): void { $this->entityName = AbstractSource::class; } - }