src/DcSiteBundle/Controller/Subaru/ServiceController.php line 58

Open in your IDE?
  1. <?php
  2. namespace DcSiteBundle\Controller\Subaru;
  3. use CoreBundle\Component\CoreFormFactory;
  4. use CoreBundle\Component\FormManager;
  5. use CoreBundle\Component\Request\Curl;
  6. use CoreBundle\Entity\Forms;
  7. use CoreBundle\Entity\Model;
  8. use CoreBundle\Entity\ViDiDepartment;
  9. use CoreBundle\Factory\Vehicle as VehicleFactory;
  10. use CoreBundle\Model\Api\OnlineService\ApiServer1C;
  11. use CoreBundle\Model\Vehicles\Repository;
  12. use CoreBundle\Model\ViDiDepartmentModel;
  13. use CoreBundle\Services\MediaExtensionVidi;
  14. use DcSiteBundle\Model\Form\ServicesOrderForm;
  15. use DcSiteBundle\Services\VehicleService;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use PortalBundle\Model\SeoMetaTag;
  18. use Symfony\Component\Filesystem\Filesystem;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\RequestStack;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  24. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  25. use Symfony\Component\Routing\RouterInterface;
  26. use Twig\Environment;
  27. class ServiceController extends MainController
  28. {
  29.     const SUBARU_URL 'https://vin.subaru.ua/';
  30.     public function __construct(CoreFormFactory $coreFormFactorySeoMetaTag $seoMetaTagRequestStack $requestStackRouterInterface $routerFormManager $formManagerEntityManagerInterface $emApiServer1C $apiServer1CSessionInterface $sessionFilesystem $filesystemMediaExtensionVidi $mediaExtensionVidiRepository $vehicleRepositoryVehicleFactory $vehicleFactoryEnvironment $twig)
  31.     {
  32.         parent::__construct($coreFormFactory$seoMetaTag$requestStack$router$formManager$em$apiServer1C$session$filesystem$mediaExtensionVidi$vehicleRepository$vehicleFactory$twig);
  33.     }
  34.     public function accessories(): ?Response
  35.     {
  36.         return $this->baseSubaruRender('@DcSite/Subaru/Service/accessories.html.twig', ['buyPartsForm' => $this->CoreFormFactory()->buyPartsForm($this->getDealer())->createView()]);
  37.     }
  38.     public function assistance(): ?Response
  39.     {
  40.         return $this->baseSubaruRender('@DcSite/Subaru/Service/assistance.html.twig');
  41.     }
  42.     public function bodyRepair(): ?Response
  43.     {
  44.         $repairPhotoForm $this->CoreFormFactory()->repairPhotoForm();
  45.         return $this->baseSubaruRender('@DcSite/Subaru/Service/body-repair.html.twig', [
  46.             'repairPhotoForm' => $repairPhotoForm->createView(),
  47.         ]);
  48.     }
  49.     public function orderTo(): ?Response
  50.     {
  51.         $serviceForm $this->CoreFormFactory()->serviceForm();
  52.         return $this->baseSubaruRender('@DcSite/Subaru/Service/order-to.html.twig', [
  53.             'serviceForm' => $serviceForm->createView(),
  54.             'dealerName' => $this->getDealer()->getBrand()->getName()
  55.         ]);
  56.     }
  57.     public function regulationsTo(VehicleService $vehicleService): ?Response
  58.     {
  59.         $models $vehicleService->getModelsForRegulationsTo($this->getDealer());
  60.         return $this->baseSubaruRender('@DcSite/Subaru/Service/regulations-to.html.twig', [
  61.             'models' => $models,
  62.         ]);
  63.     }
  64.     public function regulationsToModel($model): ?Response
  65.     {
  66.         $model $this->em->getRepository(Model::class)->findOneBy(['url' => $model]);
  67.         if (!$model) {
  68.             throw new NotFoundHttpException();
  69.         }
  70.         return $this->baseSubaruRender('@DcSite/Subaru/Service/regulations-to-model.html.twig', [
  71.             'model' => $model->getId(),
  72.             'modelTitle' => $model->getTitle(),
  73.         ]);
  74.     }
  75.     public function spareParts(): ?Response
  76.     {
  77.         $quest = new Forms();
  78.         $department $this->em->getRepository(ViDiDepartment::class)->findOneBy(['dealer' => $this->getDealer(), 'type' => ViDiDepartmentModel::DEPARTMENT_TYPE_PARTS]);
  79.         $quest->setDepartment($department);
  80.         return $this->baseSubaruRender('@DcSite/Subaru/Service/spare-parts.html.twig', [
  81.             'questionsp' => $this->CoreFormFactory()->feedbackQuestionForm($quest$this->getDealer())->createView(),
  82.         ]);
  83.     }
  84.     public function tireHotel(Request $request): ?Response
  85.     {
  86.         return $this->baseSubaruRender('@DcSite/Subaru/Service/tires.html.twig', [
  87.             'serviceOrderForm' => $this->CoreFormFactory()->servicesOrderForm(ServicesOrderForm::TIRE_HOTEL$request->getLocale())->createView(),
  88.         ]);
  89.     }
  90.     public function serviceCompany(): ?Response
  91.     {
  92.         return $this->baseSubaruRender('@DcSite/Subaru/Service/service-company.html.twig');
  93.     }
  94.     public function checkVin(Request $requestCurl $curl): JsonResponse
  95.     {
  96.         $vin $request->request->get('vin');
  97.         $headers = [
  98.             'Content-Type: application/json; charset=UTF-8',
  99.         ];
  100.         $curl->init(self::SUBARU_URL '?vin=' $vin)
  101.             ->setOpt(CURLOPT_CUSTOMREQUEST"GET")
  102.             ->setOpt(CURLOPT_HTTPHEADER$headers)
  103.             ->setOpt(CURLOPT_RETURNTRANSFERtrue);
  104.         $result $curl->send();
  105.         $result json_decode(trim($this->removeBOM($result)), true);
  106.         if ($curl->getResultCode() === 400) {
  107.             return new JsonResponse(['status' => false'error_message' => $result['error_message']]);
  108.         }
  109.         $firstElement current($result);
  110.         $model $firstElement['model_name'] . ' ' $firstElement['model_year'];
  111.         return new JsonResponse(['success' => true'data' => $result'model' => $model]);
  112.     }
  113.     public function multiConsultationEnter(): ?Response
  114.     {
  115.         return $this->baseSubaruRender('@DcSite/Subaru/Service/consultation.html.twig');
  116.     }
  117.     public function multiConsultationForm(): ?Response
  118.     {
  119.         return $this->baseSubaruRender('@DcSite/Subaru/Service/consultation-form.html.twig');
  120.     }
  121.     public function multiConsultationFormOnline(): ?Response
  122.     {
  123.         return $this->baseSubaruRender('@DcSite/Subaru/Service/consultation-form-online.html.twig');
  124.     }
  125.     public function multiConsultationTestdriveForm(): ?Response
  126.     {
  127.         return $this->baseSubaruRender('@DcSite/Subaru/Service/consultation-testdrive-form.html.twig');
  128.     }
  129.     public function nightServiceAgreement(): ?Response
  130.     {
  131.         return $this->baseSubaruRender('@DcSite/Subaru/Service/night-service-agreement.html.twig', [
  132.             'dealer' => $this->getDealer()
  133.         ]);
  134.     }
  135. }