2018-07-18 11:35:27 -04:00
|
|
|
<?php declare(strict_types=1);
|
2017-11-30 15:06:13 -05:00
|
|
|
|
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;
|
2022-09-29 18:35:53 -04:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2018-02-14 15:08:03 -05:00
|
|
|
use Doctrine\ORM\ORMInvalidArgumentException;
|
2022-03-03 10:53:48 -05:00
|
|
|
use LogicException;
|
2018-11-30 16:01:30 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2018-01-03 16:35:10 -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;
|
2017-11-30 15:06:13 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Camera controller.
|
|
|
|
*/
|
2022-02-17 15:16:47 -05:00
|
|
|
#[Route(path: 'camera')]
|
2018-11-30 16:01:30 -05:00
|
|
|
class CameraController extends AbstractController
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2022-03-03 10:53:48 -05:00
|
|
|
use FormControllerTrait;
|
|
|
|
|
|
|
|
protected const ENTITY = Camera::class;
|
2022-09-29 18:35:53 -04:00
|
|
|
protected const TEMPLATE_PATH = 'camera/';
|
|
|
|
protected const ROUTE_PREFIX = 'camera_';
|
2022-03-03 10:53:48 -05:00
|
|
|
protected const FORM = CameraType::class;
|
|
|
|
|
2022-09-29 18:35:53 -04:00
|
|
|
public function __construct(private readonly EntityManagerInterface $entityManager)
|
2022-03-03 10:53:48 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all camera entities.
|
|
|
|
*/
|
|
|
|
#[Route(path: '/', name: 'camera_index', methods: ['GET'])]
|
|
|
|
public function indexAction(): Response
|
|
|
|
{
|
2022-09-29 18:35:53 -04:00
|
|
|
$receivedItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
|
2022-03-03 11:15:12 -05:00
|
|
|
'received' => TRUE,
|
2022-03-03 10:53:48 -05:00
|
|
|
], [
|
|
|
|
'isWorking' => 'ASC',
|
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
2022-09-29 18:35:53 -04:00
|
|
|
$newItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
|
2022-03-03 11:15:12 -05:00
|
|
|
'received' => FALSE,
|
2022-03-03 10:53:48 -05:00
|
|
|
], [
|
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
|
|
|
$working = array_filter($receivedItems, [$this, 'isWorking']);
|
|
|
|
$notWorking = array_filter($receivedItems, [$this, 'isNotWorking']);
|
|
|
|
|
|
|
|
return $this->render('camera/index.html.twig', [
|
|
|
|
'not_received' => $newItems,
|
|
|
|
'not_working' => $notWorking,
|
|
|
|
'working' => $working,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new camera entity.
|
|
|
|
*/
|
|
|
|
#[Route(path: '/new', name: 'camera_new', methods: ['GET', 'POST'])]
|
|
|
|
public function newAction(Request $request): RedirectResponse|Response
|
|
|
|
{
|
|
|
|
return $this->itemCreate($request, 'camera/new.html.twig', 'camera', 'camera_show');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds and displays a camera entity.
|
|
|
|
*/
|
|
|
|
#[Route(path: '/{id}', name: 'camera_show', methods: ['GET'])]
|
|
|
|
public function showAction(Camera $camera): Response
|
|
|
|
{
|
|
|
|
return $this->itemView($camera, 'camera/show.html.twig', 'camera');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a form to edit an existing camera entity.
|
|
|
|
*
|
|
|
|
* @throws LogicException
|
|
|
|
*/
|
|
|
|
#[Route(path: '/{id}/edit', name: 'camera_edit', methods: ['GET', 'POST'])]
|
|
|
|
public function editAction(Request $request, Camera $camera): RedirectResponse|Response
|
|
|
|
{
|
|
|
|
return $this->itemUpdate($request, $camera, 'camera/edit.html.twig', 'camera', 'camera_show');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a camera entity.
|
|
|
|
*
|
|
|
|
* @throws LogicException
|
|
|
|
*/
|
|
|
|
#[Route(path: '/{id}', name: 'camera_delete', methods: ['DELETE'])]
|
|
|
|
public function deleteAction(Request $request, Camera $camera): RedirectResponse
|
|
|
|
{
|
|
|
|
return $this->itemDelete($request, $camera, 'camera_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a camera to the previouslyOwned table
|
|
|
|
*
|
|
|
|
* @throws LogicException
|
|
|
|
* @throws ORMInvalidArgumentException
|
|
|
|
*/
|
|
|
|
#[Route(path: '/{id}/deacquire', name: 'camera_deacquire', methods: ['POST'])]
|
|
|
|
public function deacquireAction(Request $request, Camera $camera): RedirectResponse
|
|
|
|
{
|
|
|
|
return $this->itemDeacquire($request, $camera, 'previously-owned-camera_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to delete a camera entity.
|
|
|
|
*
|
|
|
|
* @param Camera $camera The camera entity
|
|
|
|
*
|
|
|
|
* @return FormInterface The form
|
|
|
|
*/
|
|
|
|
private function createDeleteForm(Camera $camera): FormInterface
|
|
|
|
{
|
|
|
|
return $this->buildForm($camera, 'camera_delete', 'DELETE');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to move
|
|
|
|
*
|
|
|
|
* @param Camera $camera The camera entity
|
|
|
|
*/
|
|
|
|
private function createDeacquireForm(Camera $camera): FormInterface
|
|
|
|
{
|
|
|
|
return $this->buildForm($camera, 'camera_deacquire');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isWorking(Camera $camera): bool
|
|
|
|
{
|
|
|
|
return $camera->getIsWorking();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isNotWorking(Camera $camera): bool
|
|
|
|
{
|
|
|
|
return ! $this->isWorking($camera);
|
|
|
|
}
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|