collection-crud/src/Controller/LensesController.php

136 lines
3.1 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;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2018-07-11 09:18:46 -04:00
use Symfony\Component\Routing\Annotation\Route;
2018-01-04 10:42:36 -05:00
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{Request, RedirectResponse};
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("lens")
*/
class LensesController extends AbstractController
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
use FormControllerTrait;
protected const ENTITY = Lenses::class;
protected const FORM = LensesType::class;
2017-11-30 15:06:13 -05:00
/**
2018-01-04 10:42:36 -05:00
* Lists all lens entities.
2017-11-30 15:06:13 -05:00
*
2018-07-11 09:18:46 -04:00
* @Route("/", name="lens_index", methods={"GET"})
2017-11-30 15:06:13 -05:00
*/
public function indexAction()
{
2018-07-18 11:35:27 -04:00
$em = $this->getDoctrine()->getManager();
$receivedItems = $em->getRepository(self::ENTITY)->findBy([
'received' => true
], [
2017-11-30 15:06:13 -05:00
'brand' => 'ASC',
'productLine' => 'ASC',
'mount' => 'ASC',
'minFocalLength' => 'ASC',
'maxFStop' => 'ASC',
]);
2018-07-18 11:35:27 -04:00
$newItems = $em->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,
]);
2017-11-30 15:06:13 -05:00
}
/**
2018-01-04 10:42:36 -05:00
* Creates a new lens entity.
2017-11-30 15:06:13 -05:00
*
2018-07-11 09:18:46 -04:00
* @Route("/new", name="lens_new", methods={"GET", "POST"})
2017-11-30 15:06:13 -05:00
*/
public function newAction(Request $request)
{
2018-07-16 13:50:07 -04:00
return $this->itemCreate($request, 'lenses/new.html.twig', 'lense', 'lens_show');
2017-11-30 15:06:13 -05:00
}
/**
2018-01-04 10:42:36 -05:00
* Finds and displays a lens entity.
2017-11-30 15:06:13 -05:00
*
2018-07-11 09:18:46 -04:00
* @Route("/{id}", name="lens_show", methods={"GET"})
2017-11-30 15:06:13 -05:00
*/
2018-07-16 13:50:07 -04:00
public function showAction(Lenses $lens)
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemView($lens, 'lenses/show.html.twig', 'lense');
2017-11-30 15:06:13 -05:00
}
/**
2018-01-04 10:42:36 -05:00
* Displays a form to edit an existing lens entity.
2017-11-30 15:06:13 -05:00
*
2018-07-11 09:18:46 -04:00
* @Route("/{id}/edit", name="lens_edit", methods={"GET", "POST"})
2017-11-30 15:06:13 -05:00
*/
2018-01-04 10:42:36 -05:00
public function editAction(Request $request, Lenses $lens)
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemUpdate($request, $lens, 'lenses/edit.html.twig', 'lense', 'lens_show');
2017-11-30 15:06:13 -05:00
}
/**
2018-01-04 10:42:36 -05:00
* Moves a camera to the previouslyOwned table
*
2018-07-11 09:18:46 -04:00
* @Route("/{id}/deacquire", name="lens_deacquire", methods={"POST"})
2018-01-04 10:42:36 -05:00
* @param Request $request
* @param Lenses $lens
* @return RedirectResponse
*/
public function deacquireAction(Request $request, Lenses $lens)
{
2018-07-16 13:50:07 -04:00
return $this->itemDeacquire($request, $lens, 'previously-owned-lens_index');
2018-01-04 10:42:36 -05:00
}
/**
* Deletes a lens entity.
2017-11-30 15:06:13 -05:00
*
2018-07-11 09:18:46 -04:00
* @Route("/{id}", name="lens_delete", methods={"DELETE"})
2017-11-30 15:06:13 -05:00
*/
2018-01-04 10:42:36 -05:00
public function deleteAction(Request $request, Lenses $lens)
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemDelete($request, $lens, 'lens_index');
2017-11-30 15:06:13 -05:00
}
/**
2018-01-04 10:42:36 -05:00
* Creates a form to delete a lens entity.
2017-11-30 15:06:13 -05:00
*
2018-01-04 10:42:36 -05:00
* @param Lenses $lens The lens entity
2017-11-30 15:06:13 -05:00
*
2018-01-04 10:42:36 -05:00
* @return FormInterface The form
2017-11-30 15:06:13 -05:00
*/
2018-01-04 10:42:36 -05:00
private function createDeleteForm(Lenses $lens): FormInterface
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->buildForm($lens, 'lens_delete', 'DELETE');
2017-11-30 15:06:13 -05:00
}
2018-01-04 10:42:36 -05:00
/**
* Creates a form to move
*
* @param Lenses $lens The lens entity
*
* @return FormInterface
*/
private function createDeacquireForm(Lenses $lens): FormInterface
{
2018-07-16 13:50:07 -04:00
return $this->buildForm($lens, 'lens_deacquire');
2018-01-04 10:42:36 -05:00
}
2017-11-30 15:06:13 -05:00
}