2018-07-18 11:35:27 -04:00
|
|
|
<?php declare(strict_types=1);
|
2018-02-15 09:48:57 -05:00
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Entity\Film;
|
|
|
|
use App\Form\FilmType;
|
2018-07-18 11:35:27 -04:00
|
|
|
use Doctrine\Common\Collections\Criteria;
|
2018-11-30 16:01:30 -05:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2018-07-11 09:18:46 -04:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2018-02-15 09:48:57 -05:00
|
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Film controller.
|
|
|
|
*
|
|
|
|
* @Route("film")
|
|
|
|
*/
|
2018-11-30 16:01:30 -05:00
|
|
|
class FilmController extends AbstractController
|
2018-02-15 09:48:57 -05:00
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
use FormControllerTrait;
|
|
|
|
|
|
|
|
protected const ENTITY = Film::class;
|
|
|
|
protected const FORM = FilmType::class;
|
|
|
|
|
2018-02-15 09:48:57 -05:00
|
|
|
/**
|
|
|
|
* Lists all film entities.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/", name="film_index", methods={"GET"})
|
2018-02-15 09:48:57 -05:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2018-07-18 11:35:27 -04:00
|
|
|
|
|
|
|
$repo = $this->getDoctrine()->getManager()->getRepository(self::ENTITY);
|
|
|
|
|
|
|
|
$criteria = Criteria::create()
|
|
|
|
->where(Criteria::expr()->gt('rollsInCamera', 0))
|
|
|
|
->orderBy([
|
|
|
|
'filmFormat' => Criteria::ASC,
|
|
|
|
'brand' => Criteria::ASC,
|
|
|
|
'rollsInCamera' => Criteria::DESC,
|
|
|
|
'productLine' => Criteria::ASC,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$inCamera = $repo->matching($criteria);
|
|
|
|
|
|
|
|
$notInCamera = $repo->findBy([
|
|
|
|
'rollsInCamera' => 0,
|
|
|
|
], [
|
2018-02-15 09:48:57 -05:00
|
|
|
'brand' => 'ASC',
|
|
|
|
'productLine' => 'ASC',
|
|
|
|
'filmFormat' => 'ASC',
|
|
|
|
]);
|
2018-07-18 11:35:27 -04:00
|
|
|
|
|
|
|
return $this->render('film/index.html.twig', [
|
|
|
|
'in_camera' => $inCamera,
|
|
|
|
'films' => $notInCamera,
|
|
|
|
]);
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new film entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/new", name="film_new", methods={"GET", "POST"})
|
2018-02-15 09:48:57 -05:00
|
|
|
*/
|
|
|
|
public function newAction(Request $request)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemCreate($request, 'film/new.html.twig', 'film', 'film_show');
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds and displays a film entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}", name="film_show", methods={"GET"})
|
2018-02-15 09:48:57 -05:00
|
|
|
*/
|
|
|
|
public function showAction(Film $film)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemView($film, 'film/show.html.twig', 'film');
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a form to edit an existing film entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}/edit", name="film_edit", methods={"GET", "POST"})
|
2018-02-15 09:48:57 -05:00
|
|
|
* @throws \LogicException
|
|
|
|
*/
|
|
|
|
public function editAction(Request $request, Film $film)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemUpdate($request, $film, 'film/edit.html.twig', 'film', 'film_show');
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a film entity.
|
|
|
|
*
|
2018-07-11 09:18:46 -04:00
|
|
|
* @Route("/{id}", name="film_delete", methods={"DELETE"})
|
2018-02-15 09:48:57 -05:00
|
|
|
* @throws \LogicException
|
|
|
|
*/
|
|
|
|
public function deleteAction(Request $request, Film $film)
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->itemDelete($request, $film, 'film_index');
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to delete a film entity.
|
|
|
|
*
|
|
|
|
* @param Film $film The film entity
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\Form\FormInterface The form
|
|
|
|
*/
|
|
|
|
private function createDeleteForm(Film $film): FormInterface
|
|
|
|
{
|
2018-07-16 13:10:00 -04:00
|
|
|
return $this->buildForm($film, 'film_delete', 'DELETE');
|
2018-02-15 09:48:57 -05:00
|
|
|
}
|
|
|
|
}
|