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\PreviouslyOwnedCamera;
|
|
|
|
use App\Form\PreviouslyOwnedCameraType;
|
2018-02-14 15:08:03 -05:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\{Method, Route};
|
2017-11-30 15:06:13 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2018-02-14 15:08:03 -05:00
|
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\{RedirectResponse, Request};
|
2017-11-30 15:06:13 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Previouslyownedcamera controller.
|
|
|
|
*
|
|
|
|
* @Route("previously-owned-camera")
|
|
|
|
*/
|
|
|
|
class PreviouslyOwnedCameraController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Lists all previouslyOwnedCamera entities.
|
|
|
|
*
|
|
|
|
* @Route("/", name="previously-owned-camera_index")
|
|
|
|
* @Method("GET")
|
2018-01-04 10:42:36 -05:00
|
|
|
* @throws \UnexpectedValueException
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
2018-02-14 16:42:39 -05:00
|
|
|
$previouslyOwnedCameras = $em->getRepository('App:PreviouslyOwnedCamera')->findBy([], [
|
2017-11-30 15:06:13 -05:00
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->render('previouslyownedcamera/index.html.twig', array(
|
|
|
|
'previouslyOwnedCameras' => $previouslyOwnedCameras,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds and displays a previouslyOwnedCamera entity.
|
|
|
|
*
|
|
|
|
* @Route("/{id}", name="previously-owned-camera_show")
|
|
|
|
* @Method("GET")
|
|
|
|
*/
|
|
|
|
public function showAction(PreviouslyOwnedCamera $previouslyOwnedCamera)
|
|
|
|
{
|
|
|
|
return $this->render('previouslyownedcamera/show.html.twig', array(
|
|
|
|
'previouslyOwnedCamera' => $previouslyOwnedCamera,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a form to edit an existing previouslyOwnedCamera entity.
|
|
|
|
*
|
|
|
|
* @Route("/{id}/edit", name="previously-owned-camera_edit")
|
|
|
|
* @Method({"GET", "POST"})
|
2018-01-04 10:42:36 -05:00
|
|
|
* @throws \LogicException
|
2017-11-30 15:06:13 -05:00
|
|
|
*/
|
|
|
|
public function editAction(Request $request, PreviouslyOwnedCamera $previouslyOwnedCamera)
|
|
|
|
{
|
2018-01-04 10:42:36 -05:00
|
|
|
$editForm = $this->createForm(PreviouslyOwnedCameraType::class, $previouslyOwnedCamera);
|
2017-11-30 15:06:13 -05:00
|
|
|
$editForm->handleRequest($request);
|
|
|
|
|
2018-02-14 15:08:03 -05:00
|
|
|
$reacquireForm = $this->createReacquireForm($previouslyOwnedCamera);
|
|
|
|
|
2017-11-30 15:06:13 -05:00
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('previously-owned-camera_edit', array('id' => $previouslyOwnedCamera->getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('previouslyownedcamera/edit.html.twig', array(
|
|
|
|
'previouslyOwnedCamera' => $previouslyOwnedCamera,
|
|
|
|
'edit_form' => $editForm->createView(),
|
2018-02-14 15:08:03 -05:00
|
|
|
'reacquire_form' => $reacquireForm->createView()
|
2017-11-30 15:06:13 -05:00
|
|
|
));
|
|
|
|
}
|
2018-02-14 15:08:03 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a camera to the previouslyOwned table
|
|
|
|
*
|
|
|
|
* @Route("/{id}/reacquire", name="previously-owned-camera_reacquire")
|
|
|
|
* @Method("POST")
|
|
|
|
* @param Request $request
|
|
|
|
* @param PreviouslyOwnedCamera $camera
|
|
|
|
* @throws \LogicException
|
|
|
|
* @throws \Doctrine\ORM\ORMInvalidArgumentException
|
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
|
|
|
public function reacquireAction(Request $request, PreviouslyOwnedCamera $camera): RedirectResponse
|
|
|
|
{
|
|
|
|
$form = $this->createReacquireForm($camera);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
$repository = $this->getDoctrine()->getRepository(PreviouslyOwnedCamera::class);
|
|
|
|
$repository->reacquire($camera);
|
|
|
|
|
|
|
|
return $this->redirectToRoute('previously-owned-camera_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to move
|
|
|
|
*
|
|
|
|
* @param PreviouslyOwnedCamera $camera The camera entity
|
|
|
|
*
|
|
|
|
* @return FormInterface
|
|
|
|
*/
|
|
|
|
private function createReacquireForm(PreviouslyOwnedCamera $camera): FormInterface
|
|
|
|
{
|
|
|
|
return $this->createFormBuilder()
|
|
|
|
->setAction($this->generateUrl('previously-owned-camera_reacquire', ['id' => $camera->getId()]))
|
|
|
|
->setMethod('POST')
|
|
|
|
->getForm();
|
|
|
|
}
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|