src/Controller/DeathInsurance/DeathInsuranceController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\DeathInsurance;
  3. use App\Controller\BaseController;
  4. use App\Entity\Customer\TrackerActivity;
  5. use App\Entity\DeathInsurance\IssueData;
  6. use App\Entity\Order\Order;
  7. use App\Manager\DeathInsurance\DeathInsuranceManager;
  8. use App\Manager\Partner\PartnerManager;
  9. use App\Service\CustomerService;
  10. use App\Service\DeathInsurance\AdminGridService;
  11. use App\Service\DeathInsurance\DeathInsuranceService;
  12. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. class DeathInsuranceController extends BaseController
  17. {
  18.     public function indexAction(Request $request)
  19.     {
  20.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  21.         $request->getSession()->remove('iframeSourceLink');
  22.         $trackerActivityService $this->getContainer()->get('app.service.customer.tracker_activity');
  23.         $trackerActivityService->startTracking($customerTrackerActivity::FROM_DIRECT_URLTrackerActivity::TYPE_DEATH_INSURANCE_ACTIVITY);
  24.         $render '@templates/DeathInsurance/death-insurance.html.twig';
  25.         return $this->render($render, [
  26.             'issueDataList' => $this->getEntityManager()->getRepository(IssueData::class)->findAllAsArray(),
  27.         ]);
  28.     }
  29.     /**
  30.      * @param Request $request
  31.      * @return Response
  32.      */
  33.     public function removeFromCart(Request $request): Response
  34.     {
  35.         $deathInsuranceService $this->getContainer()->get('app.service.death_insurance.death_insurance');
  36.         $result $deathInsuranceService->removeDeathInsuranceFromCartSessionByCnp($request->get('cnp'));
  37.         return new Response(json_encode(array('result' => $result)));
  38.     }
  39.     public function checkAlreadyActive(Request $request): Response
  40.     {
  41.         $deathInsuranceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  42.         return new Response(json_encode(array('isActive' => $deathInsuranceService->isAlreadyActiveForCnpAndValidFrom($request->request->all()))));
  43.     }
  44.     public function retrieveIssueData(Request $request): JsonResponse
  45.     {
  46.         /** @var AdminGridService $adminGridService */
  47.         $adminGridService $this->getContainer()->get('app.service.death_insurance_issue_data.admin_grid');
  48.         return new JsonResponse($adminGridService->retrieveDeathInsuranceIssueGridData());
  49.     }
  50.     public function submitData(Request $request) : Response
  51.     {
  52.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  53.         $deathInsuranceService $this->getContainer()->get('app.service.death_insurance.death_insurance');
  54.         $deathInsuranceTrackerActivityService $this->getContainer()->get('app.service.death_insurance.tracker_activity');
  55.         if (DeathInsuranceManager::isDeathInsuranceIframe($request)) {
  56.             $deathInsuranceService->removeDeathInsuranceFromCartSessionByCnp($request->get('cnp'));
  57.         }
  58.         $deathInsuranceResponse $deathInsuranceService->storeNewDeathInsuranceInCart();
  59.         $deathInsuranceTrackerActivityService->setDeathInsuranceSubmittedToCart($customer$deathInsuranceResponse);
  60.         return new Response(json_encode($deathInsuranceResponse));
  61.     }
  62.     /**
  63.      * @param Request $request
  64.      * @return Response
  65.      */
  66.     public function storePolicy(Request $request) : Response
  67.     {
  68.         $response = ['isStored' => false];
  69.         $localFilePath $this->getContainer()->getParameter('kernel.project_dir') . '/var/storage/nn_insurance/policy_production/';
  70.         $deathInsuranceService $this->getContainer()->get('app.service.death_insurance.death_insurance');
  71.         if (!is_dir($localFilePath)) {
  72.             // Third parameter 'true' makes the directory recursive, creating parent directories as needed
  73.             mkdir($localFilePath0777true);
  74.         }
  75.         $data json_decode($request->getContent(), true);
  76.         $urlPolicy $data['urlPolicy'];
  77.         $filename $data['fileName'];
  78.         if ($filename && $urlPolicy) {
  79.             $stored $deathInsuranceService->storeDeathInsurancePolicyOnServer($localFilePath$filename$urlPolicy);
  80.             $response = ['isStored' => $stored];
  81.         }
  82.         return new Response(json_encode($response));
  83.     }
  84.     public function showPolicyForPartner(Request $request): Response
  85.     {
  86.         $id $request->get('order_id');
  87.         $id base64_decode($id);
  88.         $order $this->getDoctrine()->getRepository(Order::class)->find($id);
  89.         if ($order->hasDeathInsurance()) {
  90.             $deathInsurance $order->getDeathInsurance();
  91.             foreach ($deathInsurance as $deathInsuranceItem) {
  92.                 if ($deathInsuranceItem && $deathInsuranceItem->getPolicyNumber()) {
  93.                     $fileName 'Polita de asigurare ' $deathInsuranceItem->getPolicyNumber() . '.pdf';
  94.                     $filePath $this->getContainer()->getParameter('kernel.project_dir') . '/var/storage/nn_insurance/_policy/' $fileName;
  95.                     if ($filePath && file_exists($filePath)) {
  96.                         header('Content-Type: application/pdf');
  97.                         $pdfContent file_get_contents($filePath);
  98.                         echo $pdfContent;
  99.                     } else {
  100.                         return new Response('File not found'404);
  101.                     }
  102.                 }
  103.             }
  104.         }
  105.         return new Response('error');
  106.     }
  107.     public function deathInsuranceIframe(Request $request): Response
  108.     {
  109.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  110.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_DEATH_INSURANCE_INDEX);
  111.         $token['partnerPublicToken'] = $request->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME);
  112.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_death_insurance_iframe'$token));
  113.         PartnerManager::checkQRCodeFlow($request);
  114.         return $this->render('@templates/DeathInsurance/iframe.html.twig', [
  115.             'issueDataList' => $this->getEntityManager()->getRepository(IssueData::class)->findAllAsArray(),
  116.             'publicToken' => $token['partnerPublicToken'] ?? null,
  117.         ]);
  118.     }
  119. }