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

95 lines
3.0 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\PreviouslyOwnedCamera;
use App\Form\PreviouslyOwnedCameraType;
2022-09-30 10:48:14 -04:00
use App\Traits\FormControllerTrait;
2022-09-29 18:35:53 -04:00
use Doctrine\ORM\EntityManagerInterface;
2022-03-03 10:53:48 -05:00
use Doctrine\ORM\ORMInvalidArgumentException;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2018-02-14 15:08:03 -05:00
use Symfony\Component\Form\FormInterface;
2022-03-03 11:15:12 -05:00
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
2022-03-03 10:53:48 -05:00
use Symfony\Component\Routing\Annotation\Route;
use UnexpectedValueException;
2017-11-30 15:06:13 -05:00
/**
* Previouslyownedcamera controller.
*/
#[Route(path: 'previously-owned-camera')]
class PreviouslyOwnedCameraController extends AbstractController
2017-11-30 15:06:13 -05:00
{
2022-03-03 10:53:48 -05:00
use FormControllerTrait;
protected const ENTITY = PreviouslyOwnedCamera::class;
2022-09-29 18:35:53 -04:00
protected const TEMPLATE_PATH = 'previouslyownedcamera/';
protected const ROUTE_PREFIX = 'previously-owned-camera_';
2022-03-03 10:53:48 -05:00
protected const FORM = PreviouslyOwnedCameraType::class;
2022-02-18 11:34:25 -05:00
2022-09-29 18:35:53 -04:00
public function __construct(private readonly EntityManagerInterface $entityManager)
2022-03-03 10:53:48 -05:00
{
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Lists all previouslyOwnedCamera entities.
*
* @throws UnexpectedValueException
*/
#[Route(path: '/', name: 'previously-owned-camera_index', methods: ['GET'])]
2022-09-30 10:48:14 -04:00
public function indexAction(): Response
2022-03-03 10:53:48 -05:00
{
2022-09-30 10:48:14 -04:00
return $this->itemListView( 'previouslyOwnedCameras', [
2022-03-03 10:53:48 -05:00
'brand' => 'ASC',
'mount' => 'ASC',
'model' => 'ASC',
2022-09-30 10:48:14 -04:00
]);
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Finds and displays a previouslyOwnedCamera entity.
*/
#[Route(path: '/{id}', name: 'previously-owned-camera_show', methods: ['GET'])]
public function showAction(PreviouslyOwnedCamera $previouslyOwnedCamera): Response
{
2022-09-30 10:48:14 -04:00
return $this->itemView($previouslyOwnedCamera, 'previouslyOwnedCamera');
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Displays a form to edit an existing previouslyOwnedCamera entity.
*
* @throws LogicException
*/
#[Route(path: '/{id}/edit', name: 'previously-owned-camera_edit', methods: ['GET', 'POST'])]
public function editAction(Request $request, PreviouslyOwnedCamera $previouslyOwnedCamera): RedirectResponse|Response
{
2022-09-30 10:48:14 -04:00
return $this->itemUpdate($request, $previouslyOwnedCamera, 'previouslyOwnedCamera');
2022-03-03 10:53:48 -05:00
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Moves a camera to the previouslyOwned table
*
* @param Request $request
*
* @throws LogicException
* @throws ORMInvalidArgumentException
*
* @return RedirectResponse
*/
#[Route(path: '/{id}/reacquire', name: 'previously-owned-camera_reacquire', methods: ['POST'])]
public function reacquireAction(Request $request, PreviouslyOwnedCamera $camera): RedirectResponse
{
return $this->itemReacquire($request, $camera, 'camera_index');
}
2022-02-18 11:34:25 -05:00
2022-03-03 10:53:48 -05:00
/**
* Creates a form to move
*
* @param PreviouslyOwnedCamera $camera The camera entity
*/
private function createReacquireForm(PreviouslyOwnedCamera $camera): FormInterface
{
return $this->buildForm($camera, 'previously-owned-camera_reacquire', 'POST');
}
2017-11-30 15:06:13 -05:00
}