src/Action/PressSite/Product/SingleMovieAction.php line 20

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\EntityActionInterface;
  5. use App\Entity\Product;
  6. use App\Entity\ProductTVSeries;
  7. use App\Repository\ProductRepository;
  8. use App\Service\Helper\PressSite\MultimediaHelper;
  9. use App\Service\PressSite\DomainAwareManager;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Twig\Environment;
  14. /**
  15.  * Class SingleMovieAction.
  16.  */
  17. class SingleMovieAction extends DomainAwareAction implements EntityActionInterface
  18. {
  19.     /**
  20.      * The instance of the product entity repository.
  21.      *
  22.      * @var \App\Repository\ProductRepository
  23.      */
  24.     private $productRepository;
  25.     public function __construct(
  26.         Environment $twig,
  27.         DomainAwareManager $domainAwareManager,
  28.         ProductRepository $productRepository
  29.     ) {
  30.         parent::__construct($twig$domainAwareManager);
  31.         $this->productRepository $productRepository;
  32.     }
  33.     /**
  34.      * Responsible for loading single product.
  35.      *
  36.      * @param \Symfony\Component\HttpFoundation\Request $request
  37.      *   The current request object
  38.      * @param int $id
  39.      *   The ID of the product entity to load
  40.      *
  41.      * @return \Symfony\Component\HttpFoundation\Response
  42.      *   The response object to return
  43.      */
  44.     public function __invoke(Request $requestint $id): Response
  45.     {
  46.         $entity $this->productRepository->findOneByDomainAndLanguageCode(
  47.             $id,
  48.             $this->getDomainManager()->getCurrentByHostnameAndLocale()->getId(),
  49.             $this->getDomainManager()->getCurrentByHostnameAndLocale()->getLanguageCode()
  50.         );
  51.         if (!$entity instanceof Product) {
  52.             throw new NotFoundHttpException('Product not found');
  53.         }
  54.         $request->attributes->set('_product_id'$id);
  55.         $data $request->getSession()->get(MultimediaHelper::createStorageKey($request));
  56.         $itemsCount = (!empty($data) && !empty($data['count'])) ? $data['count'] : 0;
  57.         $isTvSeries $entity instanceof ProductTVSeries;
  58.         return $this->render('press_site/actions/movies/single_movie.html.twig', [
  59.             'entity' => $entity,
  60.             'is_tv_series' => $isTvSeries,
  61.             'storage_items_count' => $itemsCount,
  62.         ]);
  63.     }
  64. }