mirror of
https://forge.chapril.org/tykayn/caisse-bliss
synced 2025-06-20 01:44:42 +02:00
82 lines
3.1 KiB
PHP
82 lines
3.1 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace App\Controller;
|
||
|
|
||
|
use App\Entity\GroupOfProducts;
|
||
|
use App\Form\GroupOfProductsType;
|
||
|
use App\Repository\GroupOfProductsRepository;
|
||
|
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;
|
||
|
|
||
|
#[Route('/group/of/products')]
|
||
|
final class GroupOfProductsController extends AbstractController
|
||
|
{
|
||
|
#[Route(name: 'app_group_of_products_index', methods: ['GET'])]
|
||
|
public function index(GroupOfProductsRepository $groupOfProductsRepository): Response
|
||
|
{
|
||
|
return $this->render('group_of_products/index.html.twig', [
|
||
|
'group_of_products' => $groupOfProductsRepository->findAll(),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
#[Route('/new', name: 'app_group_of_products_new', methods: ['GET', 'POST'])]
|
||
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||
|
{
|
||
|
$groupOfProduct = new GroupOfProducts();
|
||
|
$form = $this->createForm(GroupOfProductsType::class, $groupOfProduct);
|
||
|
$form->handleRequest($request);
|
||
|
|
||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||
|
$entityManager->persist($groupOfProduct);
|
||
|
$entityManager->flush();
|
||
|
|
||
|
return $this->redirectToRoute('app_group_of_products_index', [], Response::HTTP_SEE_OTHER);
|
||
|
}
|
||
|
|
||
|
return $this->render('group_of_products/new.html.twig', [
|
||
|
'group_of_product' => $groupOfProduct,
|
||
|
'form' => $form,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
#[Route('/{id}', name: 'app_group_of_products_show', methods: ['GET'])]
|
||
|
public function show(GroupOfProducts $groupOfProduct): Response
|
||
|
{
|
||
|
return $this->render('group_of_products/show.html.twig', [
|
||
|
'group_of_product' => $groupOfProduct,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
#[Route('/{id}/edit', name: 'app_group_of_products_edit', methods: ['GET', 'POST'])]
|
||
|
public function edit(Request $request, GroupOfProducts $groupOfProduct, EntityManagerInterface $entityManager): Response
|
||
|
{
|
||
|
$form = $this->createForm(GroupOfProductsType::class, $groupOfProduct);
|
||
|
$form->handleRequest($request);
|
||
|
|
||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||
|
$entityManager->flush();
|
||
|
|
||
|
return $this->redirectToRoute('app_group_of_products_index', [], Response::HTTP_SEE_OTHER);
|
||
|
}
|
||
|
|
||
|
return $this->render('group_of_products/edit.html.twig', [
|
||
|
'group_of_product' => $groupOfProduct,
|
||
|
'form' => $form,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
#[Route('/{id}', name: 'app_group_of_products_delete', methods: ['POST'])]
|
||
|
public function delete(Request $request, GroupOfProducts $groupOfProduct, EntityManagerInterface $entityManager): Response
|
||
|
{
|
||
|
if ($this->isCsrfTokenValid('delete'.$groupOfProduct->getId(), $request->getPayload()->getString('_token'))) {
|
||
|
$entityManager->remove($groupOfProduct);
|
||
|
$entityManager->flush();
|
||
|
}
|
||
|
|
||
|
return $this->redirectToRoute('app_group_of_products_index', [], Response::HTTP_SEE_OTHER);
|
||
|
}
|
||
|
}
|