2017-11-30 15:06:13 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CameraBundle\Controller;
|
|
|
|
|
|
|
|
use CameraBundle\Entity\Lenses;
|
2018-01-04 10:42:36 -05:00
|
|
|
use CameraBundle\Form\LensesType;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\{Method, Route};
|
2017-11-30 15:06:13 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
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 Controller
|
|
|
|
{
|
|
|
|
/**
|
2018-01-04 10:42:36 -05:00
|
|
|
* Lists all lens entities.
|
2017-11-30 15:06:13 -05:00
|
|
|
*
|
|
|
|
* @Route("/", name="lens_index")
|
|
|
|
* @Method("GET")
|
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
|
|
|
$lenses = $em->getRepository('CameraBundle:Lenses')->findBy([], [
|
|
|
|
'received' => 'DESC',
|
|
|
|
'brand' => 'ASC',
|
|
|
|
'productLine' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'minFocalLength' => 'ASC',
|
|
|
|
'maxFStop' => 'ASC',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->render('lenses/index.html.twig', array(
|
|
|
|
'lenses' => $lenses,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-04 10:42:36 -05:00
|
|
|
* Creates a new lens entity.
|
2017-11-30 15:06:13 -05:00
|
|
|
*
|
|
|
|
* @Route("/new", name="lens_new")
|
|
|
|
* @Method({"GET", "POST"})
|
|
|
|
*/
|
|
|
|
public function newAction(Request $request)
|
|
|
|
{
|
2018-01-04 10:42:36 -05:00
|
|
|
$lens = new Lenses();
|
|
|
|
$form = $this->createForm(LensesType::class, $lens);
|
2017-11-30 15:06:13 -05:00
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
2018-01-04 10:42:36 -05:00
|
|
|
$em->persist($lens);
|
2017-11-30 15:06:13 -05:00
|
|
|
$em->flush();
|
|
|
|
|
2018-01-04 10:42:36 -05:00
|
|
|
return $this->redirectToRoute('lens_show', array('id' => $lens->getId()));
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('lenses/new.html.twig', array(
|
2018-01-04 10:42:36 -05:00
|
|
|
'lense' => $lens,
|
2017-11-30 15:06:13 -05:00
|
|
|
'form' => $form->createView(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-04 10:42:36 -05:00
|
|
|
* Finds and displays a lens entity.
|
2017-11-30 15:06:13 -05:00
|
|
|
*
|
|
|
|
* @Route("/{id}", name="lens_show")
|
|
|
|
* @Method("GET")
|
|
|
|
*/
|
|
|
|
public function showAction(Lenses $lense)
|
|
|
|
{
|
|
|
|
$deleteForm = $this->createDeleteForm($lense);
|
|
|
|
|
|
|
|
return $this->render('lenses/show.html.twig', array(
|
|
|
|
'lense' => $lense,
|
|
|
|
'delete_form' => $deleteForm->createView(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*
|
|
|
|
* @Route("/{id}/edit", name="lens_edit")
|
|
|
|
* @Method({"GET", "POST"})
|
|
|
|
*/
|
2018-01-04 10:42:36 -05:00
|
|
|
public function editAction(Request $request, Lenses $lens)
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2018-01-04 10:42:36 -05:00
|
|
|
$deleteForm = $this->createDeleteForm($lens);
|
|
|
|
$deacquireForm = $this->createDeacquireForm($lens);
|
|
|
|
$editForm = $this->createForm(LensesType::class, $lens);
|
2017-11-30 15:06:13 -05:00
|
|
|
$editForm->handleRequest($request);
|
|
|
|
|
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
2018-01-04 10:42:36 -05:00
|
|
|
return $this->redirectToRoute('lens_edit', array('id' => $lens->getId()));
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('lenses/edit.html.twig', array(
|
2018-01-04 10:42:36 -05:00
|
|
|
'lense' => $lens,
|
2017-11-30 15:06:13 -05:00
|
|
|
'edit_form' => $editForm->createView(),
|
|
|
|
'delete_form' => $deleteForm->createView(),
|
2018-01-04 10:42:36 -05:00
|
|
|
'deacquire_form' => $deacquireForm->createView()
|
2017-11-30 15:06:13 -05:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-04 10:42:36 -05:00
|
|
|
* Moves a camera to the previouslyOwned table
|
|
|
|
*
|
|
|
|
* @Route("/{id}/deacquire", name="lens_deacquire")
|
|
|
|
* @Method("POST")
|
|
|
|
* @param Request $request
|
|
|
|
* @param Lenses $lens
|
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deacquireAction(Request $request, Lenses $lens)
|
|
|
|
{
|
|
|
|
$form = $this->createDeacquireForm($lens);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
$repository = $this->getDoctrine()->getRepository(Lenses::class);
|
|
|
|
$repository->deacquire($lens);
|
|
|
|
|
|
|
|
return $this->redirectToRoute('lens_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a lens entity.
|
2017-11-30 15:06:13 -05:00
|
|
|
*
|
|
|
|
* @Route("/{id}", name="lens_delete")
|
|
|
|
* @Method("DELETE")
|
|
|
|
*/
|
2018-01-04 10:42:36 -05:00
|
|
|
public function deleteAction(Request $request, Lenses $lens)
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2018-01-04 10:42:36 -05:00
|
|
|
$form = $this->createDeleteForm($lens);
|
2017-11-30 15:06:13 -05:00
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
2018-01-04 10:42:36 -05:00
|
|
|
$em->remove($lens);
|
2017-11-30 15:06:13 -05:00
|
|
|
$em->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirectToRoute('lens_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
{
|
|
|
|
return $this->createFormBuilder()
|
2018-01-04 10:42:36 -05:00
|
|
|
->setAction($this->generateUrl('lens_delete', array('id' => $lens->getId())))
|
2017-11-30 15:06:13 -05:00
|
|
|
->setMethod('DELETE')
|
|
|
|
->getForm();
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
return $this->createFormBuilder()
|
|
|
|
->setAction($this->generateUrl('lens_deacquire', ['id' => $lens->getId()]))
|
|
|
|
->setMethod('POST')
|
|
|
|
->getForm();
|
|
|
|
}
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|