src/Controller/HomeController.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Faq;
  4. use App\Entity\Deals;
  5. use App\Entity\Features;
  6. use App\Entity\Subscribe;
  7. use App\Entity\Leads\Leads;
  8. use App\Entity\Leads\Configurator;
  9. use App\Entity\Leads\SoftwareVersion;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\String\ByteString;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. class HomeController extends AbstractController
  18. {
  19.     protected $em;
  20.     public function __construct(EntityManagerInterface $entityManager)
  21.     {
  22.         $this->em $entityManager;
  23.     }
  24.     /**
  25.      * @Route("/send/call", name="call")
  26.      */
  27.     public function call(Request $request): Response
  28.     {
  29.         $params= !empty($request->request->all()) ? $request->request->all() : null;
  30.         $result $this->em->getRepository(Leads::class)->setLead($params);
  31.         return new JsonResponse($result);
  32.     }
  33.     /**
  34.      * @Route("/send/configurator", name="configurator")
  35.      */
  36.     public function configurator(Request $request): Response
  37.     {
  38.         $name = !empty($request->get('name')) ? $request->get('name') : null;
  39.         $value = !empty($request->get('value')) ? $request->get('value') : null;
  40.         $params['form'][$name] = $value;
  41.         $params['type_lead'] = !empty($request->get('type')) ? $request->get('type') : 'unknow';
  42.         $params['hash'] = !empty($request->get('hash')) ? $request->get('hash') : null;
  43.         if(!empty($params['form'])){
  44.             $result $this->em->getRepository(Configurator::class)->saveStep($params);
  45.         }
  46.         if(!empty($request->get('complete'))){
  47.             $params $this->em->getRepository(Configurator::class)->findOneBy(["hash"=>$params['hash']]);
  48.             $list $this->em->getRepository(Subscribe::class)->findBy(["statut"=>1"default_sub"=>1]);
  49.             $features $this->em->getRepository(Features::class)->findBy(["statut"=>1]);
  50.         
  51.             $version = new SoftwareVersion($list$features);
  52.             $result $version->compareElements($params->getForm());
  53.             return $this->render('components/configurator-result.html.twig', [
  54.                 'result'         => $result[0]
  55.             ]);
  56.         }
  57.         return new JsonResponse($result);
  58.     }
  59.     
  60.     public function index(): Response
  61.     {
  62.         $faq $this->em->getRepository(Faq::class)->findBy(["statut"=>1], ["position"=>"ASC"]);
  63.         $deals $this->em->getRepository(Deals::class)->findBy(["statut"=> 1]);
  64.         return $this->render('home/index.html.twig', [
  65.             'deals'         => $deals,
  66.             'faq'           => $faq,
  67.             'hashSales'     => (new ByteString)->fromRandom(15)->toString()
  68.         ]);
  69.     }
  70. }