2017-11-30 15:06:13 -05:00
|
|
|
<?php
|
|
|
|
|
2018-02-14 16:42:39 -05:00
|
|
|
namespace App\Controller;
|
2017-11-30 15:06:13 -05:00
|
|
|
|
2018-02-14 16:42:39 -05:00
|
|
|
use App\Entity\Camera;
|
|
|
|
use App\Form\CameraType;
|
2018-02-14 15:08:03 -05:00
|
|
|
use Doctrine\ORM\OptimisticLockException;
|
|
|
|
use Doctrine\ORM\ORMInvalidArgumentException;
|
2017-11-30 15:06:13 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2018-07-11 09:18:46 -04:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2018-01-03 16:35:10 -05:00
|
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2017-11-30 15:06:13 -05:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Camera controller.
|
|
|
|
*
|
|
|
|
* @Route("camera")
|
|
|
|
*/
|
|
|
|
class CameraController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Lists all camera entities.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/", name="camera_index", methods={"GET"})
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
2018-02-14 16:42:39 -05:00
|
|
|
$cameras = $em->getRepository('App:Camera')->findBy([], [
|
2017-11-30 15:06:13 -05:00
|
|
|
'received' => 'DESC',
|
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->render('camera/index.html.twig', array(
|
|
|
|
'cameras' => $cameras,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new camera entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/new", name="camera_new", methods={"GET", "POST"})
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function newAction(Request $request)
|
|
|
|
{
|
|
|
|
$camera = new Camera();
|
2018-01-03 16:35:10 -05:00
|
|
|
$form = $this->createForm(CameraType::class, $camera);
|
2017-11-30 15:06:13 -05:00
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($camera);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('camera_show', array('id' => $camera->getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('camera/new.html.twig', array(
|
|
|
|
'camera' => $camera,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds and displays a camera entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}", name="camera_show", methods={"GET"})
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function showAction(Camera $camera)
|
|
|
|
{
|
|
|
|
$deleteForm = $this->createDeleteForm($camera);
|
|
|
|
|
|
|
|
return $this->render('camera/show.html.twig', array(
|
|
|
|
'camera' => $camera,
|
|
|
|
'delete_form' => $deleteForm->createView(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a form to edit an existing camera entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}/edit", name="camera_edit", methods={"GET", "POST"})
|
2018-01-03 16:35:10 -05:00
|
|
|
* @throws \LogicException
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function editAction(Request $request, Camera $camera)
|
|
|
|
{
|
|
|
|
$deleteForm = $this->createDeleteForm($camera);
|
2018-01-03 16:35:10 -05:00
|
|
|
$deacquireForm = $this->createDeacquireForm($camera);
|
|
|
|
|
|
|
|
$editForm = $this->createForm(CameraType::class, $camera);
|
2017-11-30 15:06:13 -05:00
|
|
|
$editForm->handleRequest($request);
|
|
|
|
|
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('camera_edit', array('id' => $camera->getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('camera/edit.html.twig', array(
|
|
|
|
'camera' => $camera,
|
|
|
|
'edit_form' => $editForm->createView(),
|
2018-01-03 16:35:10 -05:00
|
|
|
'deacquire_form' => $deacquireForm->createView(),
|
2017-11-30 15:06:13 -05:00
|
|
|
'delete_form' => $deleteForm->createView(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a camera entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}", name="camera_delete", methods={"DELETE"})
|
2018-01-03 16:35:10 -05:00
|
|
|
* @throws \LogicException
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function deleteAction(Request $request, Camera $camera)
|
|
|
|
{
|
|
|
|
$form = $this->createDeleteForm($camera);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2018-01-03 16:35:10 -05:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->remove($camera);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('camera_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a camera to the previouslyOwned table
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}/deacquire", name="camera_deacquire", methods={"POST"})
|
2018-01-03 16:35:10 -05:00
|
|
|
* @param Request $request
|
|
|
|
* @param Camera $camera
|
2018-02-14 15:08:03 -05:00
|
|
|
* @throws \LogicException
|
|
|
|
* @throws OptimisticLockException
|
|
|
|
* @throws ORMInvalidArgumentException
|
2018-01-03 16:35:10 -05:00
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
2018-02-14 15:08:03 -05:00
|
|
|
public function deacquireAction(Request $request, Camera $camera): RedirectResponse
|
2018-01-03 16:35:10 -05:00
|
|
|
{
|
|
|
|
$form = $this->createDeacquireForm($camera);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
$repository = $this->getDoctrine()->getRepository(Camera::class);
|
|
|
|
$repository->deacquire($camera);
|
2017-11-30 15:06:13 -05:00
|
|
|
|
|
|
|
return $this->redirectToRoute('camera_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to delete a camera entity.
|
|
|
|
*
|
|
|
|
* @param Camera $camera The camera entity
|
|
|
|
*
|
2018-01-03 16:35:10 -05:00
|
|
|
* @return \Symfony\Component\Form\FormInterface The form
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
2018-01-03 16:35:10 -05:00
|
|
|
private function createDeleteForm(Camera $camera): FormInterface
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
|
|
|
return $this->createFormBuilder()
|
2018-01-03 16:35:10 -05:00
|
|
|
->setAction($this->generateUrl('camera_delete', ['id' => $camera->getId()]))
|
2017-11-30 15:06:13 -05:00
|
|
|
->setMethod('DELETE')
|
|
|
|
->getForm();
|
|
|
|
}
|
2018-01-03 16:35:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to move
|
|
|
|
*
|
|
|
|
* @param Camera $camera The camera entity
|
|
|
|
*
|
|
|
|
* @return FormInterface
|
|
|
|
*/
|
|
|
|
private function createDeacquireForm(Camera $camera): FormInterface
|
|
|
|
{
|
|
|
|
return $this->createFormBuilder()
|
|
|
|
->setAction($this->generateUrl('camera_deacquire', ['id' => $camera->getId()]))
|
|
|
|
->setMethod('POST')
|
|
|
|
->getForm();
|
|
|
|
}
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|