src/Controller/V1/CinemaWebController.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\V1;
  4. use FOS\RestBundle\Controller\Annotations as Rest;
  5. use FOS\RestBundle\Controller\Annotations\View;
  6. use Nelmio\ApiDocBundle\Annotation\Model;
  7. use Swagger\Annotations as SWG;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/cinemasweb")
  12.  * @SWG\Tag(name="CinemaWeb_v1")
  13.  */
  14. class CinemaWebController extends BaseCinemaController
  15. {
  16.     /**
  17.      * @Route("/{id}/movies", methods={"GET"})
  18.      * @Rest\QueryParam(name="date", allowBlank=true)
  19.      * @View(serializerGroups={"Default", "movie_details"})
  20.      *
  21.      * @SWG\Response(
  22.      *     response="200",
  23.      *     description="Get upcoming web movies list by cinema id",
  24.      *     @SWG\Schema(type="array", items=@SWG\Items(ref=@Model(type=\App\Entity\Vista\ScheduledFilm::class))))
  25.      * @SWG\Response(
  26.      *     response="404",
  27.      *     description="Cinema not found")
  28.      *
  29.      * @param $id
  30.      * @param \DateTime|null $date
  31.      * @return array
  32.      * @throws \Exception
  33.      */
  34.     public function moviesAction($id, ?\DateTime $date null)
  35.     {
  36.         $cinema $this->getCinema($id);
  37.         $defaultDate $this->sessionHelper->getDefaultDate([$cinema->getId()]);
  38.         if (!$date || ($date $defaultDate)) {
  39.             $date $defaultDate;
  40.         }
  41.         $response $this->prepareMoviesResponse(
  42.             $this->movieRepository->findByCinemaIdAndDate($cinema->getId(), $date)
  43.         );
  44.         return $this->filterSessionByType($response'WWW');
  45.     }
  46.     /**
  47.      * @Route("/with-movies", methods={"GET"})
  48.      * @Rest\QueryParam(name="locationId", allowBlank=true, nullable=true)
  49.      * @Rest\QueryParam(name="date", allowBlank=true)
  50.      * @Rest\QueryParam(name="order", allowBlank=true)
  51.      * @View(serializerGroups={"Default", "cinema_list"})
  52.      *
  53.      * @SWG\Response(
  54.      *     response="200",
  55.      *     description="Returns a list of cinemas",
  56.      *     @SWG\Schema(type="array", items=@SWG\Items(ref=@Model(type=\App\Entity\Local\Response\CinemasWithMoviesItem::class))))
  57.      *
  58.      * @param int|null       $locationId
  59.      * @param \DateTime|null $date
  60.      * @return array
  61.      * @throws \Exception
  62.      */
  63.     public function cinemasWithMoviesAction($locationId null, ?\DateTime $date null)
  64.     {
  65.         if (!is_numeric($locationId)) {
  66.             $locationId null;
  67.         } else {
  68.             $locationId = (int) $locationId;
  69.         }
  70.         $filter = [];
  71.         if (null !== $locationId) {
  72.             $filter['id'] = $this->locationRepository->findById($locationId)->getItems();
  73.         } else {
  74.             $filter['id'] = $this->locationRepository->findLocationIds();
  75.         }
  76.         $defaultDate $this->sessionHelper->getDefaultDate(null$locationId);
  77.         if (!$date) {
  78.             $date $defaultDate;
  79.         } elseif ($date $defaultDate) {
  80.             $date $defaultDate;
  81.         }
  82.         return $this->prepareResponse($this->getCinemasWithMovies('WWW'$filter$date));
  83.     }
  84. }