<?php
namespace App\Action\PressSite\Product;
use App\Action\PressSite\DomainAwareAction;
use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
use App\Service\PressSite\Content\Callback\UpcomingMoviesCallback;
use App\Service\PressSite\Content\MovieContentBuilder;
use App\Service\PressSite\DomainAwareManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;
/**
* Class UpcomingMoviesAction.
*/
class UpcomingMoviesAction extends DomainAwareAction implements GenericActionInterface
{
/**
* The custom content builder responsible for returning the list with new movies.
*
* @var \App\Service\PressSite\Content\MovieContentBuilder
*/
private $contentBuilder;
public function __construct(
Environment $twig,
DomainAwareManager $domainAwareManager,
MovieContentBuilder $contentBuilder
) {
parent::__construct($twig, $domainAwareManager);
$this->contentBuilder = $contentBuilder;
}
/**
* Responsible for returning a collection of products.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object
*
* @return \Symfony\Component\HttpFoundation\Response
* The response object
*/
public function __invoke(Request $request): Response
{
// Theatrical sites do not have upcoming movies content page.
if ($this->getDomainManager()->getCurrentByHostnameAndLocale()->isBroadcastType()) {
throw new NotFoundHttpException('Page not found');
}
$this->contentBuilder->addCallback(new UpcomingMoviesCallback());
return $this->render('press_site/actions/movies/upcoming_movies.html.twig', [
'collection' => $this->contentBuilder->getContent(
100,
MovieContentBuilder::SORT_ORDER_ASC,
MovieContentBuilder::SORT_BY_DATE_TYPE
),
]);
}
}