src/Controller/PackageController.php line 95

Open in your IDE?
  1. <?php
  2.     namespace App\Controller;
  3.     use App\Service\TessituraBundle\CateringService;
  4.     use App\Service\TessituraBundle\Entity\CateringItemPerformance;
  5.     use App\Service\TessituraBundle\Item\PackageItemPackage;
  6.     use App\Service\TessituraBundle\PackageService;
  7.     use App\Service\TessituraSDK\Entity\Remote\Package;
  8.     use App\Service\TessituraSDK\Entity\Remote\Season;
  9.     use App\Service\TessituraSDK\Resource\ReferenceData\Seasons;
  10.     use App\Service\TessituraSDK\Resource\TXN\Packages;
  11.     use App\Service\TessituraSDK\TessituraClient;
  12.     use Doctrine\ORM\NoResultException;
  13.     use Psr\Cache\CacheItemPoolInterface;
  14.     use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  15.     use Symfony\Component\Routing\Annotation\Route;
  16.     use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17.     use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
  18.     use Symfony\Component\DependencyInjection\ContainerInterface;
  19.     use Symfony\Component\HttpFoundation\Request;
  20.     use Symfony\Component\Serializer\Serializer;
  21.     use Symfony\Component\Serializer\SerializerInterface;
  22.     use Symfony\Contracts\Translation\TranslatorInterface;
  23.     use Symfony\Component\Validator\Constraints\DateTime;
  24.     class PackageController extends AbstractController
  25.     {
  26.         /**
  27.          * @var TessituraClient
  28.          */
  29.         private $client;
  30.         /**
  31.          * @var Serializer
  32.          */
  33.         private $serializer;
  34.         /**
  35.          * @var CacheItemPoolInterface|TagAwareAdapterInterface
  36.          */
  37.         private $cache;
  38.         /**
  39.          * @var TranslatorInterface
  40.          */
  41.         private $translator;
  42.         /**
  43.          * @var ParameterBagInterface
  44.          */
  45.         private $params;
  46.         /**
  47.          * CartController constructor.
  48.          *
  49.          * @param TessituraClient $client
  50.          * @param SerializerInterface $serializer
  51.          * @param ContainerInterface $container
  52.          * @param TranslatorInterface $translator
  53.          * @param ParameterBagInterface $params
  54.          */
  55.         public function __construct(
  56.             TessituraClient $client,
  57.             SerializerInterface $serializer,
  58.             ContainerInterface $container,
  59.             TranslatorInterface $translator,
  60.             ParameterBagInterface $params
  61.         ) {
  62.             $this->client     $client;
  63.             $this->serializer $serializer;
  64.             $this->container  $container;
  65.             $this->cache      $container->get('cache.app');
  66.             $this->translator $translator;
  67.             $this->params     $params;
  68.         }
  69.         /**
  70.          * @Route(
  71.          *     "/{_locale}/package/",
  72.          *     name="package",
  73.          *     defaults={
  74.          *          "_locale": "fi"
  75.          *     },
  76.          *     requirements={
  77.          *          "_locale": "fi|sv|en"
  78.          *     }
  79.          * )
  80.          * @param Request $request
  81.          * @param PackageService $packageService
  82.          *
  83.          * @return \Symfony\Component\HttpFoundation\Response
  84.          */
  85.         public function packageAction(Request $requestPackageService $packageService)
  86.         {
  87.             $seasonId = (int)$this->params->get('tessitura.package_season');
  88.             $packages $packageService->getAll($seasonId);
  89.             // Display only packages that are translated
  90.             $packages array_filter($packages, function ($package) {
  91.                 /** @var PackageItemPackage $package */
  92.                 try {
  93.                     $package->getPackage();
  94.                 } catch (NoResultException $exception) {
  95.                     return false;
  96.                 }
  97.                 return true;
  98.             });
  99.             return $this->render('page/package.html.twig', [
  100.                 'packages' => $packages
  101.             ]);
  102.         }
  103.     }