src/Action/PressSite/Content/DefaultAction.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Action\PressSite\Content;
  3. use App\Action\PressSite\DomainAwareAction;
  4. use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
  5. use App\Service\PressSite\Content\Callback\NewMoviesCallback;
  6. use App\Service\PressSite\Content\Callback\UpcomingMoviesCallback;
  7. use App\Service\PressSite\Content\MovieContentBuilder;
  8. use App\Service\PressSite\DomainAwareManager;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Twig\Environment;
  13. /**
  14.  * Class HomepageAction.
  15.  */
  16. class DefaultAction extends DomainAwareAction implements GenericActionInterface
  17. {
  18.     /**
  19.      * The custom content builder responsible for returning the list with new movies.
  20.      *
  21.      * @var \App\Service\PressSite\Content\MovieContentBuilder
  22.      */
  23.     private $contentBuilder;
  24.     public function __construct(
  25.         Environment $twig,
  26.         DomainAwareManager $domainAwareManager,
  27.         MovieContentBuilder $contentBuilder
  28.     ) {
  29.         parent::__construct($twig$domainAwareManager);
  30.         $this->contentBuilder $contentBuilder;
  31.     }
  32.     /**
  33.      * Responsible for rendering the homepage content.
  34.      *
  35.      * @param \Symfony\Component\HttpFoundation\Request $request
  36.      *   The current request object
  37.      *
  38.      * @return \Symfony\Component\HttpFoundation\Response
  39.      *   The response object to return
  40.      */
  41.     public function __invoke(Request $request): Response
  42.     {
  43.         // Theatrical sites do not have the new movies content page.
  44.         if ($this->getDomainManager()->getCurrentByHostnameAndLocale()->isBroadcastType()) {
  45.             throw new NotFoundHttpException('Page not found');
  46.         }
  47.         $limit 5;
  48.         return $this->render('press_site/actions/content/default.html.twig', [
  49.             'new_movies_collection' => $this->getNewMovies($limit),
  50.             'upcoming_movies_collection' => $this->getUpcomingMovies($limit),
  51.         ]);
  52.     }
  53.     /**
  54.      * Returns the collection of upcoming movies.
  55.      *
  56.      * @param int $limit
  57.      *   The amount of results to return
  58.      *
  59.      * @return array
  60.      *   The movies collection
  61.      */
  62.     protected function getUpcomingMovies(int $limit): array
  63.     {
  64.         $this->contentBuilder->reset();
  65.         $this->contentBuilder->addCallback(new UpcomingMoviesCallback());
  66.         return $this->contentBuilder->getContent(
  67.             $limit,
  68.             MovieContentBuilder::SORT_ORDER_ASC,
  69.             MovieContentBuilder::SORT_BY_DATE_TYPE
  70.         );
  71.     }
  72.     /**
  73.      * Returns the collection of new movies.
  74.      *
  75.      * @param int $limit
  76.      *   The amount of results to return
  77.      *
  78.      * @return array
  79.      *   The movies collection
  80.      */
  81.     protected function getNewMovies(int $limit): array
  82.     {
  83.         $this->contentBuilder->reset();
  84.         $this->contentBuilder->addCallback(new NewMoviesCallback());
  85.         return $this->contentBuilder->getContent($limitMovieContentBuilder::SORT_ORDER_DESC);
  86.     }
  87. }