collection-crud/src/Controller/PreviouslyOwnedCameraContro...

88 lines
2.6 KiB
PHP

<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\PreviouslyOwnedCamera;
use App\Form\PreviouslyOwnedCameraType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request};
/**
* Previouslyownedcamera controller.
*
* @Route("previously-owned-camera")
*/
class PreviouslyOwnedCameraController extends AbstractController
{
use FormControllerTrait;
protected const ENTITY = PreviouslyOwnedCamera::class;
protected const FORM = PreviouslyOwnedCameraType::class;
/**
* Lists all previouslyOwnedCamera entities.
*
* @Route("/", name="previously-owned-camera_index", methods={"GET"})
* @throws \UnexpectedValueException
*/
public function indexAction()
{
return $this->itemListView('previouslyownedcamera/index.html.twig', 'previouslyOwnedCameras', [
'brand' => 'ASC',
'mount' => 'ASC',
'model' => 'ASC',
]);
}
/**
* Finds and displays a previouslyOwnedCamera entity.
*
* @Route("/{id}", name="previously-owned-camera_show", methods={"GET"})
*/
public function showAction(PreviouslyOwnedCamera $previouslyOwnedCamera)
{
return $this->itemView($previouslyOwnedCamera, 'previouslyownedcamera/show.html.twig', 'previouslyOwnedCamera');
}
/**
* Displays a form to edit an existing previouslyOwnedCamera entity.
*
* @Route("/{id}/edit", name="previously-owned-camera_edit", methods={"GET", "POST"})
* @throws \LogicException
*/
public function editAction(Request $request, PreviouslyOwnedCamera $previouslyOwnedCamera)
{
return $this->itemUpdate($request, $previouslyOwnedCamera, 'previouslyownedcamera/edit.html.twig', 'previouslyOwnedCamera', 'previously-owned-camera_show');
}
/**
* Moves a camera to the previouslyOwned table
*
* @Route("/{id}/reacquire", name="previously-owned-camera_reacquire", methods={"POST"})
* @param Request $request
* @param PreviouslyOwnedCamera $camera
* @throws \LogicException
* @throws \Doctrine\ORM\ORMInvalidArgumentException
* @return RedirectResponse
*/
public function reacquireAction(Request $request, PreviouslyOwnedCamera $camera): RedirectResponse
{
return $this->itemReacquire($request, $camera, 'camera_index');
}
/**
* Creates a form to move
*
* @param PreviouslyOwnedCamera $camera The camera entity
*
* @return FormInterface
*/
private function createReacquireForm(PreviouslyOwnedCamera $camera): FormInterface
{
return $this->buildForm($camera, 'previously-owned-camera_reacquire', 'POST');
}
}