mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented routing for law show
This commit is contained in:
		| @@ -3,6 +3,7 @@ namespace App\Controller; | |||||||
|  |  | ||||||
| use App\Entity\EntityInterface; | use App\Entity\EntityInterface; | ||||||
| use FOS\RestBundle\Controller\FOSRestController; | use FOS\RestBundle\Controller\FOSRestController; | ||||||
|  | use Symfony\Component\HttpFoundation\RedirectResponse; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * |  * | ||||||
| @@ -32,4 +33,11 @@ abstract class AbstractEntityController extends FOSRestController | |||||||
|         } |         } | ||||||
|         return $entity; |         return $entity; | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     protected function redirectToRouteById(string $route, int $id): RedirectResponse | ||||||
|  |     { | ||||||
|  |         return $this->redirectToRoute($route, [ | ||||||
|  |             'id' => $id | ||||||
|  |         ]); | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Response; | |||||||
| use Symfony\Component\Routing\Annotation\Route; | use Symfony\Component\Routing\Annotation\Route; | ||||||
| use App\Entity\NodeInterface; | use App\Entity\NodeInterface; | ||||||
| use App\Entity\Node; | use App\Entity\Node; | ||||||
|  | use Symfony\Component\HttpFoundation\RedirectResponse; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @todo IMPLEMENT SECURITY! |  * @todo IMPLEMENT SECURITY! | ||||||
| @@ -30,6 +31,15 @@ class NodeController extends AbstractEntityController | |||||||
|         return $this->handleView($view); |         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 |     protected function setEntityName(): void | ||||||
|     { |     { | ||||||
|         $this->entityName = Node::class; |         $this->entityName = Node::class; | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
| <?php | <?php | ||||||
|  |  | ||||||
| namespace App\Controller; | namespace App\Controller; | ||||||
|  |  | ||||||
| use Symfony\Component\HttpFoundation\Response; | use Symfony\Component\HttpFoundation\Response; | ||||||
| @@ -13,30 +12,35 @@ use App\Creator\Factory\Template\Source\SourceTemplateFormFactory; | |||||||
| use App\Creator\Factory\Form\Source\SourceFormFactory; | use App\Creator\Factory\Form\Source\SourceFormFactory; | ||||||
| use Symfony\Component\HttpFoundation\RedirectResponse; | use Symfony\Component\HttpFoundation\RedirectResponse; | ||||||
| use App\Entity\Source\AbstractSource; | use App\Entity\Source\AbstractSource; | ||||||
|  | use App\Entity\NodeInterface; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @todo IMPLEMENT SECURITY! |  | ||||||
|  * |  * | ||||||
|  |  * @todo IMPLEMENT SECURITY! | ||||||
|  |  *       | ||||||
|  * @author kevinfrantz |  * @author kevinfrantz | ||||||
|  */ |  */ | ||||||
| class SourceController extends AbstractEntityController | class SourceController extends AbstractEntityController | ||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @Route("/source/{id}.{_format}", defaults={"_format"="html"}) |      * @Route("/source/{id}.{_format}", defaults={"_format"="html"}) | ||||||
|      */ |      */ | ||||||
|     public function show(Request $request, int $id): Response |     public function show(Request $request, int $id): Response | ||||||
|     { |     { | ||||||
|         $source = $this->loadEntityById($id); |         $source = $this->loadEntityById($id); | ||||||
|         #$assembler = $this->get(SourceDTOAssember::class); |         // $assembler = $this->get(SourceDTOAssember::class); | ||||||
|         #$dto = $assembler->build($source, $this->getUser()); |         // $dto = $assembler->build($source, $this->getUser()); | ||||||
|         $view = $this->view($source, 200) |         $view = $this->view($source, 200) | ||||||
|             ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) |             ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) | ||||||
|             ->setTemplateVar('source'); |             ->setTemplateVar('source'); | ||||||
|  |          | ||||||
|         return $this->handleView($view); |         return $this->handleView($view); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) |      * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) | ||||||
|      */ |      */ | ||||||
|     public function edit(Request $request, int $id): Response |     public function edit(Request $request, int $id): Response | ||||||
| @@ -48,19 +52,24 @@ class SourceController extends AbstractEntityController | |||||||
|             $source = $form->getData(); |             $source = $form->getData(); | ||||||
|             $this->saveSource($source); |             $this->saveSource($source); | ||||||
|         } |         } | ||||||
|  |          | ||||||
|         return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ |         return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ | ||||||
|             'form' => $form->createView(), |             'form' => $form->createView() | ||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"}) |      * @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); |         $nodeId = $this->loadNodeById($id)->getId(); | ||||||
|         return $this->redirectToRoute('app_node_show', ['id' => $source->getNode()->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 |     private function saveSource(SourceInterface $source): void | ||||||
| @@ -69,10 +78,9 @@ class SourceController extends AbstractEntityController | |||||||
|         $entityManager->persist($source); |         $entityManager->persist($source); | ||||||
|         $entityManager->flush(); |         $entityManager->flush(); | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     protected function setEntityName(): void |     protected function setEntityName(): void | ||||||
|     { |     { | ||||||
|         $this->entityName = AbstractSource::class; |         $this->entityName = AbstractSource::class; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user