src/Controller/System/ShopDashboardController.php line 92

Open in your IDE?
  1. <?php
  2. namespace App\Controller\System;
  3. use App\Controller\BaseController;
  4. use App\Entity\Addressing\Country;
  5. use App\Entity\Addressing\County;
  6. use App\Manager\BitbagStatic\BlockManager;
  7. use App\Entity\Customer\Customer;
  8. use App\Entity\RCA\Availability;
  9. use App\Entity\RCA\FuelType;
  10. use App\Entity\RCA\InsuranceCompany;
  11. use App\Entity\RCA\LeasingCompany;
  12. use App\Entity\RCA\MappedCategory;
  13. use App\Entity\RCA\MappedVehicleMake;
  14. use App\Entity\RCA\UsageType;
  15. use App\Entity\RCA\VehicleType;
  16. use App\Manager\CountryManager;
  17. use App\Manager\Customer\ConfirmationCommercialNotificationManager;
  18. use App\Manager\Rca\RcaManager;
  19. use App\Manager\RoadAssistance\RoadAssistanceManager;
  20. use App\Manager\Customer\VehicleManager;
  21. use App\Manager\HuVignette\HuVignetteManager;
  22. use App\Model\CustomerModel;
  23. use App\Model\ShopUserModel;
  24. use App\Model\VignetteCategoryModel;
  25. use App\Service\CustomerService;
  26. use App\Service\StaticPagesBitbagService;
  27. use App\Service\SystemService;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Contracts\Translation\TranslatorInterface;
  31. use App\Entity\Vignette\Category as RoVignetteCategory;
  32. use App\Entity\HuVignette\Category as HuVignetteCategory;
  33. class ShopDashboardController extends BaseController
  34. {
  35.     public function homepageAction(Request $requestTranslatorInterface $translator): Response
  36.     {
  37.         $desktopView SystemService::checkDesktopView($request);
  38.         $vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
  39.         $render '@templates/Front/homepage.html.twig';
  40.         if ($this->isMobile && !$desktopView) {
  41.             $render '@templates/Mobile/homepage.html.twig';
  42.         }
  43.         if (CustomerService::retrieveCustomerFromShopUser($this->getUser())) {
  44.             $render '@templates/Account/vehicle/list.html.twig';
  45.             $leasingCompanies $this->getDoctrine()
  46.                 ->getRepository(LeasingCompany::class)->findAll();
  47.             $country $this->getDoctrine()->getRepository(Country::class)->findOneBy(array('code' => 'RO'));
  48.             $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  49.             $hashGeneratorService $this->getContainer()->get('app.service.security.hash_generator');
  50.             return $this->render($render,
  51.                 [
  52.                     'vignetteCategories' => $vignetteCategories,
  53.                     'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY '-' date('Y')),
  54.                     'customerVehicleOrderByOptions' => VehicleManager::getCustomerVehicleOrderByOptions(),
  55.                     'customerVehicleSearchByFields' => VehicleManager::getCustomerVehicleSearchByFields(),
  56.                     'countyList' => $this->getDoctrine()->getRepository(County::class)->findAllCountiesByCountryAsArray($country),
  57.                     'vehicleTypeList' => $this->getDoctrine()->getRepository(VehicleType::class)->findAllAsArrayForUI(),
  58.                     'rcaMappedCategoryList' => $this->getDoctrine()->getRepository(MappedCategory::class)->findAllAsArray(),
  59.                     'defaultMakeList' => $this->getDoctrine()->getRepository(MappedVehicleMake::class)->findByVehicleMappedCategoryAsArray(MappedCategory::MAPPED_CATEGORY_VEHICLE),
  60.                     'availabilityList' => $this->getDoctrine()->getRepository(Availability::class)->findAllAsArray(),
  61.                     'availabilityIntervalList' => RcaManager::getAvailabilityIntervalList(),
  62.                     'insuranceCompanyList' => $this->getDoctrine()->getRepository(InsuranceCompany::class)->findAllOnlyNameOrderedByPositionAsArray(),
  63.                     'fuelTypeList' => $this->getDoctrine()->getRepository(FuelType::class)->findAllAsArray(),
  64.                     'usageTypeList' => $this->getDoctrine()->getRepository(UsageType::class)->findAllAsArray(),
  65.                     'leasingCompanyList' => $this->getDoctrine()->getRepository(LeasingCompany::class)->findAllAsArray(),
  66.                     'leasingCompanies' => $leasingCompanies,
  67.                     'step' => $request->get('step'),
  68.                     'haveOldVehicleValues' => (bool)$request->getSession()->get('rcaVehicle'),
  69.                     'haveOldCustomerValues' => (bool)$request->getSession()->get('rcaCustomerData'),
  70.                     'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getEntityManager()),
  71.                     'accordionBlocksAboutRca' => StaticPagesBitbagService::getAllFilteredBlocksAsArray($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_RCA_CODE_PATTERN),
  72.                     'roadAssistanceDefaultPrice' => $roadAssistanceService->retrieveDefaultPrice(),
  73.                     'roadAssistanceTranslations' => RoadAssistanceManager::getTranslationsForUI($translator),
  74.                     'hash' => $hashGeneratorService->getHash(),
  75.                     'countries' => CountryManager::getActiveCountriesForRoVignette($this->getEntityManager()),
  76.                     'roVignetteCategories' => $this->getDoctrine()->getRepository(RoVignetteCategory::class)->findAllAsArray(),
  77.                     'huVignetteCategories' => $this->getDoctrine()->getRepository(HuVignetteCategory::class)->findAllAsArray(),
  78.                 ]);
  79.         }
  80.         return $this->render($render,
  81.             [
  82.                 'vignetteCategories' => $vignetteCategories,
  83.             ]);
  84.     }
  85.     public function oldHomepageAction(Request $request)
  86.     {
  87.         $desktopView SystemService::checkDesktopView($request);
  88.         $render '@templates/Front/homepage.html.twig';
  89.         if ($this->isMobile && !$desktopView) {
  90.             $render '@templates/Mobile/homepage.html.twig';
  91.         }
  92.         $vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
  93.         return $this->render($render,
  94.             [
  95.                 'vignetteCategories' => $vignetteCategories,
  96.             ]);
  97.     }
  98.     public function subscribeToNewsletter(Request $requestTranslatorInterface $translator)
  99.     {
  100.         $redirectToRoute 'sylius_shop_homepage';
  101.         $customer $this->getEntityManager()->getRepository(Customer::class)->findOneBy(array('email' => $request->get('email')));
  102.         if ($customer instanceof Customer) {
  103.             $customerModel = new CustomerModel($this->getEntityManager());
  104.             $customerModel->subscribeCustomerToNewsletter($customer$request->getClientIp());
  105.             $commercialNotificationService $this->getContainer()->get('app.service.customer.commercial_notification');
  106.             $commercialNotificationService->addToQueueConfirmationEmailForCommercialNotificationForCustomer($customerConfirmationCommercialNotificationManager::EMAIL_TYPE_MANUAL_ID);
  107.             $this->addFlash('success'SystemService::retrieveMessage('success'$translator));
  108.         } else {
  109.             $this->addFlash('warning'SystemService::retrieveMessage('could_not_find_a_user_with_this_email_register'$translator));
  110.             $redirectToRoute 'app_shop_customer_register';
  111.         }
  112.         return $this->redirectToRoute($redirectToRoute);
  113.     }
  114. }