src/Controller/ConfigurateurController.php line 76

  1. <?php
  2. namespace App\Controller;
  3. use App\Services\DbMenu;
  4. use App\Services\DbPage;
  5. use App\Services\MailerHandler;
  6. use App\Controller\ConfigurateurController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. class ConfigurateurController extends AbstractController
  13. {
  14.     const SHORCODE_REGEX '/\[%\[([^<]*)\]%\]/';
  15.     public static function get_configurator_between($string)
  16.     {
  17.         preg_match_all(self::SHORCODE_REGEX$string$out);
  18.         return $out[1];
  19.     }
  20.     public static function parseCMSContent($content
  21.     {
  22.         $parsed ConfigurateurController::get_configurator_between($content);
  23.         foreach ($parsed as $key => $value) {
  24.             $valueArray explode('|',$value);
  25.             $content str_replace("[%[".$value."]%]"""$content);
  26.         }
  27.         return ["configurateurCode" => $valueArray[1], "content" => $content];
  28.     }
  29.     public function isAjaxCall($request)
  30.     {
  31.         return ($request->isXmlHttpRequest() && $request->isMethod('POST'));
  32.     }
  33.     public function getJsonContent($request)
  34.     {
  35.         return json_decode($request->getContent(), true);
  36.     }
  37.     public function prepareJsonResponse($data = array())
  38.     {
  39.         return array_merge(array('error' => false), $data);
  40.     }
  41.     public function mmToInche($inche$number) {
  42.         if ($inche) {
  43.             return $number 25.4;
  44.         } else {
  45.             return $number;
  46.         }
  47.     }
  48.     #[Route(
  49.         path: ['fr' => '/{_locale}/configurateurs-axes/{link}''en' => '/{_locale}/load-pins-configurator/{link}'], 
  50.         name'configurateur'
  51.         requirements: [
  52.             '_locale' => 'en|fr',
  53.         ],
  54.         priority2,
  55.     )]
  56.     #[Route(
  57.         path: ['fr' => '/{_locale}/configurateurs-tensiometres/{link}''en' => '/{_locale}/tensiometer-configurator/{link}'], 
  58.         name'configurateur_tensiometre'
  59.         requirements: [
  60.             '_locale' => 'en|fr',
  61.         ],
  62.         priority2,
  63.     )]
  64.     public function configurateur(Request $requestDbPage $dbPage$link null): Response
  65.     {
  66.         if ($request->getLocale() == 'fr') {
  67.             if ($request->attributes->get('_route') == 'configurateur_tensiometre') {
  68.                 $breadcrumb = array(['name' => 'Configurateurs tensiomètres''link_rewrite' => 'configurateurs-tensiometres']);
  69.             } else {
  70.                 $breadcrumb = array(['name' => 'Configurateurs axes''link_rewrite' => 'configurateurs-axes']);
  71.             }
  72.         } else {
  73.             if ($request->attributes->get('_route') == "configurateur_tensiometre") {
  74.                 $breadcrumb = array(['name' => 'Tensiometer-configurator''link_rewrite' => 'tensiometer-configurator']);
  75.             } else {
  76.                 $breadcrumb = array(['name' => 'Load-pins configurator''link_rewrite' => 'load-pins-configurator']);
  77.             }
  78.         }
  79.         $contents $dbPage->getContent($link$request->getLocale());
  80.         $link $dbPage->getLink($contents[0]['id_cms'], $request);
  81.         $configurateurCodeArray $this->parseCMSContent($contents[0]['content']);
  82.         $contents[0]['content'] = $configurateurCodeArray["content"];
  83.         $configurateurCode $configurateurCodeArray["configurateurCode"];
  84.         return $this->render('configurateur/configurateur.html.twig', ['contents' => $contents'link' => $link'configurateurCode' => $configurateurCode'breadcrumb' => $breadcrumb]);
  85.     }
  86.     #[Route(
  87.         path: ['fr' => '/{_locale}/configurateurs-axes''en' => '/{_locale}/load-pins-configurator'], 
  88.         name'configurateur_menu'
  89.         requirements: [
  90.             '_locale' => 'en|fr',
  91.         ],
  92.         priority1,
  93.     )]
  94.     #[Route(
  95.         path: ['fr' => '/{_locale}/configurateurs-tensiometres''en' => '/{_locale}/tensiometer-configurator'], 
  96.         name'configurateur_tensiometre_menu'
  97.         requirements: [
  98.             '_locale' => 'en|fr',
  99.         ],
  100.         priority1,
  101.     )]
  102.     public function configurateur_menu(Request $requestDbMenu $dbMenu): Response
  103.     {
  104.         if ($request->getLocale() == 'fr') {
  105.             if ($request->attributes->get('_route') == 'configurateur_tensiometre_menu') {
  106.                 $breadcrumb = array(['name' => 'Configurateurs tensiomètres''link_rewrite' => 'configurateurs-tensiometres']);
  107.                 $link '/en/tensiometer-configurator';
  108.             } else {
  109.                 $breadcrumb = array(['name' => 'Configurateurs axes''link_rewrite' => 'configurateurs-axes']);
  110.                 $link '/en/load-pins-configurator';
  111.             }
  112.         } else {
  113.             
  114.             
  115.             if ($request->attributes->get('_route') == "configurateur_tensiometre_menu") {
  116.                 $breadcrumb = array(['name' => 'Tensiometer-configurator''link_rewrite' => 'tensiometer-configurator']);
  117.                 $link '/fr/configurateurs-tensiometres';
  118.             } else {
  119.                 $breadcrumb = array(['name' => 'Load-pins configurator''link_rewrite' => 'load-pins-configurator']);
  120.                 $link '/fr/configurateurs-axes';
  121.             }
  122.         }
  123.         $parent $dbMenu->getContent($breadcrumb[0]["link_rewrite"], $request->getLocale());
  124.         $menus = array();
  125.         $menusCms $dbMenu->getMenusCms($parent[0]['id_cms_category'], $request->getLocale());
  126.         
  127.         return $this->render('apropos/aproposmenu.html.twig', ['link' => $link'breadcrumb' => $breadcrumb'menus' => $menus'menusCms' => $menusCms]);
  128.     }
  129.     #[Route(
  130.         path: ['fr' => '/configurateurs/mail''en' => '/configurator/mail'], 
  131.         name'configurateur_mail'
  132.         requirements: [
  133.             '_locale' => 'en|fr',
  134.         ],
  135.     )]
  136.     public function configurateur_mail(Request $requestMailerHandler $mailer): Response
  137.     {
  138.         if ($this->isAjaxCall($request)) {
  139.             $content $this->getJsonContent($request);
  140.             $societe $content["societe"];
  141.             $quantite $content["quantite"];
  142.             $pays $content["pays"];
  143.             $telephone $content["telephone"];
  144.             $remarque $content["remarque"];
  145.             $nom $content["nom"];
  146.             $unite $content["unite"];
  147.             $trougraisse $content["trougraisse"];
  148.             $dunit $content["dunit"];
  149.             $da $content["da"];
  150.             $di $content["di"];
  151.             $daa $content["daa"];
  152.             $dd $content["dd"];
  153.             $nominal $content["nominal"];
  154.             $nominalunit $content["nominalunit"];
  155.             $signal $content["signal"];
  156.             $bridge $content["bridge"];
  157.             $cable $content["cable"];
  158.             $cableunit $content["cableunit"];
  159.             $temperature $content["temperature"];
  160.             $temperaturevalue $content["temperaturevalue"];
  161.             $temperatureunit $content["temperatureunit"];
  162.             $environnement $content["environnement"];
  163.             $profondeur $content["profondeur"];
  164.             $temps $content["temps"];
  165.             $tempsunit $content["tempsunit"];
  166.             $application $content["application"];
  167.             $protection $content["protection"];
  168.             $securite $content["securite"];
  169.             $autre $content["autre"];
  170.             $remarquecarac $content["remarquecarac"];
  171.             $designg $content["designg"];
  172.             $designr $content["designr"];
  173.             $product $content["produit"];
  174.             
  175.             $capacite $content["capacite"];
  176.             $capaciteunit $content["capaciteunit"];
  177.             $diametres $content["diametres"];
  178.             $diametree $content["diametree"];
  179.             $diametreunite $content["diametreunite"];
  180.             $environnementt $content["environnementt"];
  181.             $type $content["type"];
  182.             $signalt $content["signalt"];
  183.             $securitet $content["securitet"];
  184.             $autret $content["autret"];
  185.             $mail $content["mail"];
  186.             $from "info@sensy.com";
  187.             $subject 'SENSY simulation, the '.date('d/m/Y');
  188.             $mailer->send([$mail], $from$subject'mail/configurateur/configurateurclient.html.twig');
  189.             $content '<strong>Model:</strong> ' $product '<br/><br/>';
  190.             if ($product == '5000' || $product == '5050') {
  191.                 $inche false;
  192.                 $unit '';
  193.                 if ($unite == 1) {
  194.                     $unit 'mm';
  195.                 } else {
  196.                     $unit 'inches';
  197.                     $inche true;
  198.                 }
  199.                 $greasing_hole '';
  200.                 if ($trougraisse == 1) {
  201.                     $greasing_hole 'No';
  202.                 } else {
  203.                     $greasing_hole 'Yes';
  204.                 }
  205.                 $D_unit '';
  206.                 if ($dunit == 1) {
  207.                     $D_unit 'h9';
  208.                 } else if ($dunit == 2) {
  209.                     $D_unit 'h8';
  210.                 } else if ($dunit == 3) {
  211.                     $D_unit 'h7';
  212.                 } else if ($dunit == 4) {
  213.                     $D_unit 'h6';
  214.                 }
  215.                 //Calcul pour Load pins général
  216.                 $palier01 $this->mmToInche($inche25);
  217.                 $palier02 $this->mmToInche($inche40);
  218.                 $palier03 $this->mmToInche($inche63);
  219.                 $palier04 $this->mmToInche($inche100);
  220.                 $palier05 $this->mmToInche($inche160);
  221.                 $H 0;
  222.                 $b 0;
  223.                 $data_D $dd;
  224.                 if ($data_D $palier01) {
  225.                     $H $this->mmToInche($inche10);
  226.                     $b $this->mmToInche($inche5);
  227.                 } else if ($data_D >= $palier01 && $data_D $palier02) {
  228.                     $H $this->mmToInche($inche12);
  229.                     $b $this->mmToInche($inche6);
  230.                 } else if ($data_D >= $palier02 && $data_D $palier03) {
  231.                     $H $this->mmToInche($inche16);
  232.                     $b $this->mmToInche($inche8);
  233.                 } else if ($data_D >= $palier03 && $data_D $palier04) {
  234.                     $H $this->mmToInche($inche20);
  235.                     $b $this->mmToInche($inche10);
  236.                 } else if ($data_D >= $palier04 && $data_D $palier05) {
  237.                     $H $this->mmToInche($inche25);
  238.                     $b $this->mmToInche($inche12);
  239.                 } else if ($data_D >= $palier05) {
  240.                     $H $this->mmToInche($inche32);
  241.                     $b $this->mmToInche($inche16);
  242.                 }
  243.                 $Long =  $da +  $di +  $daa $H $this->mmToInche($inche45);
  244.                 if ($Long <= $this->mmToInche($inche55)) {
  245.                     $Long 0;
  246.                 }
  247.                 $L =  $da +  $di +  $daa;
  248.                 //Arrondie les chiffre Ã  une décimal après la virgule
  249.                 $Long round($Long1);
  250.                 $L round($L1);
  251.                 $H round($H1);
  252.                 $b round($b1);
  253.                 //End Calcul pour Load pins général
  254.                 $content .= '
  255.                     <strong><u>General:</u></strong><br/><br/>
  256.                     <strong>Unit: </strong>' $unit '<br/>';
  257.                 $content .= $product != '5050' '<strong>Greasing hole: </strong>' $greasing_hole '<br/>' '';
  258.                 $content .= '<strong>A: </strong>' $da '<br/>
  259.                     <strong>I: </strong>' $di '<br/>
  260.                     <strong>A/A\': </strong>' $daa '<br/>
  261.                     <strong>D: </strong>' $dd' ' $D_unit '<br/>
  262.                     <strong>Long: </strong>' $Long '<br/>
  263.                     <strong>L: </strong>' $L '<br/>
  264.                     <strong>H: </strong>' $H '<br/>
  265.                     <strong>b: </strong>' $b '<br/><br/>';
  266.                 //END General section
  267.             
  268.                 //Specification section
  269.                 $nominal_capacity_unit '';
  270.                 if ($nominalunit == 1) {
  271.                     $nominal_capacity_unit 't';
  272.                 } else if ($nominalunit == 2) {
  273.                     $nominal_capacity_unit 'kN';
  274.                 } else if ($nominalunit == 3) {
  275.                     $nominal_capacity_unit 'klbs';
  276.                 }
  277.             
  278.                 $output_signal '';
  279.                 if ($signal == 1) {
  280.                     $output_signal 'mV/V';
  281.                 } else if ($signal == 2) {
  282.                     $output_signal '4-20mA';
  283.                 } else if ($signal == 3) {
  284.                     $output_signal '0-10V (force)';
  285.                 } else if ($signal == 4) {
  286.                     $output_signal '1-10V';
  287.                 } else if ($signal == 5) {
  288.                     $output_signal '1-5V';
  289.                 } else if ($signal == 6) {
  290.                     $output_signal 'RS232';
  291.                 } else if ($signal == 7) {
  292.                     $output_signal 'RS485';
  293.                 } else if ($signal == 8) {
  294.                     $output_signal 'Wireless';
  295.                 } else if ($signal == 9) {
  296.                     $output_signal 'Other';
  297.                 }
  298.             
  299.             
  300.                 $dual_bridge '';
  301.                 if ($bridge == 1) {
  302.                     $dual_bridge 'No';
  303.                 } else if ($bridge == 2) {
  304.                     $dual_bridge 'Yes';
  305.                 }
  306.             
  307.                 $cable_length_unit '';
  308.                 if ($cableunit == 1) {
  309.                     $cable_length_unit 'm';
  310.                 } else if ($cableunit == 2) {
  311.                     $cable_length_unit 'ft';
  312.                 }
  313.             
  314.                 $temperature '';
  315.                 if ($temperature == 1) {
  316.                     $temperature 'Standard';
  317.                 } else if ($temperature == 2) {
  318.                     $temperature 'Other -> ';
  319.                     $temperature .= $temperaturevalue;
  320.                     if ($temperatureunit == 1) {
  321.                         $temperature .= ' Â°C';
  322.                     } else if ($temperatureunit == 2) {
  323.                         $temperature .= ' Â°F';
  324.                     }
  325.                 }
  326.                 $env '';
  327.                 if ($environnement == 1) {
  328.                     $env 'Normal';
  329.                 } else if ($environnement == 2) {
  330.                     $env 'Marine';
  331.                 } else if ($environnement == 3) {
  332.                     $env 'Subsea <br/>';
  333.             
  334.                     $env .= '   -> Immersion depth (m): ' $profondeur '<br/>';
  335.                     $env .= '   -> Immersion time: ' $temps ' ' $tempsunit '<br/>';
  336.                 } else if ($environnement == 4) {
  337.                     $env 'Corrosive';
  338.                 }
  339.                 $application_type '';
  340.                 if ($application == 1) {
  341.                     $application_type 'Hoisting (CE certified)';
  342.                 } else if ($application == 2) {
  343.                     $application_type 'Force, static';
  344.                 } else if ($application == 3) {
  345.                     $application_type 'Force, dynamic';
  346.                 }
  347.                 $protection_level '';
  348.                 if ($protection == 1) {
  349.                     $protection_level 'IP65';
  350.                 } else if ($protection == 2) {
  351.                     $protection_level 'IP66';
  352.                 } else if ($protection == 3) {
  353.                     $protection_level 'IP67';
  354.                 } else if ($protection == 4) {
  355.                     $protection_level 'IP68';
  356.                 } else if ($protection == 5) {
  357.                     $protection_level 'Other';
  358.                 }
  359.             
  360.             
  361.                 $intrinsically_safe '';
  362.                 if ($securite == 1) {
  363.                     $intrinsically_safe 'Not applicable';
  364.                 } else if ($securite == 2) {
  365.                     $intrinsically_safe 'ATEX';
  366.                 } else if ($securite == 3) {
  367.                     $intrinsically_safe 'IECEx / ATEX';
  368.                 } else if ($securite == 4) {
  369.                     $intrinsically_safe 'CSA (US / Canada)';
  370.                 } else if ($securite == 5) {
  371.                     $intrinsically_safe 'Triple certification';
  372.                 }
  373.             
  374.                 $other '';
  375.                 if ($autre == 1) {
  376.                     $other 'No';
  377.                 } else if ($autre == 2) {
  378.                     $other 'Biaxial load pin, directions X and Y';
  379.                 } else if ($autre == 3) {
  380.                     $other 'Special Design';
  381.                 } else if ($autre == 4) {
  382.                     $other 'Special environment';
  383.                 } else if ($autre == 5) {
  384.                     $other 'Special connector and/or cable';
  385.                 }
  386.                 $content .= '
  387.                     <strong><u>Specifications:</u></strong><br/><br/>
  388.                     <strong>Nominal capacity: </strong>' $nominal ' ' $nominal_capacity_unit '<br/>
  389.                     <strong>Output signal: </strong>' $output_signal '<br/>
  390.                     <strong>Dual bridge circuit: </strong>' $dual_bridge '<br/>
  391.                     <strong>Cable length: </strong>' $cableunit ' ' $cable_length_unit '<br/>
  392.                     <strong>Service temperature range: </strong>' $temperature '<br/>
  393.                     <strong>Environment: </strong>' $env '<br/>
  394.                     <strong>Type of application: </strong>' $application_type '<br/>
  395.                     <strong>Protection level: </strong>' $protection_level '<br/>
  396.                     <strong>Intrinsically Safe: </strong>' $intrinsically_safe '<br/>
  397.                     <strong>Other: </strong>' $other '<br/>
  398.                     <strong>Remarks: </strong>' $remarquecarac '<br/><br/>
  399.                 ';
  400.                 //END Specification section
  401.             
  402.                 // Available designs
  403.                 $content .= '
  404.                     <strong><u>Available designs:</u></strong><br/><br/>
  405.                     <strong>Design start: </strong>' $designg '<br/>
  406.                     <strong>Design end: </strong>' $designr '<br/><br/>';
  407.                 // END Available designs
  408.             } else if ($product == '5560S' || $product == '5570-5575' || $product == '5580-5585') {
  409.                 $capacity_unit '';
  410.                 if ($capacite == 1) {
  411.                     $capacity_unit 't';
  412.                 } else if ($capacite == 2) {
  413.                     $capacity_unit 'kN';
  414.                 } else if ($capacite == 3) {
  415.                     $capacity_unit 'klbs';
  416.                 }
  417.             
  418.                 $rope_diameter_unit '';
  419.                 if ($diametreunite == 1) {
  420.                     $rope_diameter_unit 'mm';
  421.                 } else if ($diametreunite == 2) {
  422.                     $rope_diameter_unit 'inches';
  423.                 }
  424.             
  425.                 $env '';
  426.                 if ($environnementt == 1) {
  427.                     $env 'Standard (IP 65)';
  428.                 } else if ($environnementt == 2) {
  429.                     $env 'Marine';
  430.                 } else if ($environnementt == 3) {
  431.                     $env 'Subsea';
  432.                 }
  433.             
  434.                 $rope_type '';
  435.                 if ($type == 1) {
  436.                     $rope_type 'Steel';
  437.                 } else if ($type == 2) {
  438.                     $rope_type 'Synthetic';
  439.                 } else if ($type == 3) {
  440.                     $rope_type 'Carbon';
  441.                 }
  442.                 $output_signal '';
  443.                 if ($signalt == 1) {
  444.                     $output_signal 'mV/V';
  445.                 } else if ($signalt == 2) {
  446.                     $output_signal '0-10V';
  447.                 } else if ($signalt == 3) {
  448.                     $output_signal '4-20mA';
  449.                 } else if ($signalt == 4) {
  450.                     $output_signal 'RS485-ASCII';
  451.                 }
  452.             
  453.                 $safe '';
  454.                 if ($securitet == 1) {
  455.                     $safe 'Not applicable';
  456.                 } else if ($securitet == 2) {
  457.                     $safe 'ATEX';
  458.                 } else if ($securitet == 3) {
  459.                     $safe 'IECEx / ATEX';
  460.                 } else if ($securitet == 4) {
  461.                     $safe 'CSA (US / Canada)';
  462.                 } else if ($securitet == 5) {
  463.                     $safe 'Triple certification';
  464.                 }
  465.                 $content .= '
  466.                     <strong><u>General:</u></strong><br/><br/>
  467.                     <strong>Capacity: </strong>' $capacite ' ' $capacity_unit '<br/>
  468.                     <strong>Rope/line diameter(s): </strong>' $diametres ' to ' $diametree ' ' $rope_diameter_unit '<br/>
  469.                     <strong>Environment: </strong>' $env '<br/>
  470.                     <strong>Type of rope/line: </strong>' $rope_type '<br/>
  471.                     <strong>Output signal: </strong>' $output_signal '<br/>
  472.                     <strong>Intrinsically Safe: </strong>' $safe '<br/>
  473.                     <strong>Other: </strong>' $autret '<br/><br/> ';
  474.             }
  475.             $content .= '
  476.                 <strong><u>Personal infos:</u></strong><br/><br/>
  477.                 <strong>Company: </strong>' $societe '<br/>
  478.                 <strong>Name: </strong>' $nom '<br/>
  479.                 <strong>Email: </strong>' $mail '<br/>
  480.                 <strong>Quantity: </strong>' $quantite '<br/>
  481.                 <strong>Country: </strong>' $pays '<br/>
  482.                 <strong>Phone: </strong>' $telephone '<br/>
  483.                 <strong>Remark(s): </strong>' $remarque '<br/><br/> ';
  484.             // $mail = ["jm@adevo.be"];
  485.             $to = ["jm@adevo.be""jeremymortier@hotmail.com"];
  486.             // // $mail = ["fg@sensy.com", "cornil@sensy.com", "amo@sensy.com", "web@sensy.com", "giansante.fab@gmail.com"];
  487.             $from "noreply@sensy.com";
  488.             $subject 'Nouvelle demande par internet pour le modèle ' $product ', le ' date('d/m/Y');
  489.             $mailer->send($to$from$subject'mail/configurateur/configurateur.html.twig', ['content' =>  $content]);
  490.         }
  491.         return new JsonResponse();
  492.     }
  493. }
  494. ?>