mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Implemented view for node
This commit is contained in:
		
							
								
								
									
										43
									
								
								application/src/Controller/NodeController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								application/src/Controller/NodeController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Controller;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\Controller\FOSRestController;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Request;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Response;
 | 
			
		||||
use Symfony\Component\Routing\Annotation\Route;
 | 
			
		||||
use App\Entity\NodeInterface;
 | 
			
		||||
use App\Entity\Node;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @todo IMPLEMENT SECURITY!
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class NodeController extends FOSRestController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @Route("/node/{id}.{_format}", defaults={"_format"="html"})
 | 
			
		||||
     */
 | 
			
		||||
    public function show(Request $request, int $id): Response
 | 
			
		||||
    {
 | 
			
		||||
        $node = $this->loadSource($request, $id);
 | 
			
		||||
        $view = $this->view($node, 200)
 | 
			
		||||
        ->setTemplate('node/view/standard.html.twig')
 | 
			
		||||
        ->setTemplateVar('node');
 | 
			
		||||
 | 
			
		||||
        return $this->handleView($view);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function loadSource(Request $request, int $id): NodeInterface
 | 
			
		||||
    {
 | 
			
		||||
        $node = $this->getDoctrine()
 | 
			
		||||
        ->getRepository(Node::class)
 | 
			
		||||
        ->find($id);
 | 
			
		||||
        if (!$node) {
 | 
			
		||||
            throw $this->createNotFoundException('No node found for id '.$id);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $node;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -11,6 +11,7 @@ use FOS\RestBundle\Controller\FOSRestController;
 | 
			
		||||
use App\Entity\SourceInterface;
 | 
			
		||||
use App\Creator\Factory\Template\Source\SourceTemplateFormFactory;
 | 
			
		||||
use App\Creator\Factory\Form\Source\SourceFormFactory;
 | 
			
		||||
use Symfony\Component\HttpFoundation\RedirectResponse;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @todo IMPLEMENT SECURITY!
 | 
			
		||||
@@ -50,6 +51,16 @@ class SourceController extends FOSRestController
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"})
 | 
			
		||||
     */
 | 
			
		||||
    public function node(Request $request, int $id): RedirectResponse
 | 
			
		||||
    {
 | 
			
		||||
        $source = $this->loadSource($request, $id);
 | 
			
		||||
 | 
			
		||||
        return $this->redirectToRoute('app_node_show', ['id' => $source->getNode()->getId()]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function loadSource(Request $request, int $id): SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
        $source = $this->getDoctrine()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user