refs #1287. Created menu templates and controller
testing/ogcore-api/pipeline/head This commit looks good Details

pull/18/head
Manuel Aranda Rosales 2024-12-20 08:33:49 +01:00
parent 094ff7d34c
commit fb381b9627
1 changed files with 39 additions and 3 deletions

View File

@ -4,20 +4,56 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Client;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Twig\Environment;
class TestController extends AbstractController
class MenuBrowserController extends AbstractController
{
public function __construct(
protected readonly EntityManagerInterface $entityManager,
private Environment $twig,
)
{
}
#[Route('/menu-browser')]
public function index(Request $request): Response
{
$host = $request->getHost();
$host = $request->getClientIp();
return $this->render('test.html.twig', [
$partitions = [];
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $host]);
if ($client) {
$partitions = $client->getPartitions();
}
$menuName = $client->getMenu()->getPublicUrl();
return $this->render('browser/' . $menuName . '.html.twig', [
'ip' => $host,
'partitions' => $partitions,
]);
}
#[Route('/menu/{templateName}', name: 'render_menu_template')]
public function renderMenu(string $templateName, Request $request): Response
{
$templatePath = 'browser/' . $templateName . '.html.twig';
if (!$this->twig->getLoader()->exists($templatePath)) {
throw $this->createNotFoundException(sprintf('La plantilla "%s" no existe.', $templateName));
}
return $this->render($templatePath, [
'ip' => 'invitado',
'partitions' => [],
]);
}
}