src/Controller/BookingApi/ApiCatalogControllerApi.php line 581

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller\BookingApi;
  7. use App\Ecommerce\OrderManager\Filter\TicketCatalog;
  8. use App\Model\BookingApi\DateRange;
  9. use App\Model\BookingApi\Event;
  10. use App\Model\BookingApi\EventAgeGroupPrice;
  11. use App\Model\BookingApi\Image;
  12. use App\Model\BookingApi\LocalizedText;
  13. use App\Model\BookingApi\PriceInfos;
  14. use App\Model\BookingApi\SimpleIdTextObject;
  15. use App\Model\BookingApi\TextWithHeadline;
  16. use App\Model\BookingApi\TicketCatalogUpgradeRelation;
  17. use App\Model\BookingApi\TicketInsurance;
  18. use App\Model\BookingApi\TicketValidity;
  19. use App\Model\Shop\Event\EventProduct;
  20. use App\Model\Shop\Event\ShopDynamicPrice;
  21. use App\Model\Shop\Ticket\ShopTicketCatalog;
  22. use App\Model\Type\TenantType;
  23. use App\Traits\EnvironmentTrait;
  24. use Carbon\Carbon;
  25. use OpenApi\Annotations as OA;
  26. use Pimcore\Model\DataObject\Data\ObjectMetadata;
  27. use Pimcore\Model\DataObject\Fieldcollection\Data\CustomDescription;
  28. use Pimcore\Model\DataObject\Fieldcollection\Data\PriceInfo;
  29. use Pimcore\Model\DataObject\ShopEvent;
  30. use Symfony\Component\HttpFoundation\JsonResponse;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. /**
  34.  * Class ApiCatalogControllerApi
  35.  *
  36.  * @Route("/bookingAPI/catalog")
  37.  *
  38.  * @OA\Tag(name="Catalog")
  39.  */
  40. class ApiCatalogControllerApi extends ApiAbstractController
  41. {
  42.     use EnvironmentTrait;
  43.     /**
  44.      * Return all relevant ticket catalog data for marketplace
  45.      *
  46.      * @param Request $request
  47.      *
  48.      * @Route("/ticketcatalogs", name="catalog_ticketcatalogs", methods={"POST", "GET"})
  49.      *
  50.      * @OA\Post(
  51.      *     path="/bookingAPI/catalog/ticketcatalogs",
  52.      *     description="Get all relevant ticket catalog data for marketplace",
  53.      *     tags={"Catalog"},
  54.      *
  55.      *     @OA\RequestBody(
  56.      *      required=false,
  57.      *
  58.      *           @OA\JsonContent(
  59.      *
  60.      *              @OA\Property( property="pageSize", type="string", example="10"),
  61.      *              @OA\Property( property="pageNumber", type="string", example="1"),
  62.      *          )
  63.      *      ),
  64.      *
  65.      *      @OA\Response(
  66.      *          response=200,
  67.      *          description="Successful operation",
  68.      *
  69.      *          @OA\MediaType(
  70.      *              mediaType="application/json",
  71.      *
  72.      *              @OA\Schema(
  73.      *                  type = "object",
  74.      *
  75.      *                   @OA\Property(property="success", type="boolean"),
  76.      *                   @OA\Property(property="total", type="int", example=50),
  77.      *                   @OA\Property(property="pageCurrent", type="int", example=1),
  78.      *                   @OA\Property(property="pageSize", type="int", example=10),
  79.      *                   @OA\Property(property="pageLast", type="int", example=5),
  80.      *                   @OA\Property(property="ticketCatalogs", type="array",
  81.      *
  82.      *                      @OA\Items(ref="#/components/schemas/TicketCatalog")
  83.      *                   )
  84.      *              )
  85.      *          )
  86.      *      ),
  87.      *
  88.      *     @OA\Response(
  89.      *          response=500,
  90.      *          description="Error",
  91.      *      ),
  92.      *
  93.      *     @OA\Info (
  94.      *          title="ticket catalog",
  95.      *          version="0.0.1"
  96.      *      )
  97.      *
  98.      *
  99.      * )
  100.      */
  101.     public function ticketcatalogsAction(Request $request): JsonResponse
  102.     {
  103.         $body $request->getContent();
  104.         $requestData json_decode($bodytrue);
  105.         $pageSize $requestData intval($requestData['pageSize']) : 100;
  106.         $pageNumber $requestData intval($requestData['pageNumber']) : 1;
  107.         try {
  108.             $ticketData $this->getTicketCatalogsAsJson($pageSize$pageNumber);
  109.             $returnData['success'] = true;
  110.             $returnData array_merge($returnData$ticketData);
  111.             if ($request->get('debug')) {
  112.                 p_r($returnData);
  113.                 die();
  114.             }
  115.             return new JsonResponse($returnData);
  116.         } catch (\Throwable $throwable) {
  117.             $this->bookingapiLogger->error($throwable->getMessage() . 'Stack Trace: ' $throwable->getTraceAsString());
  118.             return $this->sendErrors([$throwable->getMessage()], 500);
  119.         }
  120.     }
  121.     /**
  122.      * Return all relevant event catalog data for marketplace. Quota gets displayed for each day with the timestamp being the beginning of the day
  123.      *
  124.      * @param Request $request
  125.      *
  126.      * @Route("/events", name="catalog_events", methods={"POST", "GET"})
  127.      *
  128.      * @OA\Post(
  129.      *     path="/bookingAPI/catalog/events",
  130.      *     description="Get all relevant event catalog data for marketplace. Quota gets displayed for each day with the timestamp being the beginning of the day",
  131.      *     tags={"Catalog"},
  132.      *
  133.      *     @OA\RequestBody(
  134.      *      required=false,
  135.      *
  136.      *           @OA\JsonContent(
  137.      *
  138.      *              @OA\Property( property="pageSize", type="string", example="10"),
  139.      *              @OA\Property( property="pageNumber", type="string", example="1"),
  140.      *          )
  141.      *      ),
  142.      *
  143.      *      @OA\Response(
  144.      *          response=200,
  145.      *          description="Successful operation",
  146.      *
  147.      *          @OA\MediaType(
  148.      *              mediaType="application/json",
  149.      *
  150.      *              @OA\Schema(
  151.      *                  type = "object",
  152.      *
  153.      *                   @OA\Property(property="success", type="boolean"),
  154.      *                   @OA\Property(property="total", type="int", example=50),
  155.      *                   @OA\Property(property="pageCurrent", type="int", example=1),
  156.      *                   @OA\Property(property="pageSize", type="int", example=10),
  157.      *                   @OA\Property(property="pageLast", type="int", example=5),
  158.      *                   @OA\Property(property="events", type="array",
  159.      *
  160.      *                      @OA\Items(ref="#/components/schemas/Event")
  161.      *                   )
  162.      *              )
  163.      *          )
  164.      *      ),
  165.      *
  166.      *     @OA\Response(
  167.      *          response=500,
  168.      *          description="Error",
  169.      *      ),
  170.      *
  171.      * )
  172.      */
  173.     public function eventsAction(Request $request): JsonResponse
  174.     {
  175.         $body $request->getContent();
  176.         $requestData json_decode($bodytrue);
  177.         $pageSize $requestData intval($requestData['pageSize']) : 100;
  178.         $pageNumber $requestData intval($requestData['pageNumber']) : 1;
  179.         try {
  180.             $this->setEnvironmentTenant();
  181.             $eventData $this->getEventsAsJson($pageSize$pageNumber);
  182.             $returnData['success'] = true;
  183.             $returnData array_merge($returnData$eventData);
  184.             if ($request->get('debug')) {
  185.                 p_r($returnData);
  186.                 die();
  187.             }
  188.             return new JsonResponse($returnData);
  189.         } catch (\Throwable $throwable) {
  190.             $this->bookingapiLogger->error($throwable->getMessage() . 'Stack Trace: ' $throwable->getTraceAsString());
  191.             return $this->sendErrors([$throwable->getMessage()], 500);
  192.         }
  193.     }
  194.     /**
  195.      * @param int $pageSize
  196.      * @param int $pageNumber
  197.      *
  198.      * @return array<string,mixed>
  199.      */
  200.     private function getTicketCatalogsAsJson(int $pageSizeint $pageNumber): array
  201.     {
  202.         $jsonTicketData = [];
  203.         $listing = new \Pimcore\Model\DataObject\ShopTicketCatalog\Listing();
  204.         $listing->setOrderKey('sort DESC, name ASC'false);
  205.         $listing->addConditionParam('FIND_IN_SET("' TenantType::MARKETPLACE '", tenant)');
  206.         $listing->setOffset($pageNumber == : ($pageSize * ($pageNumber 1) + 1));
  207.         $listing->setLimit($pageSize);
  208.         foreach ($listing->load() as $shopTicketCatalog) {
  209.             /**
  210.              * @var ShopTicketCatalog $shopTicketCatalog
  211.              */
  212.             $catalogId $shopTicketCatalog->getId();
  213.             $teaserPrice $shopTicketCatalog->getTeaserPrice();
  214.             $galleryImages = [];
  215.             if($shopTicketCatalog->getMainImage()){
  216.                 $galleryImages[$shopTicketCatalog->getMainImage()->getId()]=$this->formatImage($shopTicketCatalog->getMainImage());
  217.             }
  218.             foreach($shopTicketCatalog->getGallery() as $galleryImage){
  219.                 $galleryImages[$galleryImage->getImage()->getId()] = $this->formatImage($galleryImage->getImage());
  220.             }
  221.             $galleryImages array_values($galleryImages);
  222.             $ticketCatalogItem = new \App\Model\BookingApi\TicketCatalog();
  223.             $ticketCatalogItem->id $catalogId;
  224.             $ticketCatalogItem->sort $shopTicketCatalog->getSort() ?: 0;
  225.             $ticketCatalogItem->images $galleryImages;
  226.             $ticketCatalogItem->interests $this->getInterests($shopTicketCatalog);
  227.             $ticketCatalogItem->category $this->getCategory($shopTicketCatalog);
  228.             $ticketCatalogItem->bookingDisabled boolval($shopTicketCatalog->getIsNotBookable());
  229.             $ticketCatalogItem->setIsUpgrade(boolval($shopTicketCatalog->getIsUpgrade()));
  230.             if(!$shopTicketCatalog->getIsUpgrade() && count($shopTicketCatalog->getUpgrades())>0){
  231.                 $upgradeInfo = [];
  232.                 foreach($shopTicketCatalog->getUpgrades() as $objectMetadata){
  233.                     $relation = new TicketCatalogUpgradeRelation();
  234.                     $relation->setUpgradeCatalogId($objectMetadata->getObject()->getId());
  235.                     $relation->setUpgradeKey($objectMetadata->getData()['name']);
  236.                     $upgradeInfo[]=$relation;
  237.                 }
  238.                 $ticketCatalogItem->setUpgradeCatalogs($upgradeInfo);
  239.             }
  240.             $ticketCatalogItem->setIsMarketplacePackage(boolval($shopTicketCatalog->getIsMarketplacePackage()));
  241.             $validDates = [];
  242.             foreach ($shopTicketCatalog->getAllValidDateRanges(Carbon::now()->startOfDay(), 'U000') as $dateRange) {
  243.                 $validDates[] = new DateRange($dateRange['from'], $dateRange['to']);
  244.             }
  245.             $ticketCatalogItem->validDates $validDates;
  246.             $ticketCatalogItem->consumerCategories $this->getConsumerCategories($shopTicketCatalog->getTicketConsumerCategories());
  247.             $ticketCatalogItem->ticketProducts $this->getTicketProducts($shopTicketCatalog);
  248.             $ticketCatalogItem->insurances $this->getInsurances($shopTicketCatalog);
  249.             $ticketCatalogItem->createdAt $shopTicketCatalog->getCreationDate() * 1000;
  250.             $ticketCatalogItem->updatedAt $shopTicketCatalog->getModificationDate() * 1000;
  251.             if ($teaserPrice) {
  252.                 $ticketCatalogItem->priceFrom $this->formatPrice($teaserPrice);
  253.             }
  254.             $ticketCatalogItem->setCustomDescriptions($this->getCustomDescriptions($shopTicketCatalog));
  255.             $ticketCatalogItem->setPriceInfos($this->getPriceInfos($shopTicketCatalog));
  256.             $name = new LocalizedText();
  257.             $description = new LocalizedText();
  258.             $topLine = new LocalizedText();
  259.             $priceDescription = new LocalizedText();
  260.             $includeDescription = new LocalizedText();
  261.             $bookingNoteDescription = new LocalizedText();
  262.             $priceInfoNote = new LocalizedText();
  263.             foreach ($this->languages as $language) {
  264.                 $topLine->$language $shopTicketCatalog->getTitleMarketplace($language) ?: '';
  265.                 $name->$language $shopTicketCatalog->getName($language) ?: '';
  266.                 $bookingNoteDescription->$language $shopTicketCatalog->getBookingNoteDescription($language) ?: '';
  267.                 $includeDescription->$language $shopTicketCatalog->getIncludeDescription($language) ?: '';
  268.                 $priceDescription->$language $shopTicketCatalog->getPriceInfoDescription($language) ?: '';
  269.                 $priceInfoNote->$language $shopTicketCatalog->getPriceInfoNote($language) ?: '';
  270.                 $description->$language $shopTicketCatalog->getMarketplaceDescription($language) ?: '';
  271.             }
  272.             $ticketCatalogItem->name $name;
  273.             $ticketCatalogItem->description $description;
  274.             $ticketCatalogItem->topLine $topLine;
  275.             $ticketCatalogItem->priceDescription $priceDescription;
  276.             $ticketCatalogItem->priceInfoNote $priceInfoNote;
  277.             $ticketCatalogItem->includeDescriptions $includeDescription;
  278.             $ticketCatalogItem->bookingNoteDescription $bookingNoteDescription;
  279.             $jsonTicketData[] = $ticketCatalogItem->jsonSerialize();
  280.         }
  281.         return [
  282.             'total' => $listing->getTotalCount(),
  283.             'pageCurrent' => intval($pageNumber),
  284.             'pageSize' => intval($pageSize),
  285.             'pageLast' => intval(ceil($listing->getTotalCount() / $pageSize)),
  286.             'ticketCatalogs' => $jsonTicketData,
  287.         ];
  288.     }
  289.     /**
  290.      * @param int $pageSize
  291.      * @param int $pageNumber
  292.      *
  293.      * @return array<string, mixed>
  294.      */
  295.     public function getEventsAsJson(int $pageSizeint $pageNumber): array
  296.     {
  297.         $listing = new \Pimcore\Model\DataObject\ShopEvent\Listing();
  298.         $listing->setOrderKey('sort ASC, name ASC'false);
  299.         $listing->addConditionParam('FIND_IN_SET("' TenantType::MARKETPLACE '", tenant)');
  300.         $listing->setOffset($pageNumber == : ($pageSize * ($pageNumber 1) + 1));
  301.         $listing->setLimit($pageSize);
  302.         $jsonEventData = [];
  303.         foreach ($listing->load() as $shopEvent) {
  304.             /**
  305.              * @var EventProduct $shopEvent
  306.              */
  307.             $apiEvent = new Event();
  308.             $apiEvent->id $shopEvent->getId();
  309.             $teaserPrice $shopEvent->getTeaserPrice();
  310.             $apiEvent->sort intval($shopEvent->getSort());
  311.             $apiEvent->images $this->getEventImages($shopEvent);
  312.             $apiEvent->bookable $shopEvent->isBookable();
  313.             $apiEvent->stopSale intval($shopEvent->getStopSale());
  314.             $apiEvent->stopSaleEndOfDay boolval($shopEvent->getBookableOnDayOfEvent());
  315.             $apiEvent->maxParticipantPerBooking $shopEvent->getMaxParticipantPerBooking() ?: 0;
  316.             $apiEvent->ageGroups $this->getEventAgeGroups($shopEvent);
  317.             $apiEvent->validDates $this->getValidEventDates($shopEvent);
  318.             $apiEvent->interests $this->getInterests($shopEvent);
  319.             $apiEvent->displayDates $shopEvent->getDisplayDates();
  320.             $apiEvent->createdAt $shopEvent->getCreationDate() * 1000;
  321.             $apiEvent->updatedAt $shopEvent->getModificationDate() * 1000;
  322.             $apiEvent->priceFrom $this->formatPrice($teaserPrice);
  323.             $apiEvent->category $this->getCategory($shopEvent);
  324.             $apiEvent->setCustomDescriptions($this->getCustomDescriptions($shopEvent));
  325.             $apiEvent->setPriceInfos($this->getPriceInfos($shopEvent));
  326.             $name = new LocalizedText();
  327.             $topLine = new LocalizedText();
  328.             $description = new LocalizedText();
  329.             $priceDescription = new LocalizedText();
  330.             $includeDescription = new LocalizedText();
  331.             $priceInfoNote = new LocalizedText();
  332.             foreach ($this->languages as $language) {
  333.                 $name->$language $shopEvent->getName($language) ?: '';
  334.                 $topLine->$language $shopEvent->getTopTitle($language) ?: '';
  335.                 $description->$language $shopEvent->getMarketplaceDescription($language) ?: '';
  336.                 $priceDescription->$language $shopEvent->getPriceInfoDescription($language) ?: '';
  337.                 $priceInfoNote->$language $shopEvent->getPriceInfoNote($language) ?: '';
  338.                 $includeDescription->$language $shopEvent->getIncludeDescription($language) ?: '';
  339.             }
  340.             $apiEvent->setName($name);
  341.             $apiEvent->setTopLine($topLine);
  342.             $apiEvent->setDescription($description);
  343.             $apiEvent->setPriceDescription($priceDescription);
  344.             $apiEvent->setPriceInfoNote($priceInfoNote);
  345.             $apiEvent->setIncludeDescription($includeDescription);
  346.             $jsonEventData[] = $apiEvent->jsonSerialize();
  347.         }
  348.         return [
  349.             'total' => $listing->getTotalCount(),
  350.             'pageCurrent' => intval($pageNumber),
  351.             'pageSize' => intval($pageSize),
  352.             'pageLast' => intval(ceil($listing->getTotalCount() / $pageSize)),
  353.             'events' => $jsonEventData,
  354.         ];
  355.     }
  356.     /**
  357.      * @param ShopTicketCatalog|EventProduct $shopTicketCatalog
  358.      *
  359.      * @return SimpleIdTextObject[]
  360.      */
  361.     private function getInterests(ShopTicketCatalog|EventProduct $shopTicketCatalog): array
  362.     {
  363.         $interests = [];
  364.         foreach ($shopTicketCatalog->getInterestsMarketplace() as $interest) {
  365.             $apiObject = new SimpleIdTextObject();
  366.             $apiObject->id $interest->getId();
  367.             $text = new LocalizedText();
  368.             foreach ($this->languages as $language) {
  369.                 $text->$language $interest->getName($language) ?: '';
  370.             }
  371.             $apiObject->texts $text;
  372.             $interests[] = $apiObject;
  373.         }
  374.         return $interests;
  375.     }
  376.     private function getCategory(ShopTicketCatalog|EventProduct $shopTicketCatalog): SimpleIdTextObject
  377.     {
  378.         $apiObject = new SimpleIdTextObject();
  379.         $category $shopTicketCatalog->getProductCategoryMarketplace();
  380.         if ($category) {
  381.             $apiObject->id $category->getId();
  382.             $texts = new LocalizedText();
  383.             foreach ($this->languages as $language) {
  384.                 $texts->$language $category->getName($language) ?: '';
  385.             }
  386.             $apiObject->texts $texts;
  387.         }
  388.         return $apiObject;
  389.     }
  390.     /**
  391.      * @param ShopTicketCatalog|EventProduct $sourceObject
  392.      *
  393.      * @return PriceInfos[]
  394.      */
  395.     private function getPriceInfos(ShopTicketCatalog|EventProduct $sourceObject): array
  396.     {
  397.         $priceInfos = [];
  398.         if ($sourceObject->getPriceInfos()) {
  399.             foreach ($sourceObject->getPriceInfos() as $priceInfoItem) {
  400.                 /**
  401.                  * @var PriceInfo $priceInfoItem
  402.                  */
  403.                 $priceInfo = new PriceInfos();
  404.                 $title = new LocalizedText();
  405.                 $additionalInfo = new LocalizedText();
  406.                 $ageGroupInfo = new LocalizedText();
  407.                 $priceInfoText = new LocalizedText();
  408.                 foreach ($this->languages as $language) {
  409.                     $title->$language $priceInfoItem->getTitle($language) ?: '';
  410.                     $additionalInfo->$language $priceInfoItem->getAdditionalInfo($language) ?: '';
  411.                     $ageGroupInfo->$language $priceInfoItem->getAgeGroup($language) ?: '';
  412.                     $priceInfoText->$language $priceInfoItem->getPriceInfoText($language) ?: '';
  413.                 }
  414.                 $priceInfo->setTitle($title);
  415.                 $priceInfo->setAdditionalInfo($additionalInfo);
  416.                 $priceInfo->setAgeGroupText($ageGroupInfo);
  417.                 $priceInfo->setPriceInfoText($priceInfoText);
  418.                 $priceInfos[] = $priceInfo;
  419.             }
  420.         }
  421.         return $priceInfos;
  422.     }
  423.     /**
  424.      * @param ShopTicketCatalog|EventProduct $sourceObject
  425.      *
  426.      * @return TextWithHeadline[]
  427.      */
  428.     private function getCustomDescriptions(ShopTicketCatalog|EventProduct $sourceObject): array
  429.     {
  430.         $customDescriptions = [];
  431.         foreach ($sourceObject->getCustomDescriptions() ?: [] as $customDescriptionItem) {
  432.             /**
  433.              * @var CustomDescription $customDescriptionItem
  434.              */
  435.             $localizedHeadine = new LocalizedText();
  436.             $localizedText = new LocalizedText();
  437.             $customDescription = new TextWithHeadline();
  438.             foreach ($this->languages as $language) {
  439.                 $localizedHeadine->$language $customDescriptionItem->getCustomHeadline($language) ?: '';
  440.                 $localizedText->$language $customDescriptionItem->getCustomDescription($language) ?: '';
  441.             }
  442.             $customDescription->headline $localizedHeadine;
  443.             $customDescription->text $localizedText;
  444.             $customDescriptions[] = $customDescription;
  445.         }
  446.         return $customDescriptions;
  447.     }
  448.     /**
  449.      * @param ShopTicketCatalog $ticketCatalog
  450.      *
  451.      * @return \App\Model\BookingApi\TicketProduct[]
  452.      */
  453.     private function getTicketProducts(ShopTicketCatalog $ticketCatalog): array
  454.     {
  455.         $ticketData = [];
  456.         foreach ($ticketCatalog->getTicketProducts() as $ticketProduct) {
  457.             /**
  458.              * @var  \Elements\Bundle\TicketShopFrameworkBundle\Model\DataObject\TicketProduct $ticketProduct
  459.              */
  460.             $apiTicketProduct = new \App\Model\BookingApi\TicketProduct();
  461.             $apiTicketProduct->id $ticketProduct->getId();
  462.             $localizedName = new LocalizedText();
  463.             $localizedInfoText = new LocalizedText();
  464.             $localizedCatalogInfoText = new LocalizedText();
  465.             foreach ($this->languages as $language) {
  466.                 $localizedName->$language $ticketProduct->getName($language) ?: '';
  467.                 $localizedCatalogInfoText->$language $ticketCatalog->getInfoBubbleDescription($language) ?: '';
  468.                 $localizedInfoText->$language $ticketProduct->getDescription($language) ?: '';
  469.             }
  470.             $apiTicketProduct->name $localizedName;
  471.             $apiTicketProduct->infoText $localizedInfoText;
  472.             $apiTicketProduct->infoTextCatalog $localizedCatalogInfoText;
  473.             $apiTicketProduct->acquisitionTypes $ticketProduct->getAllowedAcquisitionTypes() ?: [];
  474.             $apiTicketProduct->defaultAcquisitionType $ticketProduct->getDefaultAcquisitionType() ?: '';
  475.             $apiTicketProduct->personalization $ticketProduct->getRequirements() ?: [];
  476.             $validity = new TicketValidity();
  477.             $validity->validityValue $ticketProduct->getValidityValue();
  478.             $validity->validityUnit $ticketProduct->getValidityUnit();
  479.             $apiTicketProduct->validity $validity;
  480.             $ticketData[] = $apiTicketProduct;
  481.         }
  482.         return $ticketData;
  483.     }
  484.     /**
  485.      * @param ShopTicketCatalog $shopTicketCatalog
  486.      *
  487.      * @return TicketInsurance[]
  488.      */
  489.     private function getInsurances(ShopTicketCatalog $shopTicketCatalog): array
  490.     {
  491.         $insurances = [];
  492.         foreach ($shopTicketCatalog->getInsurances() as $insurance) {
  493.             $apiInsurance = new TicketInsurance();
  494.             $apiInsurance->id $insurance->getId();
  495.             $localizedName = new LocalizedText();
  496.             $localizedDescription = new LocalizedText();
  497.             foreach ($this->languages as $language) {
  498.                 $localizedName->$language $insurance->getName($language) ?: '';
  499.                 $localizedDescription->$language $insurance->getDescription($language) ?: '';
  500.             }
  501.             $apiInsurance->name $localizedName;
  502.             $apiInsurance->description $localizedDescription;
  503.             $insurances[] = $apiInsurance;
  504.         }
  505.         return $insurances;
  506.     }
  507.     /**
  508.      * @param ShopEvent $shopEvent
  509.      *
  510.      * @return Image[]
  511.      */
  512.     private function getEventImages(ShopEvent $shopEvent): array
  513.     {
  514.         $imageData = [];
  515.         if($shopEvent->getMainImage()){
  516.             $imageData[$shopEvent->getMainImage()->getId()]= $this->formatImage($shopEvent->getMainImage());
  517.         }
  518.         foreach ($shopEvent->getImages() as $image) {
  519.             if ($image instanceof \Pimcore\Model\DataObject\Data\Hotspotimage) {
  520.                 $image $image->getImage();
  521.             }
  522.             $imageData[$image->getId()] = $this->formatImage($image);
  523.         }
  524.         return array_values($imageData);
  525.     }
  526.     /**
  527.      * @param EventProduct $shopEvent
  528.      *
  529.      * @return array<mixed>
  530.      */
  531.     private function getValidEventDates(EventProduct $shopEvent): array
  532.     {
  533.         $ranges $shopEvent->getAllValidDateRanges(Carbon::now()->startOfDay(), null);
  534.         $dates = [];
  535.         foreach ($ranges as $range) {
  536.             $dates[] = [
  537.                 'from' => $range['from']->getTimestamp() * 1000,
  538.                 'to' => $range['to']->getTimestamp() * 1000,
  539.                 'availability' => $this->getAvailability($range['from'], $range['to'], $shopEvent),
  540.             ];
  541.         }
  542.         return $dates;
  543.     }
  544.     /**
  545.      * @param Carbon $from
  546.      * @param Carbon $to
  547.      * @param EventProduct $shopEvent
  548.      *
  549.      * @return array<int,int>
  550.      */
  551.     private function getAvailability(Carbon $fromCarbon $toEventProduct $shopEvent): array
  552.     {
  553.         $availability = [];
  554.         /**
  555.          * @var \App\Ecommerce\AvailabilitySystem\Event\AvailabilitySystem $availabilitySystem
  556.          */
  557.         $availabilitySystem $shopEvent->getAvailabilitySystemImplementation();
  558.         $items $availabilitySystem->getAvailableList($shopEvent$from$to);
  559.         foreach ($items as $key => $item) {
  560.             $timeStampMs intval($key) * 1000;
  561.             $availability[$timeStampMs] = $item->getAvailableQuota() <= $item->getAvailableQuota();
  562.         }
  563.         return $availability;
  564.     }
  565.     /**
  566.      * @param ShopEvent $shopEvent
  567.      *
  568.      * @return EventAgeGroupPrice[]
  569.      */
  570.     private function getEventAgeGroups(ShopEvent $shopEvent): array
  571.     {
  572.         $eventAgeGroupsData = [];
  573.         $dynamicPrices $shopEvent->getPrices() ?: [];
  574.         foreach ($dynamicPrices as $dynamicPrice) {
  575.             /**
  576.              * @var ObjectMetadata $dynamicPrice
  577.              */
  578.             $groupName '';
  579.             if(in_array('groupname'$dynamicPrice->getColumns())){
  580.                 if(isset($dynamicPrice->getData()['groupname'])){
  581.                     $groupName $dynamicPrice->getData()['groupname'];
  582.                 }
  583.             }
  584.             $dynamicPriceObject $dynamicPrice->getObject();
  585.             if ($dynamicPriceObject instanceof ShopDynamicPrice) {
  586.                 $ageGroupData = new EventAgeGroupPrice();
  587.                 $ageGroupData->setId($dynamicPriceObject->getId());
  588.                 $ageGroupData->setPrice($this->formatPrice($dynamicPriceObject->getDefaultPrice()));
  589.                 $localizedTexts = new LocalizedText();
  590.                 $localizedGroupName = new LocalizedText();
  591.                 foreach ($this->languages as $language) {
  592.                     $localizedTexts->$language $dynamicPriceObject->getPriceLabel($language);
  593.                     if(!empty($groupName)) {
  594.                         $localizedGroupName->$language $this->translator->trans($groupName, [], null$language);
  595.                     }
  596.                 }
  597.                 if(!empty($groupName)){
  598.                     $ageGroupData->setGroupName($groupName);
  599.                     $ageGroupData->setGroupNameTexts($localizedGroupName);
  600.                 }
  601.                 $ageGroupData->setName($localizedTexts);
  602.                 $eventAgeGroupsData[] = $ageGroupData;
  603.             }
  604.         }
  605.         return $eventAgeGroupsData;
  606.     }
  607. }