collection-crud/src/Controller/LensesController.php

131 lines
3.8 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;
2022-03-03 10:53:48 -05:00
use Doctrine\Persistence\ManagerRegistry;
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
{
2022-03-03 10:53:48 -05:00
use FormControllerTrait;
protected const ENTITY = Lenses::class;
protected const FORM = LensesType::class;
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
public function __construct(private readonly ManagerRegistry $managerRegistry)
{
}
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
{
$em = $this->managerRegistry->getManager();
$receivedItems = $em->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',
]);
$newItems = $em->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
{
return $this->itemCreate($request, 'lenses/new.html.twig', 'lense', 'lens_show');
}
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
{
return $this->itemView($lens, 'lenses/show.html.twig', 'lense');
}
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
{
return $this->itemUpdate($request, $lens, 'lenses/edit.html.twig', 'lense', 'lens_show');
}
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.
*/
#[Route(path: '/{id}', name: 'lens_delete', methods: ['DELETE'])]
public function deleteAction(Request $request, Lenses $lens): RedirectResponse
{
return $this->itemDelete($request, $lens, 'lens_index');
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Creates a form to delete a lens entity.
*
* @param Lenses $lens The lens entity
*
* @return FormInterface The form
*/
private function createDeleteForm(Lenses $lens): FormInterface
{
return $this->buildForm($lens, 'lens_delete', 'DELETE');
}
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
}