123 lines
3.5 KiB
PHP
123 lines
3.5 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Lenses;
|
|
use App\Form\LensesType;
|
|
use App\Controller\
|
|
{DeleteFormTrait};
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
/**
|
|
* Lens controller.
|
|
*/
|
|
#[Route(path: 'lens')]
|
|
class LensesController extends AbstractController
|
|
{
|
|
use FormControllerBase;
|
|
use DeleteFormTrait;
|
|
|
|
protected const ENTITY = Lenses::class;
|
|
protected const TEMPLATE_PATH = 'lenses/';
|
|
protected const ROUTE_PREFIX = 'lens_';
|
|
protected const FORM = LensesType::class;
|
|
|
|
public function __construct(private readonly EntityManagerInterface $entityManager)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Lists all lens entities.
|
|
*/
|
|
#[Route(path: '/', name: 'lens_index', methods: ['GET'])]
|
|
public function indexAction(): Response
|
|
{
|
|
$receivedItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
|
|
'received' => TRUE,
|
|
], [
|
|
'brand' => 'ASC',
|
|
'productLine' => 'ASC',
|
|
'mount' => 'ASC',
|
|
'minFocalLength' => 'ASC',
|
|
'maxFStop' => 'ASC',
|
|
]);
|
|
$newItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
|
|
'received' => FALSE,
|
|
], [
|
|
'brand' => 'ASC',
|
|
'productLine' => 'ASC',
|
|
'mount' => 'ASC',
|
|
'minFocalLength' => 'ASC',
|
|
'maxFStop' => 'ASC',
|
|
]);
|
|
|
|
return $this->render('lenses/index.html.twig', [
|
|
'not_received' => $newItems,
|
|
'lenses' => $receivedItems,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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, 'lense');
|
|
}
|
|
|
|
/**
|
|
* Finds and displays a lens entity.
|
|
*/
|
|
#[Route(path: '/{id}', name: 'lens_show', methods: ['GET'])]
|
|
public function showAction(Lenses $lens): Response
|
|
{
|
|
return $this->itemView($lens, 'lense');
|
|
}
|
|
|
|
/**
|
|
* 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, 'lense');
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
}
|
|
|
|
/**
|
|
* Deletes a lens entity.
|
|
*/
|
|
#[Route(path: '/{id}', name: 'lens_delete', methods: ['POST', 'DELETE'])]
|
|
public function deleteAction(Request $request, Lenses $lens): RedirectResponse
|
|
{
|
|
return $this->itemDelete($request, $lens);
|
|
}
|
|
|
|
/**
|
|
* Creates a form to move
|
|
*
|
|
* @param Lenses $lens The lens entity
|
|
*/
|
|
private function createDeacquireForm(Lenses $lens): FormInterface
|
|
{
|
|
return $this->buildForm($lens, 'lens_deacquire');
|
|
}
|
|
}
|