src/Controller/HuVignette/HuVignetteController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller\HuVignette;
  3. use App\Controller\BaseController;
  4. use App\Entity\Addressing\Country;
  5. use App\Manager\BitbagStatic\BlockManager;
  6. use App\Entity\HuVignette\Category;
  7. use App\Entity\HuVignette\Price;
  8. use App\Entity\System\ProductStatus;
  9. use App\Manager\Cart\CartManager;
  10. use App\Manager\CountryManager;
  11. use App\Manager\HuVignette\HuVignetteManager;
  12. use App\Manager\Partner\PartnerManager;
  13. use App\Model\ShopUserModel;
  14. use App\Service\HuVignetteService;
  15. use App\Service\StaticPagesBitbagService;
  16. use App\Validator\HuVignetteFormValidator;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. class HuVignetteController extends BaseController
  20. {
  21.     public function indexAction(Request $request)
  22.     {
  23.         $invalidCategory 'B2';
  24.         $render '@templates/Front/HuVignette/hu-vignette.html.twig';
  25.         if ($this->isMobile) {
  26.             $render '@templates/Mobile/HuVignette/hu-vignette.html.twig';
  27.         }
  28.         $request->getSession()->remove('iframeSourceLink');
  29.         return $this->render($render,
  30.             [
  31.                 'categories' => $this->getDoctrine()->getRepository(Category::class)->findAllCategoriesWithout($invalidCategory),
  32.                 'countries' => CountryManager::getActiveCountriesForHuVignette($this->getEntityManager()),
  33.                 'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getDoctrine()->getManager()),
  34.                 'accordionBlocksAboutHuVignette' => StaticPagesBitbagService::getAllFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_HU_VIGNETTE_CODE_PATTERN),
  35.                 'huVignetteKeywordsForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_HU_VIGNETTE_KEYWORD_CODE_PATTERN),
  36.                 'huVignetteDescriptionForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_HU_VIGNETTE_DESCRIPTION_CODE_PATTERN),
  37.                 'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY '-' date('Y'))
  38.             ]);
  39.     }
  40.     public function getAvailabilitiesByCategory(Request $request)
  41.     {
  42.         $id $request->get('id');
  43.         $availabilities null;
  44.         if ($id != null) {
  45.             $availabilities $this->getDoctrine()->getRepository(Price::class)->getAvailabilityForCategoryId($id);
  46.             $serializer $this->container->get('serializer');
  47.             $availabilities $serializer->serialize($availabilities'json');
  48.         }
  49.         return new Response($availabilities);
  50.     }
  51.     public function formSubmitAction(Request $request)
  52.     {
  53.         $session $request->getSession();
  54.         $validator = new HuVignetteFormValidator($this->getEntityManager(), $this->getSerializer());
  55.         $errors null;
  56.         if ($validator->checkForm($request)) {
  57.             $errors json_encode(array('success' => 1));
  58.         } else {
  59.             if ($session->has('huVignetteErrors')) {
  60.                 $errors $session->get('huVignetteErrors');
  61.             }
  62.         }
  63.         $session->set('previousUrl''hu-vignette');
  64.         return new Response($errors);
  65.     }
  66.     public function checkVignetteAtApi(Request $request)
  67.     {
  68.         $errors null;
  69.         $session $request->getSession();
  70.         $order CartManager::getCartData($session'huVignetteGlobalOrder');
  71.         $validRegistrationNumber true;
  72.         if ($order) {
  73.             $validRegistrationNumber HuVignetteService::checkHuVignetteValidation($order$request$this->getEntityManager());
  74.         }
  75.         if ($validRegistrationNumber) {
  76.             HuVignetteService::checkHuVignette($request);
  77.             if ($request->request->has('huVignetteSubmitForm')
  78.                 && $request->request->get('huVignetteSubmitForm') == 1) {
  79.                 $errors json_encode(array('success' => true));
  80.             } elseif ($request->request->has('specialErrors')) {
  81.                 $vignetteApiError = (array) $request->request->get('specialErrors');
  82.                 $apiStatusCode $request->request->get('apiStatusCode');
  83.                 $errors json_encode(array('vignetteApiError' => $vignetteApiError'apiStatusCode' => $apiStatusCode));
  84.             }
  85.         } else {
  86.             $vignetteApiError = array('alreadyInCart' => 'Already in cart');
  87.             $apiStatusCode 400;
  88.             $errors json_encode(array('vignetteApiError' => $vignetteApiError'apiStatusCode' => $apiStatusCode));
  89.         }
  90.         return new Response($errors);
  91.     }
  92.     public function removeHuVignetteFromCart(Request $request)
  93.     {
  94.         $selectedItem $request->get('guid');
  95.         $removeSmsAlert $request->get('smsAlert');
  96.         $huVignettes CartManager::getCartData($request->getSession(), 'huVignetteGlobalOrder');
  97.         $response 'success';
  98.         if ($huVignettes) {
  99.             foreach ($huVignettes as $key => $huVignette) {
  100.                 if ($selectedItem == $huVignette->guid) {
  101.                     if (isset($removeSmsAlert) && $removeSmsAlert == true) {
  102.                         if ($huVignette->vignette_alert == 1) {
  103.                             $huVignette->vignette_alert 0;
  104.                         } else {
  105.                             $response 'alertNotSet';
  106.                         }
  107.                     } else {
  108.                         unset($huVignettes[$key]);
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.         $huVignettes array_values($huVignettes);
  114.         CartManager::setToCart($request->getSession(), 'huVignetteGlobalOrder'$huVignettes);
  115.         return new Response(json_encode($response));
  116.     }
  117.     public function huVignetteIframe(Request $request)
  118.     {
  119.         $invalidCategory 'B2';
  120.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  121.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_HU_VIGNETTE_INDEX);
  122.         $token['partnerPublicToken'] = $request->getSession()->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME);
  123.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_ro_vignette_iframe'$token));
  124.         PartnerManager::checkQRCodeFlow($request);
  125.         $render '@templates/Front/HuVignette/iframe.html.twig';
  126.         if ($this->isMobile) {
  127.             $render '@templates/Mobile/HuVignette/iframe.html.twig';
  128.         }
  129.         return $this->render($render,
  130.             [
  131.                 'categories' => $this->getDoctrine()->getRepository(Category::class)->findAllCategoriesWithout($invalidCategory),
  132.                 'countries' => CountryManager::getActiveCountriesForHuVignette($this->getEntityManager()),
  133.                 'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getDoctrine()->getManager()),
  134.                 'accordionBlocksAboutHuVignette' => StaticPagesBitbagService::getAllFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_HU_VIGNETTE_CODE_PATTERN),
  135.                 'huVignetteKeywordsForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_HU_VIGNETTE_KEYWORD_CODE_PATTERN),
  136.                 'huVignetteDescriptionForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_HU_VIGNETTE_DESCRIPTION_CODE_PATTERN),
  137.                 'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY '-' date('Y')),
  138.                 'publicToken' => $request->get('partnerPublicToken')
  139.             ]);
  140.     }
  141. }