collection-crud/src/Controller/LensesController.php

123 lines
3.5 KiB
PHP
Raw Normal View History

2018-07-18 11:35:27 -04:00
<?php declare(strict_types=1);
2017-11-30 15:06:13 -05:00
namespace App\Controller;
2017-11-30 15:06:13 -05:00
use App\Entity\Lenses;
use App\Form\LensesType;
2023-07-21 10:23:16 -04:00
use App\Controller\
{DeleteFormTrait};
2022-09-29 18:35:53 -04:00
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2018-01-04 10:42:36 -05:00
use Symfony\Component\Form\FormInterface;
2022-03-03 11:15:12 -05:00
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
2022-03-03 10:53:48 -05:00
use Symfony\Component\Routing\Annotation\Route;
2017-11-30 15:06:13 -05:00
/**
2018-01-04 10:42:36 -05:00
* Lens controller.
2017-11-30 15:06:13 -05:00
*/
#[Route(path: 'lens')]
class LensesController extends AbstractController
2017-11-30 15:06:13 -05:00
{
2023-07-21 10:23:16 -04:00
use FormControllerBase;
2022-09-30 10:49:02 -04:00
use DeleteFormTrait;
2022-03-03 10:53:48 -05:00
2022-09-30 10:49:02 -04:00
protected const ENTITY = Lenses::class;
protected const TEMPLATE_PATH = 'lenses/';
protected const ROUTE_PREFIX = 'lens_';
protected const FORM = LensesType::class;
2022-02-18 11:34:25 -05:00
2022-09-29 18:35:53 -04:00
public function __construct(private readonly EntityManagerInterface $entityManager)
2022-03-03 10:53:48 -05:00
{
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Lists all lens entities.
*/
#[Route(path: '/', name: 'lens_index', methods: ['GET'])]
public function indexAction(): Response
{
2022-09-29 18:35:53 -04:00
$receivedItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
2022-03-03 11:15:12 -05:00
'received' => TRUE,
2022-03-03 10:53:48 -05:00
], [
'brand' => 'ASC',
'productLine' => 'ASC',
'mount' => 'ASC',
'minFocalLength' => 'ASC',
'maxFStop' => 'ASC',
]);
2022-09-29 18:35:53 -04:00
$newItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
2022-03-03 11:15:12 -05:00
'received' => FALSE,
2022-03-03 10:53:48 -05:00
], [
'brand' => 'ASC',
'productLine' => 'ASC',
'mount' => 'ASC',
'minFocalLength' => 'ASC',
'maxFStop' => 'ASC',
]);
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
return $this->render('lenses/index.html.twig', [
'not_received' => $newItems,
'lenses' => $receivedItems,
]);
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Creates a new lens entity.
*/
#[Route(path: '/new', name: 'lens_new', methods: ['GET', 'POST'])]
public function newAction(Request $request): RedirectResponse|Response
{
2022-09-30 10:49:02 -04:00
return $this->itemCreate($request, 'lense');
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Finds and displays a lens entity.
*/
#[Route(path: '/{id}', name: 'lens_show', methods: ['GET'])]
public function showAction(Lenses $lens): Response
{
2022-09-30 10:48:14 -04:00
return $this->itemView($lens, 'lense');
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Displays a form to edit an existing lens entity.
*/
#[Route(path: '/{id}/edit', name: 'lens_edit', methods: ['GET', 'POST'])]
public function editAction(Request $request, Lenses $lens): RedirectResponse|Response
{
2022-09-30 10:48:14 -04:00
return $this->itemUpdate($request, $lens, 'lense');
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Moves a camera to the previouslyOwned table
*
* @param Request $request
*
* @return RedirectResponse
*/
#[Route(path: '/{id}/deacquire', name: 'lens_deacquire', methods: ['POST'])]
public function deacquireAction(Request $request, Lenses $lens): RedirectResponse
{
return $this->itemDeacquire($request, $lens, 'previously-owned-lens_index');
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Deletes a lens entity.
*/
2022-09-30 10:49:02 -04:00
#[Route(path: '/{id}', name: 'lens_delete', methods: ['POST', 'DELETE'])]
2022-03-03 10:53:48 -05:00
public function deleteAction(Request $request, Lenses $lens): RedirectResponse
{
2022-09-30 10:48:14 -04:00
return $this->itemDelete($request, $lens);
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Creates a form to move
*
* @param Lenses $lens The lens entity
*/
private function createDeacquireForm(Lenses $lens): FormInterface
{
return $this->buildForm($lens, 'lens_deacquire');
}
2017-11-30 15:06:13 -05:00
}