<?php
namespace App\Controller;
use App\Entity\Categoria;
use App\Entity\Mueble;
use App\Repository\CategoriaRepository;
use App\Repository\MuebleRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
/**
* @IsGranted("IS_AUTHENTICATED_FULLY")
*/
class TiendaController extends AbstractController
{
private $entityManager;
private $security;
public function __construct(EntityManagerInterface $entityManager, Security $security)
{
$this->entityManager = $entityManager;
$this->security = $security;
}
/**
* @Route("/tienda/{categoriaId?}", name="tienda")
*/
public function index(CategoriaRepository $categoriaRepository, MuebleRepository $muebleRepository, Request $request, $categoriaId = null): Response
{
$categorias = $categoriaRepository->findAll();
$muebles = [];
if ($categoriaId) {
$categoria = $categoriaRepository->find($categoriaId);
if ($categoria) {
$muebles = $muebleRepository->findBy(['categoria' => $categoria]);
}
} else {
$muebles = $muebleRepository->findAll();
}
return $this->render('web/tienda.html.twig', [
'categorias' => $categorias,
'categoriaId' => $categoriaId,
'muebles' => $muebles
]);
}
/**
* @Route("/inventario", name="inventario")
*/
public function inventario(): Response {
return $this->render('web/inventario.html.twig');
}
}