src/Action/PressSite/Product/AllMoviesAction.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Action\PressSite\Product;
  3. use App\Action\PressSite\DomainAwareAction;
  4. use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
  5. use App\Service\PressSite\Content\MovieContentBuilder;
  6. use App\Service\PressSite\DomainAwareManager;
  7. use App\Service\PressSite\Paginator;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Twig\Environment;
  11. /**
  12.  * Class AllMoviesAction.
  13.  */
  14. class AllMoviesAction extends DomainAwareAction implements GenericActionInterface
  15. {
  16.     /**
  17.      * The custom content builder responsible for returning the list with all movies.
  18.      *
  19.      * @var \App\Service\PressSite\Content\MovieContentBuilder
  20.      */
  21.     private $contentBuilder;
  22.     /**
  23.      * The pagination helper service.
  24.      *
  25.      * @var \App\Service\PressSite\Paginator
  26.      */
  27.     private $paginatorHelper;
  28.     public function __construct(
  29.         Environment $twig,
  30.         DomainAwareManager $domainAwareManager,
  31.         MovieContentBuilder $contentBuilder,
  32.         Paginator $paginator
  33.     ) {
  34.         parent::__construct($twig$domainAwareManager);
  35.         $this->contentBuilder $contentBuilder;
  36.         $this->paginatorHelper $paginator;
  37.     }
  38.     /**
  39.      * Responsible for returning a collection of products.
  40.      *
  41.      * @param \Symfony\Component\HttpFoundation\Request $request
  42.      *   The current request object
  43.      *
  44.      * @return \Symfony\Component\HttpFoundation\Response
  45.      *   The response object
  46.      */
  47.     public function __invoke(Request $request): Response
  48.     {
  49.         $this->contentBuilder->setLoadAllMovies(true);
  50.         $totalItems $this->contentBuilder->count();
  51.         $this->paginatorHelper->setTotalItems($totalItems);
  52.         $this->contentBuilder->setOffset($this->paginatorHelper->getOffset());
  53.         return $this->render('press_site/actions/movies/all_movies.html.twig', [
  54.             'collection' => $this->contentBuilder->getContent(
  55.                 $this->paginatorHelper->getLimit(),
  56.                 MovieContentBuilder::SORT_ORDER_ASC,
  57.                 MovieContentBuilder::SORT_BY_TITLE
  58.             ),
  59.             'paginator' => $this->paginatorHelper,
  60.             'total_items' => $totalItems,
  61.         ]);
  62.     }
  63. }