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;
|
2018-02-14 15:08:03 -05:00
|
|
|
use Doctrine\ORM\ORMInvalidArgumentException;
|
2018-11-30 16:01:30 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2020-06-02 16:08:08 -04:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
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")
|
|
|
|
*/
|
2018-11-30 16:01:30 -05:00
|
|
|
class CameraController extends AbstractController
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
use FormControllerTrait;
|
|
|
|
|
|
|
|
protected const ENTITY = Camera::class;
|
|
|
|
protected const FORM = CameraType::class;
|
|
|
|
|
2017-11-30 15:06:13 -05:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2020-06-02 16:08:08 -04:00
|
|
|
public function indexAction(): Response
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2018-07-18 11:35:27 -04:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
|
|
|
$receivedItems = $em->getRepository(self::ENTITY)->findBy([
|
|
|
|
'received' => true
|
|
|
|
], [
|
2018-07-23 09:52:00 -04:00
|
|
|
'isWorking' => 'ASC',
|
2017-11-30 15:06:13 -05:00
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
2018-07-18 11:35:27 -04:00
|
|
|
$newItems = $em->getRepository(self::ENTITY)->findBy([
|
|
|
|
'received' => false
|
|
|
|
], [
|
|
|
|
'brand' => 'ASC',
|
|
|
|
'mount' => 'ASC',
|
|
|
|
'model' => 'ASC',
|
|
|
|
]);
|
|
|
|
|
2018-07-23 09:52:00 -04:00
|
|
|
$working = array_filter($receivedItems, [$this, 'isWorking']);
|
|
|
|
$notWorking = array_filter($receivedItems, [$this, 'isNotWorking']);
|
|
|
|
|
2018-07-18 11:35:27 -04:00
|
|
|
return $this->render('camera/index.html.twig', [
|
|
|
|
'not_received' => $newItems,
|
2018-07-23 09:52:00 -04:00
|
|
|
'not_working' => $notWorking,
|
|
|
|
'working' => $working,
|
2018-07-18 11:35:27 -04:00
|
|
|
]);
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemCreate($request, 'camera/new.html.twig', 'camera', 'camera_show');
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemView($camera, 'camera/show.html.twig', 'camera');
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemUpdate($request, $camera, 'camera/edit.html.twig', 'camera', 'camera_show');
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2018-07-16 13:10:00 -04:00
|
|
|
public function deleteAction(Request $request, Camera $camera): RedirectResponse
|
2017-11-30 15:06:13 -05:00
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemDelete($request, $camera, 'camera_index');
|
2018-01-03 16:35:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 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
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemDeacquire($request, $camera, 'previously-owned-camera_index');
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to delete a camera entity.
|
|
|
|
*
|
|
|
|
* @param Camera $camera The camera entity
|
|
|
|
*
|
2020-06-02 16:08:08 -04:00
|
|
|
* @return 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
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->buildForm($camera, 'camera_delete', 'DELETE');
|
2017-11-30 15:06:13 -05:00
|
|
|
}
|
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
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->buildForm($camera, 'camera_deacquire');
|
2018-01-03 16:35:10 -05:00
|
|
|
}
|
2018-07-23 09:52:00 -04:00
|
|
|
|
|
|
|
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
|
|
|
}
|