2022-09-29 20:09:31 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Entity\Brand;
|
|
|
|
use App\Form\BrandType;
|
2022-09-30 10:48:14 -04:00
|
|
|
use App\Traits\FormControllerTrait;
|
2022-09-29 20:09:31 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
#[Route('/brand')]
|
|
|
|
class BrandController extends AbstractController
|
|
|
|
{
|
|
|
|
use FormControllerTrait;
|
|
|
|
|
|
|
|
protected const ENTITY = Brand::class;
|
|
|
|
protected const TEMPLATE_PATH = 'brand/';
|
|
|
|
protected const ROUTE_PREFIX = 'brand_';
|
|
|
|
protected const FORM = BrandType::class;
|
|
|
|
|
|
|
|
public function __construct(private readonly EntityManagerInterface $entityManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/', name: 'brand_index', methods: ['GET'])]
|
2022-09-30 10:48:14 -04:00
|
|
|
public function index(): Response
|
2022-09-29 20:09:31 -04:00
|
|
|
{
|
2022-09-30 10:48:14 -04:00
|
|
|
return $this->itemListView('brands', [
|
|
|
|
'name' => 'asc'
|
|
|
|
]);
|
2022-09-29 20:09:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/new', name: 'brand_new', methods: ['GET', 'POST'])]
|
2022-09-30 10:48:14 -04:00
|
|
|
public function new(Request $request): Response
|
2022-09-29 20:09:31 -04:00
|
|
|
{
|
2022-09-30 10:48:14 -04:00
|
|
|
return $this->itemCreate($request, 'brand');
|
2022-09-29 20:09:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'brand_show', methods: ['GET'])]
|
|
|
|
public function show(Brand $brand): Response
|
|
|
|
{
|
2022-09-30 10:48:14 -04:00
|
|
|
return $this->itemView($brand, 'brand');
|
2022-09-29 20:09:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}/edit', name: 'brand_edit', methods: ['GET', 'POST'])]
|
2022-09-30 10:48:14 -04:00
|
|
|
public function edit(Request $request, Brand $brand): Response
|
2022-09-29 20:09:31 -04:00
|
|
|
{
|
2022-09-30 10:48:14 -04:00
|
|
|
return $this->itemUpdate($request, $brand, 'brand');
|
|
|
|
//
|
|
|
|
// $form = $this->createForm(BrandType::class, $brand);
|
|
|
|
// $form->handleRequest($request);
|
|
|
|
//
|
|
|
|
// if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
// $entityManager->flush();
|
|
|
|
//
|
|
|
|
// return $this->redirectToRoute('brand_index', [], Response::HTTP_SEE_OTHER);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return $this->renderForm('brand/edit.html.twig', [
|
|
|
|
// 'brand' => $brand,
|
|
|
|
// 'form' => $form,
|
|
|
|
// ]);
|
2022-09-29 20:09:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'brand_delete', methods: ['POST'])]
|
2022-09-30 10:48:14 -04:00
|
|
|
public function delete(Request $request, Brand $brand): Response
|
2022-09-29 20:09:31 -04:00
|
|
|
{
|
2022-09-30 10:48:14 -04:00
|
|
|
return $this->deleteCSRF($request, $brand);
|
2022-09-29 20:09:31 -04:00
|
|
|
}
|
|
|
|
}
|