src/Controller/Shop/Json/EventJsonController.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller\Shop\Json;
  7. use App\Controller\AbstractController;
  8. use App\Model\Shop\Event\EventProduct;
  9. use App\Service\Shop\JsonDataService;
  10. use Carbon\Carbon;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. /**
  16.  * @Route("/{_locale}/shop/event")
  17.  */
  18. class EventJsonController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/calendar-dates", name="json_event_calendar_dates", methods={"GET"})
  22.      */
  23.     public function calendarDatesJson(Request $requestJsonDataService $jsonDataService): Response
  24.     {
  25.         return $this->json($jsonDataService->getCalendarDates($request));
  26.     }
  27.     /**
  28.      * @Route("/b2b-calendar-dates", name="json_b2b_event_calendar_dates", methods={"GET"})
  29.      */
  30.     public function b2bCalendarDatesJson(Request $requestJsonDataService $jsonDataService): Response
  31.     {
  32.         $this->setEnvironmentTenant('b2b');
  33.         return $this->json($jsonDataService->getCalendarDates($request));
  34.     }
  35.     /**
  36.      * @Route("/list-dates", name="json_event_list_dates", methods={"GET"})
  37.      */
  38.     public function listDatesJson(Request $requestJsonDataService $jsonDataService): Response
  39.     {
  40.         return $this->json($jsonDataService->getListDatesJson(intval($request->get('activityId'))));
  41.     }
  42.     /**
  43.      * @Route("/b2b-list-dates", name="json_b2b_event_list_dates", methods={"GET"})
  44.      */
  45.     public function b2bListDatesJson(Request $requestJsonDataService $jsonDataService): Response
  46.     {
  47.         $this->setEnvironmentTenant('b2b');
  48.         return $this->json($jsonDataService->getListDatesJson(intval($request->get('activityId'))));
  49.     }
  50.     /**
  51.      * @Route("/time-list-dates", name="json_event_time_list_dates", methods={"GET"})
  52.      */
  53.     public function timeListDatesJson(Request $requestJsonDataService $jsonDataService): Response
  54.     {
  55.         return $this->json($jsonDataService->getTimeListDatesJson(intval($request->get('activityId')), $request->get('selectedDateEnd')));
  56.     }
  57.     /**
  58.      * @Route("/b2b-time-list-dates", name="json_b2b_event_time_list_dates", methods={"GET"})
  59.      */
  60.     public function b2bTimeListDatesJson(Request $requestJsonDataService $jsonDataService): Response
  61.     {
  62.         $this->setEnvironmentTenant('b2b');
  63.         return $this->json($jsonDataService->getTimeListDatesJson(intval($request->get('activityId')), $request->get('selectedDateEnd')));
  64.     }
  65.     /**
  66.      * @Route("/base_price", name="json_event_base_price", methods={"GET"})
  67.      */
  68.     public function basePriceJson(Request $requestTranslatorInterface $trans): Response
  69.     {
  70.         $json = [];
  71.         if ($product EventProduct::getById(intval($request->get('activityId')))) {
  72.             $selectedDate null;
  73.             if ($date $request->get('selectedDate')) {
  74.                 $selectedDate Carbon::createFromDate($date);
  75.             }
  76.             $priceInfo $product->getOSPriceInfo(1null$selectedDate);
  77.             /** @phpstan-ignore-next-line */
  78.             $price $priceInfo $priceInfo->getOriginalPriceInfo()->getBaseAmount() : 0;
  79.             $json = [
  80.                 'success' => true,
  81.                 'id' => (string)$request->get('activityId'),
  82.                 'basePriceInfo' => [
  83.                     'label' => $trans->trans('shop.configuration.adult-price'),
  84.                     'price' => $price,
  85.                 ],
  86.             ];
  87.         }
  88.         return $this->json($json);
  89.     }
  90. }