<?php
declare(strict_types=1);
namespace App\Controller\V1;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\Model;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/cinemasweb")
* @SWG\Tag(name="CinemaWeb_v1")
*/
class CinemaWebController extends BaseCinemaController
{
/**
* @Route("/{id}/movies", methods={"GET"})
* @Rest\QueryParam(name="date", allowBlank=true)
* @View(serializerGroups={"Default", "movie_details"})
*
* @SWG\Response(
* response="200",
* description="Get upcoming web movies list by cinema id",
* @SWG\Schema(type="array", items=@SWG\Items(ref=@Model(type=\App\Entity\Vista\ScheduledFilm::class))))
* @SWG\Response(
* response="404",
* description="Cinema not found")
*
* @param $id
* @param \DateTime|null $date
* @return array
* @throws \Exception
*/
public function moviesAction($id, ?\DateTime $date = null)
{
$cinema = $this->getCinema($id);
$defaultDate = $this->sessionHelper->getDefaultDate([$cinema->getId()]);
if (!$date || ($date < $defaultDate)) {
$date = $defaultDate;
}
$response = $this->prepareMoviesResponse(
$this->movieRepository->findByCinemaIdAndDate($cinema->getId(), $date)
);
return $this->filterSessionByType($response, 'WWW');
}
/**
* @Route("/with-movies", methods={"GET"})
* @Rest\QueryParam(name="locationId", allowBlank=true, nullable=true)
* @Rest\QueryParam(name="date", allowBlank=true)
* @Rest\QueryParam(name="order", allowBlank=true)
* @View(serializerGroups={"Default", "cinema_list"})
*
* @SWG\Response(
* response="200",
* description="Returns a list of cinemas",
* @SWG\Schema(type="array", items=@SWG\Items(ref=@Model(type=\App\Entity\Local\Response\CinemasWithMoviesItem::class))))
*
* @param int|null $locationId
* @param \DateTime|null $date
* @return array
* @throws \Exception
*/
public function cinemasWithMoviesAction($locationId = null, ?\DateTime $date = null)
{
if (!is_numeric($locationId)) {
$locationId = null;
} else {
$locationId = (int) $locationId;
}
$filter = [];
if (null !== $locationId) {
$filter['id'] = $this->locationRepository->findById($locationId)->getItems();
} else {
$filter['id'] = $this->locationRepository->findLocationIds();
}
$defaultDate = $this->sessionHelper->getDefaultDate(null, $locationId);
if (!$date) {
$date = $defaultDate;
} elseif ($date < $defaultDate) {
$date = $defaultDate;
}
return $this->prepareResponse($this->getCinemasWithMovies('WWW', $filter, $date));
}
}