<?php
namespace App\Action\PressSite\Product;
use App\Action\PressSite\DomainAwareAction;
use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
use App\Service\PressSite\Content\MovieContentBuilder;
use App\Service\PressSite\DomainAwareManager;
use App\Service\PressSite\Paginator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
/**
* Class AllMoviesAction.
*/
class AllMoviesAction extends DomainAwareAction implements GenericActionInterface
{
/**
* The custom content builder responsible for returning the list with all movies.
*
* @var \App\Service\PressSite\Content\MovieContentBuilder
*/
private $contentBuilder;
/**
* The pagination helper service.
*
* @var \App\Service\PressSite\Paginator
*/
private $paginatorHelper;
public function __construct(
Environment $twig,
DomainAwareManager $domainAwareManager,
MovieContentBuilder $contentBuilder,
Paginator $paginator
) {
parent::__construct($twig, $domainAwareManager);
$this->contentBuilder = $contentBuilder;
$this->paginatorHelper = $paginator;
}
/**
* 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
{
$this->contentBuilder->setLoadAllMovies(true);
$totalItems = $this->contentBuilder->count();
$this->paginatorHelper->setTotalItems($totalItems);
$this->contentBuilder->setOffset($this->paginatorHelper->getOffset());
return $this->render('press_site/actions/movies/all_movies.html.twig', [
'collection' => $this->contentBuilder->getContent(
$this->paginatorHelper->getLimit(),
MovieContentBuilder::SORT_ORDER_ASC,
MovieContentBuilder::SORT_BY_TITLE
),
'paginator' => $this->paginatorHelper,
'total_items' => $totalItems,
]);
}
}