collection-crud/src/Controller/FilmController.php

114 lines
2.6 KiB
PHP
Raw Normal View History

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;
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")
*/
class FilmController extends AbstractController
2018-02-15 09:48:57 -05: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)
{
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)
{
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)
{
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)
{
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
{
return $this->buildForm($film, 'film_delete', 'DELETE');
2018-02-15 09:48:57 -05:00
}
}