src/Mm/Beton/Planungsatlas/AtlasBundle/Controller/DefaultController.php line 83

Open in your IDE?
  1. <?php
  2. namespace Mm\Beton\Planungsatlas\AtlasBundle\Controller;
  3. use Knp\Bundle\SnappyBundle\KnpSnappyBundle;
  4. use Knp\Snappy\Pdf;
  5. use Mm\Beton\Planungsatlas\AtlasBundle\Entity\Main\DownloadFileModel;
  6. use Mm\Beton\Planungsatlas\AtlasBundle\Entity\Main\UserCart;
  7. use Mm\Beton\Planungsatlas\AtlasBundle\Repository\UserCartRepository;
  8. use Mm\Beton\Planungsatlas\AtlasBundle\Service\AtlasDaoDbImpl;
  9. use Mm\Beton\Planungsatlas\AtlasBundle\Service\AtlasDownloadService;
  10. use Mm\Beton\Planungsatlas\AtlasBundle\Service\HeatProtectionService;
  11. use Mm\Beton\Planungsatlas\AtlasBundle\Service\UserCartService;
  12. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  13. use Symfony\Component\HttpFoundation\Cookie;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  18. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  19. use Symfony\Component\HttpKernel\KernelInterface;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class DefaultController extends AbstractAuthenticatedController implements AuthenticatedControllerInterface
  22. {
  23.     private $atlasSession;
  24.     /**
  25.      * @var UserCartService
  26.      */
  27.     private $userCartService;
  28.     /**
  29.      * @var SessionInterface
  30.      */
  31.     private $session;
  32.     /**
  33.      * @var KnpSnappyBundle
  34.      */
  35.     private $knpSnappyPdf;
  36.     /**
  37.      * @var AtlasDownloadService
  38.      */
  39.     private $downloadService;
  40.     /**
  41.      * @var HeatProtectionService
  42.      */
  43.     private $heatProtectionService;
  44.     /**
  45.      * @var KernelInterface
  46.      */
  47.     private $kernel;
  48.     public function __construct(
  49.         UserCartService $userCartService,
  50.         SessionInterface $session,
  51.         Pdf $knpSnappyPdf,
  52.         AtlasDownloadService $downloadService,
  53.         HeatProtectionService $heatProtectionService,
  54.         KernelInterface $kernel
  55.     )
  56.     {
  57.         $this->atlasSession $this->loadAtlasSession();
  58.         $this->userCartService $userCartService;
  59.         $this->session $session;
  60.         $this->knpSnappyPdf $knpSnappyPdf;
  61.         $this->downloadService $downloadService;
  62.         $this->heatProtectionService $heatProtectionService;
  63.         $this->kernel $kernel;
  64.     }
  65.     /**
  66.      * @Route(
  67.      *   "/",
  68.      *   name="home"
  69.      * )
  70.      *
  71.      * @return Response
  72.      */
  73.     public function homeAction()
  74.     {
  75.         $data['loggedIn'] = $this->isUserLoggedIn();
  76.         $data['userData'] = $this->atlasSession->getUser();
  77.         return $this->heatProtectionAction(nullnullnull, new Request());
  78.     }
  79.     /**
  80.      * @Route(
  81.      *   "/parse-elements",
  82.      *   name="parseElements"
  83.      * )
  84.      *
  85.      * @return Response
  86.      */
  87.     public function parseElementsAction()
  88.     {
  89.         $data['loggedIn'] = $this->isUserLoggedIn();
  90.         $data['userData'] = $this->atlasSession->getUser();
  91.         return $this->render('index.html.twig'$data);
  92.     }
  93.     /**
  94.      * @Route(
  95.      *   "/logout",
  96.      *   name="logout"
  97.      * )
  98.      *
  99.      * @param Request $request
  100.      * @return Response
  101.      */
  102.     public function logoutAction(Request $request)
  103.     {
  104.         unset($_SESSION['userinfo']);
  105.         session_destroy();
  106.         return $this->redirectToRoute('home');
  107.     }
  108.     public function toAscii($str$replace = array(), $delimiter '-')
  109.     {
  110.         $clean str_replace(array('ä''ü''ö''ß''°'), array('ae''ue''oe''ss''-grad'), $str);
  111.         if (!empty($replace)) {
  112.             $clean str_replace((array)$replace' '$clean);
  113.         }
  114.         $clean iconv('UTF-8''ASCII//TRANSLIT'$clean);
  115.         $clean preg_replace("/[^a-zA-Z0-9\/_|+ -]/"''$clean);
  116.         $clean strtolower(trim($clean'-'));
  117.         $clean preg_replace("/[\/_|+ -]+/"$delimiter$clean);
  118.         return $clean;
  119.     }
  120.     public function toSearchKeyword($str$replace = array(), $delimiter '-')
  121.     {
  122.         if (!empty($replace)) {
  123.             $str str_replace((array)$replace' '$str);
  124.         }
  125.         $clean str_replace(array('ae''ue''oe''ss''-''grad'), array('ä''ü''ö''%%''%''%'), $str);
  126.         return $clean;
  127.     }
  128.     /**
  129.      * @Route(
  130.      *   "/waermeschutz/{constructionIdOrTypeName}/{constructionTypeIdOrTypeName}/{searchTermOrElementId}",
  131.      *   defaults={"constructionIdOrTypeName" = false, "constructionTypeIdOrTypeName" = false, "searchTermOrElementId" = false},
  132.      *   name="heatProtection"
  133.      * )
  134.      * @return Response
  135.      */
  136.     public function heatProtectionAction(
  137.         $constructionIdOrTypeName,
  138.         $constructionTypeIdOrTypeName,
  139.         $searchTermOrElementId,
  140.         Request $request
  141.     )
  142.     {
  143.         $this->getCartFromSession();
  144.         $search = array();
  145.         $searchTypes = array();
  146.         $constructionId false;
  147.         $constructionTypeId false;
  148.         if ($constructionIdOrTypeName) {
  149.             if (preg_match('/^\d\d-\d\d?-?\d?\d?-?\d?\d?$/'$constructionIdOrTypeName$constructionElementCode)) {
  150.                 $search[] = $constructionElementCode[0];
  151.             }
  152.             if (empty($search)) {
  153.                 preg_match('/\d+/'$constructionIdOrTypeName$constructionId);
  154.                 if (empty($constructionId)) {
  155.                     $constructionId false;
  156.                     $search[] = $this->toSearchKeyword($this->toAscii($constructionIdOrTypeName));
  157.                     $searchTypes['constructionIdOrTypeName'] = $constructionIdOrTypeName;
  158.                 } else {
  159.                     $constructionId = (int)$constructionId[0];
  160.                 }
  161.             }
  162.         }
  163.         if ($constructionTypeIdOrTypeName) {
  164.             preg_match('/\d+/'$constructionTypeIdOrTypeName$constructionTypeId);
  165.             if (empty($constructionTypeId)) {
  166.                 $searchTypes['constructionTypeIdOrTypeName'] = $constructionTypeIdOrTypeName;
  167.                 $constructionTypeId false;
  168.                 $search[] = $this->toSearchKeyword($this->toAscii($constructionTypeIdOrTypeName));
  169.             } else {
  170.                 $constructionTypeId = (int)$constructionTypeId[0];
  171.             }
  172.         }
  173.         if ($searchTermOrElementId) {
  174.             // show detail view if search term lools like link on detail page
  175.             if (preg_match('/^\d{1,3}-[a-z\-]{10,}/'$searchTermOrElementId$constructionElementId)) {
  176.                 $constructionElementId = (int)$constructionElementId[0];
  177.                 return $this->constructionsDetailAction($constructionElementId$request);
  178.             }
  179.             $search[] = $this->toSearchKeyword($this->toAscii($searchTermOrElementId));
  180.         }
  181.         $heatProtectionService $this->getHeatProtectionService();
  182.         $data $heatProtectionService->getHeatProtectionData($constructionTypeId$constructionId$search);
  183.         if (!empty($data['results'])) {
  184.             foreach ($data['results'] as $constructionName => $elements) {
  185.                 foreach ($elements as $elementId => $elementValues) {
  186.                     if ($constructionId) {
  187.                         $data['construction_link'] = $elementValues['construction_id'] . '-' $this->toAscii($elementValues['construction_name']);
  188.                         $data['construction_name'] = $constructionName;
  189.                     }
  190.                     if ($constructionTypeId and $constructionId) {
  191.                         $data['type_link'] = $data['construction_link'] . '/' $elementValues['type_id'] . '-' $this->toAscii($elementValues['type_name']);
  192.                         $data['type_name'] = $elementValues['type_name'];
  193.                     }
  194.                     $data['results'][$constructionName][$elementId]['link'] =
  195.                         $this->toAscii($elementValues['construction_name']) . '/'
  196.                         $this->toAscii($elementValues['type_name']) . '/'
  197.                         $elementId '-' $this->toAscii($elementValues['element_name']);
  198.                 }
  199.             }
  200.         }
  201.         if (!empty($searchTypes)) {
  202.             $data['origin_search'] = $searchTypes;
  203.         } else {
  204.             unset($data['type_names']);
  205.         }
  206.         $data['search'] = ((!empty($search) or $constructionId or $constructionTypeId) ? true false);
  207.         $data['loggedIn'] = $this->isUserLoggedIn();
  208.         $data['userData'] = $this->atlasSession->getUser();
  209.         $response $this->render('heatProtection.html.twig'$data);
  210.         if (!empty($data['element_string'])) {
  211.             $response->headers->setCookie(new Cookie('elements'$data['element_string']));
  212.         }
  213.         return $response;
  214.     }
  215.     private function getCartFromSession()
  216.     {
  217.         if ($this->isUserLoggedIn()) {
  218.             $this->userCartService->setSavedCartToSession($this->loadAtlasSession());
  219.         }
  220.     }
  221.     /**
  222.      * @Route(
  223.      *   "konstruktions-detail/{productId}",
  224.      *   name="constructionsDetail",
  225.      *   requirements={"productId" = ".+"},
  226.      * )
  227.      *
  228.      * @param $productId
  229.      * @return Response
  230.      */
  231.     public function constructionsDetailAction($productIdRequest $request)
  232.     {
  233.         preg_match('/\d+/'$productId$elementId);
  234.         $heatProtectionService $this->getHeatProtectionService();
  235.         $thermalData $heatProtectionService->getThermalDataByElement($productId);
  236.         $viewParameters $this->prepareFilterResponse($request);
  237.         $data $heatProtectionService->getConstructionsDetailData($productId);
  238.         if (isset($data['element'])) {
  239.             if (isset($data['element']['thermals'])) {
  240.                 foreach ($data['element']['thermals'] as $id => $thermal) {
  241.                     $digit null;
  242.                     if (preg_match('/\d$/'$thermal->getVariable(), $digit)) {
  243.                         $thermal->setVariable(preg_replace('/\d$/''<sub>' . (int)$digit[0] . '</sub>',
  244.                             $thermal->getVariable()));
  245.                     }
  246.                 }
  247.             }
  248.             $pagination $heatProtectionService->getElementPagination((int)$elementId[0],
  249.                 $request->cookies->get('elements'));
  250.             $pagination['previous_link'] =
  251.                 $this->toAscii($pagination['previous_construction_name']) . '/' .
  252.                 $this->toAscii($pagination['previous_type_name']) . '/' .
  253.                 $pagination['previous'] . '-' $this->toAscii($pagination['previous_name']);
  254.             $pagination['next_link'] =
  255.                 $this->toAscii($pagination['next_construction_name']) . '/' .
  256.                 $this->toAscii($pagination['next_type_name']) . '/' .
  257.                 $pagination['next'] . '-' $this->toAscii($pagination['next_name']);
  258.             $data array_merge($viewParameters$data);
  259.             $data array_merge($data$pagination);
  260.             $data['cart_elements'] = $this->atlasSession->getCartElements();
  261.             $data['thermalDataJson'] = $thermalData->getJson();
  262.             $data['availableTpcKeys'] = $thermalData->getTpcKeys();
  263.             $data['regulationComponents'] = $data['element']['element']->getRegulationComponents();
  264.             foreach ($data['regulationComponents'] as $index => $component) {
  265.                 $currentArrValue current($data['availableTpcKeys']);
  266.                 if(false === $currentArrValue){
  267.                     continue;
  268.                 }
  269.                 $data['regulationComponents'][$currentArrValue] = $component;
  270.                 unset($data['regulationComponents'][$index]);
  271.                 next($data['availableTpcKeys']);
  272.             }
  273.             $data['construction_link'] = $data['element']['construction_id'] . '-' $this->toAscii($data['element']['construction_name']);
  274.             $data['construction_name'] = $data['element']['construction_name'];
  275.             $data['type_link'] = $data['construction_link'] . '/' $data['element']['type_id'] . '-' $this->toAscii($data['element']['type_name']);
  276.             $data['type_name'] = $data['element']['type_name'];
  277.             $data['element_link'] = $this->toAscii($data['element']['construction_name']) . '/' .
  278.                 $this->toAscii($data['element']['type_name']) . '/' .
  279.                 $data['element']['element']->getId() . '-' $this->toAscii($data['element']['element']->getName());
  280.         }
  281.         $data['loggedIn'] = $this->isUserLoggedIn();
  282.         $data['userData'] = $this->atlasSession->getUser();
  283.         if (!isset($data['element'])) {
  284.             return $this->render('catchall.html.twig'$data);
  285.         } else {
  286.             return $this->render('constructionsDetail.html.twig'$data);
  287.         }
  288.     }
  289.     /**
  290.      * @Route(
  291.      *   "konstruktions-details-pdf-download/{productId}/{tpcKeyCode}",
  292.      *   name="constructionsDetailPdfDownload",
  293.      *   requirements={"productId" = ".+", "tpcKeyCode" = ".+"},
  294.      * )
  295.      *
  296.      * @param $productId
  297.      * @param $tpcKeyCode
  298.      * @return Response
  299.      */
  300.     public function constructionsDetailPdfDownloadAction(ParameterBagInterface $parameterBag$productId$tpcKeyCode)
  301.     {
  302.         $heatProtectionService $this->getHeatProtectionService();
  303.         $dataDirectory $this->getDataDirectory($parameterBag);
  304.         $thermalData $heatProtectionService->getThermalDataByElement($productId);
  305.         $data $heatProtectionService->getConstructionsDetailData($productId);
  306.         $thermalData->loadData($dataDirectory);
  307.         $data['tpcData'] = $thermalData->getTpc()[$tpcKeyCode] ?? null;
  308.         $data['selectedValues'] = explode('-'$tpcKeyCode);
  309.         $data['availableTpcKeys'] = $thermalData->getTpcKeys();
  310.         $data['regulationComponents'] = $data['element']['element']->getRegulationComponents();
  311.         foreach ($data['regulationComponents'] as $index => $component) {
  312.             $currentArrValue current($data['availableTpcKeys']);
  313.             if (false === $currentArrValue) {
  314.                 continue;
  315.             }
  316.             $data['regulationComponents'][$currentArrValue] = $component;
  317.             unset($data['regulationComponents'][$index]);
  318.             next($data['availableTpcKeys']);
  319.         }
  320.         $data['loggedIn'] = $this->isUserLoggedIn();
  321.         $data['userData'] = $this->atlasSession->getUser();
  322.         if ($data['element'] == null) {
  323.             return $this->render('catchall.html.twig');
  324.         } else {
  325.             $html $this->render('constructionsDetailPdf.html.twig'$data);
  326.             $this->session->save();
  327.             session_write_close();
  328.             return new Response(
  329.                 $this->knpSnappyPdf->getOutputFromHtml(
  330.                     $html->getContent(),
  331.                     array(
  332.                         'username' => $this->getParameter('atlas.authentication')['uname']
  333.                     ,
  334.                         'password' => $this->getParameter('atlas.authentication')['pass'],
  335.                     )
  336.                 ),
  337.                 200,
  338.                 array(
  339.                     'Content-Type' => 'application/pdf',
  340.                     'Content-Disposition' => 'attachment; filename="' $data['element']['element']->getCode() . '.pdf"',
  341.                 )
  342.             );
  343.         }
  344.     }
  345.     /**
  346.      * @Route(
  347.      *   "waermeberechnung-pdf-download",
  348.      *   name="heatProtectionPdfDownload",
  349.      * )
  350.      *
  351.      * @return Response
  352.      */
  353.     public function heatCalculationPdfDownloadAction(ParameterBagInterface $parameterBag)
  354.     {
  355.         $heatProtectionService $this->getHeatProtectionService();
  356.         $data['cart_elements'] = $this->atlasSession->getCartElements();
  357.         $data['cart_elements_sum'] = $this->atlasSession->getCartElementsSum();
  358.         $data['cart_ages'] = $this->atlasSession->getAges();
  359.         $data['cart_uwb'] = $this->atlasSession->getUwb();
  360.         $data['loggedIn'] = $this->isUserLoggedIn();
  361.         $data['userData'] = $this->atlasSession->getUser();
  362.         if ($data['cart_elements'] == null) {
  363.             return $this->render('catchall.html.twig'$data);
  364.         } else {
  365.             $html $this->render('heatCalculationPdf.html.twig'$data);
  366.             $this->session->save();
  367.             session_write_close();
  368.             $cdPdf '';
  369.             foreach ($data['cart_elements'] as $cartElement) {
  370.                 if ($cartElement->getConstructionElement()->getId() != null) {
  371.                     $idConstElement $cartElement->getConstructionElement()->getId();
  372.                 } else {
  373.                     $idConstElement "";
  374.                 }
  375.                 $thermalData $heatProtectionService->getThermalDataByElement($idConstElement);
  376.                 $data $heatProtectionService->getConstructionsDetailData($idConstElement);
  377.                 $data['tpcData'] = $idConstElement === "" '' : ($thermalData->getTpc()[$cartElement->getTpcKeyCode()] ?? "");
  378.                 $data['selectedValues'] = $idConstElement == "" '' explode('-'$cartElement->getTpcKeyCode());
  379.                 $htmlCd $this->render('constructionsDetailPdf.html.twig'$data);
  380.                 $cdPdf .= $htmlCd->getContent();
  381.             }
  382.             return new Response(
  383.                 $this->knpSnappyPdf->getOutputFromHtml(
  384.                     $html->getContent() . $cdPdf,
  385.                     [
  386.                         'username' => $this->getParameter('atlas.authentication')['uname'],
  387.                         'password' => $this->getParameter('atlas.authentication')['pass']
  388.                     ]
  389.                 ),
  390.                 200,
  391.                 array(
  392.                     'Content-Type' => 'application/pdf',
  393.                     'Content-Disposition' => 'attachment; filename="Wärmebrückenberechnung.pdf"',
  394.                 )
  395.             );
  396.         }
  397.     }
  398.     /**
  399.      * @Route(
  400.      *   "/waermeberechnung",
  401.      *   name="heatCalculation"
  402.      * )
  403.      *
  404.      * @return Response
  405.      */
  406.     public function heatCalculationAction()
  407.     {
  408.         $data['cart_elements'] = $this->atlasSession->getCartElements();
  409.         $data['cart_elements_sum'] = $this->atlasSession->getCartElementsSum();
  410.         $data['cart_ages'] = $this->atlasSession->getAges();
  411.         $data['cart_uwb'] = $this->atlasSession->getUwb();
  412.         $data['loggedIn'] = $this->isUserLoggedIn();
  413.         $data['userData'] = $this->atlasSession->getUser();
  414.         return $this->render('heatCalculation.html.twig'$data);
  415.     }
  416.     /**
  417.      * @Route(
  418.      *   "/oekobilanzierung",
  419.      *   name="ecobalancing"
  420.      * )
  421.      *
  422.      * @return Response
  423.      */
  424.     public function ecobalancingAction()
  425.     {
  426.         $data['loggedIn'] = $this->isUserLoggedIn();
  427.         $data['userData'] = $this->atlasSession->getUser();
  428.         return $this->render('ecobalancing.html.twig'$data);
  429.     }
  430.     /**
  431.      * @Route(
  432.      *   "/zertifizierung",
  433.      *   name="certification"
  434.      * )
  435.      *
  436.      * @return Response
  437.      */
  438.     public function certificationAction()
  439.     {
  440.         $data['loggedIn'] = $this->isUserLoggedIn();
  441.         $data['userData'] = $this->atlasSession->getUser();
  442.         return $this->render('certification.html.twig'$data);
  443.     }
  444.     /**
  445.      * @Route(
  446.      *   "/schallschutz",
  447.      *   name="noiseProtection"
  448.      * )
  449.      *
  450.      * @return Response
  451.      */
  452.     public function noiseProtectionAction()
  453.     {
  454.         $data['loggedIn'] = $this->isUserLoggedIn();
  455.         $data['userData'] = $this->atlasSession->getUser();
  456.         return $this->render('noiseProtection.html.twig'$data);
  457.     }
  458.     /**
  459.      * @Route(
  460.      *   "/info",
  461.      *   name="info"
  462.      * )
  463.      *
  464.      * @return Response
  465.      */
  466.     public function infoAction()
  467.     {
  468.         $data['loggedIn'] = $this->isUserLoggedIn();
  469.         $data['userData'] = $this->atlasSession->getUser();
  470.         return $this->render('info.html.twig'$data);
  471.     }
  472.     /**
  473.      * @Route(
  474.      *   "/impressum",
  475.      *   name="imprint"
  476.      * )
  477.      *
  478.      * @return Response
  479.      */
  480.     public function imprintAction()
  481.     {
  482.         $data['loggedIn'] = $this->isUserLoggedIn();
  483.         $data['userData'] = $this->atlasSession->getUser();
  484.         return $this->render('imprint.html.twig'$data);
  485.     }
  486.     /**
  487.      * @Route("/datenschutz", name="privacy")
  488.      *
  489.      * @return Response
  490.      */
  491.     public function privacyAction()
  492.     {
  493.         $data['loggedIn'] = $this->isUserLoggedIn();
  494.         $data['userData'] = $this->atlasSession->getUser();
  495.         return $this->render('privacy.html.twig'$data);
  496.     }
  497.     /**
  498.      * @Route(
  499.      *   "/download/{fileType}/{fileId}",
  500.      *   name="atlasDownload",
  501.      *   requirements={"fileType" = ".+", "fileId" = ".+"},
  502.      * )
  503.      *
  504.      * @param string $fileType
  505.      * @param int $fileId
  506.      * @return Response
  507.      */
  508.     public function downloadAction($fileType$fileId)
  509.     {
  510.         $downloadFile $this->downloadService->prepareDownloadFile($fileType$fileId$this->getParameter('kernel.project_dir'));
  511.         return $this->doDownload($downloadFile);
  512.     }
  513.     /**
  514.      * @Route(
  515.      *   "/ajax/{action}",
  516.      *   name="atlas_ajax",
  517.      *   requirements={"action" = ".+"},
  518.      * )
  519.      *
  520.      * @param $action
  521.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  522.      */
  523.     public function ajaxAction($action)
  524.     {
  525.         return $this->{$action 'AjaxAction'}();
  526.     }
  527.     public function addElementToCartAjaxAction()
  528.     {
  529.         $heatProtectionService $this->getHeatProtectionService();
  530.         $request = new Request();
  531.         $data $request->createFromGlobals()->get('atlas');
  532.         $elementId intval($data['elementId']);
  533.         $tpcKeyCode $data['tpcKeyCode'];
  534.         $psiValue $data['psiValue'];
  535.         $return $heatProtectionService->addElementToCart($elementId$tpcKeyCode$psiValue$this->atlasSession);
  536.         $response = array(
  537.             'state' => $return->state,
  538.             'msg' => $return->msg,
  539.         );
  540.         return new JsonResponse($response);
  541.     }
  542.     public function addEmptyElementToCartAjaxAction()
  543.     {
  544.         $heatProtectionService $this->getHeatProtectionService();
  545.         $request = new Request();
  546.         $data $request->createFromGlobals()->get('atlas');
  547.         $tpcKeyCode $data['tpcKeyCode'];
  548.         $psiValue $data['psiValue'];
  549.         $return $heatProtectionService->addEmpytElementToCart(null$tpcKeyCode$psiValue$this->loadAtlasSession());
  550.         $response = array(
  551.             'state' => $return->state,
  552.             'msg' => $return->msg,
  553.         );
  554.         return new JsonResponse($response);
  555.     }
  556.     public function removeElementFromCartAjaxAction()
  557.     {
  558.         $heatProtectionService $this->getHeatProtectionService();
  559.         $request = new Request();
  560.         $data $request->createFromGlobals()->get('atlas');
  561.         $elementId intval($data['elementId']);
  562.         $return $heatProtectionService->removeElementFromCart($elementId$this->atlasSession);
  563.         $response = array(
  564.             'state' => $return->state,
  565.             'msg' => $return->msg,
  566.         );
  567.         return new JsonResponse($response);
  568.     }
  569.     public function setElementLengthAjaxAction()
  570.     {
  571.         $heatProtectionService $this->getHeatProtectionService();
  572.         $request = new Request();
  573.         $data $request->createFromGlobals()->get('atlas');
  574.         $elementId intval($data['elementId']);
  575.         $elementLength $data['elementLength'];
  576.         $elementPsiValue $data['elementPsiValue'];
  577.         $return $heatProtectionService->setElementLengthById($elementId$elementLength$this->atlasSession$elementPsiValue);
  578.         $response = array(
  579.             'state' => $return->state,
  580.             'msg' => $return->msg,
  581.         );
  582.         return new JsonResponse($response);
  583.     }
  584.     public function setCartElementNameByIdAjaxAction()
  585.     {
  586.         $heatProtectionService $this->getHeatProtectionService();
  587.         $request = new Request();
  588.         $data $request->createFromGlobals()->get('atlas');
  589.         $cartElementId $data['cartElementId'];
  590.         $cartElementName $data['cartElementName'];
  591.         $return $heatProtectionService->setCartElementNameById($cartElementId$cartElementName$this->atlasSession);
  592.         $response = array(
  593.             'state' => $return->state,
  594.             'msg' => $return->msg,
  595.         );
  596.         return new JsonResponse($response);
  597.     }
  598.     public function setAgesAjaxAction()
  599.     {
  600.         $heatProtectionService $this->getHeatProtectionService();
  601.         $request = new Request();
  602.         $data $request->createFromGlobals()->get('atlas');
  603.         $aGes $data['aGes'];
  604.         $return $heatProtectionService->setAges($aGes$this->atlasSession);
  605.         $response = array(
  606.             'state' => $return->state,
  607.             'msg' => $return->msg,
  608.         );
  609.         return new JsonResponse($response);
  610.     }
  611.     /**
  612.      * @param DownloadFileModel $downloadFile
  613.      * @return Response
  614.      * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  615.      */
  616.     public function doDownload(DownloadFileModel $downloadFile)
  617.     {
  618.         if ($downloadFile->isValid() && $downloadFile->getContent() != null) {
  619.             $response = new Response();
  620.             $response->setStatusCode(200);
  621.             $response->headers->set('Cache-Control''private');
  622.             $response->headers->set('Content-type'$downloadFile->getFiletype());
  623.             $response->headers->set('Content-Disposition',
  624.                 'attachment; filename="' $downloadFile->getFilename() . '.' $downloadFile->getFileExt() . '";');
  625.             $response->headers->set('Content-length'filesize($downloadFile->getFilepath()));
  626.             $response->setContent($downloadFile->getContent());
  627.             return $response;
  628.         } else {
  629.             throw new NotFoundHttpException("File not found");
  630.         }
  631.     }
  632.     /**
  633.      * @param $request
  634.      * @return array
  635.      */
  636.     private function prepareFilterResponse($request)
  637.     {
  638.         $viewParameters = array();
  639.         $viewParameters['wbName'] = ($request->query->get("wbName") == '0' null $request->query->get("wbName"));
  640.         $wbId intval($request->query->get("wbId"));
  641.         $viewParameters['wbId'] = ($wbId == null $wbId);
  642.         $viewParameters['constructionTypeParam'] = ($viewParameters['wbName'] != null $viewParameters['wbName'] : $viewParameters['wbId']);
  643.         $selectedConstruction intval($request->query->get("konst"));
  644.         $viewParameters['konst'] = ($selectedConstruction == null $selectedConstruction);
  645.         $searchTerm $request->query->get("searchTerm");
  646.         $viewParameters['searchTerms'] = $this->clearUpSearchTerm($searchTerm);
  647.         $buildingType $request->query->get("buildingType");
  648.         $viewParameters['buildingType'] = ($buildingType == null 'select_wo_ge' $buildingType);
  649.         $buildingView $request->query->get("buildingView");
  650.         $viewParameters['buildingView'] = ($buildingView == null 'woge_front_svg' $buildingView);
  651.         return $viewParameters;
  652.     }
  653.     /**
  654.      * @param $searchTerm
  655.      * @return array
  656.      */
  657.     private function clearUpSearchTerm($searchTerm)
  658.     {
  659.         $searchTerms explode('|'$searchTerm);
  660.         foreach ($searchTerms as $key => $searchTerm) {
  661.             $searchTerms[$key] = trim($searchTerm);
  662.         }
  663.         return $searchTerms;
  664.     }
  665.     /**
  666.      * @Route(
  667.      *   "/{path}",
  668.      *   name="catchall",
  669.      *   requirements={"path" = ".+"}
  670.      * )
  671.      *
  672.      * @return Response
  673.      */
  674.     public function catchAllAction($path)
  675.     {
  676.         $data['loggedIn'] = $this->isUserLoggedIn();
  677.         $data['userData'] = $this->atlasSession->getUser();
  678.         return $this->render('catchall.html.twig'$data);
  679.     }
  680.     private function getDataDirectory(ParameterBagInterface $parameterBag)
  681.     {
  682.         return $parameterBag->get('thermal_data_dir');
  683.     }
  684.     private function getHeatProtectionService()
  685.     {
  686.         return $this->heatProtectionService;
  687.     }
  688.     public function saveUserCartAjaxAction()
  689.     {
  690.         $dao = new AtlasDaoDbImpl($this->getDoctrine()->getManager());
  691.         if ($this->isUserLoggedIn()) {
  692.             $userId $this->loadAtlasSession()->getUser()['uid'];
  693.             $aGes = ($this->loadAtlasSession()->getAges() == null) ? $this->loadAtlasSession()->getAges();
  694.             /** @var UserCartRepository $userCartRepo */
  695.             $userCartRepo $this->getDoctrine()->getRepository(UserCart::class);
  696.             /** @var UserCart $savedCart */
  697.             $savedCart $userCartRepo->findOneBy(array('userId' => $userId));
  698.             if (empty($savedCart)) {
  699.                 $savedCart = new UserCart();
  700.                 $savedCart->setUserId($userId);
  701.             }
  702.             $savedCart->clearCart();
  703.             $cartElements $this->loadAtlasSession()->getCartElements();
  704.             foreach ($cartElements as $cartElement) {
  705.                 $savedCart->addCartelement($cartElement);
  706.             }
  707.             $savedCart->setAGes($aGes);
  708.             $dao->saveModelTree($savedCart);
  709.         }
  710.         $response = array(
  711.             'state' => '0',
  712.             'msg' => 'ok',
  713.         );
  714.         return new JsonResponse($response);
  715.     }
  716. }