src/Controller/Front/HearingBrandController.php line 67

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: michael
  5.  * Date: 03/07/2019
  6.  * Time: 10:06
  7.  */
  8. namespace App\Controller\Front;
  9. use App\Controller\Front\LandingPage\AbstractProspectCreationController;
  10. use App\Entity\HearingBrand;
  11. use App\Entity\Prospect;
  12. use App\Form\FilterHearingBrandType;
  13. use App\Form\Model\FilterHearingBrandModel;
  14. use App\Form\ProspectType;
  15. use App\Repository\HearingBrandRepository;
  16. use App\Repository\StoreRepository;
  17. use App\Service\GmapsService;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Geocoder\Exception\Exception;
  20. use Knp\Component\Pager\PaginatorInterface;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. class HearingBrandController extends AbstractProspectCreationController
  25. {
  26.     /**
  27.      * @Route("/enseignes-auditives", name="hearing_brand_list")
  28.      * @param HearingBrandRepository $hearingBrandRepository
  29.      * @param PaginatorInterface $paginator
  30.      * @param Request $request
  31.      * @return Response
  32.      */
  33.     public function showAllHearingBrand(HearingBrandRepository $hearingBrandRepositoryPaginatorInterface $paginatorRequest $request): Response
  34.     {
  35.         $search = new FilterHearingBrandModel();
  36.         $form $this->createForm(FilterHearingBrandType::class, $search);
  37.         $form->handleRequest($request);
  38.         $pagination $paginator->paginate(
  39.             $hearingBrandRepository->getFilteredHearingBrand($search),
  40.             $request->query->getInt('page'1)
  41.         );
  42.         return $this->render('front_v4/mca/hearing_brand/list.html.twig', [
  43.             'pagination' => $pagination,
  44.             'form' => $form->createView()
  45.         ]);
  46.     }
  47.     /**
  48.      * @Route("/enseigne-auditive/{slug}", name="hearing_brand_show", methods={"GET", "POST"})
  49.      * @param Request $request
  50.      * @param HearingBrand $hearingBrand
  51.      * @param GmapsService $gmapsService
  52.      * @param StoreRepository $storeRepository
  53.      * @param EntityManagerInterface $em
  54.      * @return Response
  55.      * @throws Exception
  56.      */
  57.     public function indexHearingBrand(Request                $request,
  58.                                       HearingBrand           $hearingBrand,
  59.                                       GmapsService           $gmapsService,
  60.                                       StoreRepository        $storeRepository,
  61.                                       EntityManagerInterface $em
  62.     ): Response
  63.     {
  64.         if (!$request->get('slug')) {
  65.             throw $this->createNotFoundException();
  66.         }
  67.         // Autoscroll to lead_form
  68.         $scrollToLeadForm false;
  69.         $prospect = new Prospect();
  70.         $prospectForm $this->createForm(ProspectType::class, $prospect);
  71.         $prospectForm->handleRequest($request);
  72.         $nbOfCenter $hearingBrand->getStores()->count();
  73.         // Autoscroll to lead_form
  74.         if ($prospectForm->isSubmitted()) {
  75.             $scrollToLeadForm true;
  76.         }
  77.         if ($prospectForm->isSubmitted() && $prospectForm->isValid()) {
  78.             $result null;
  79.             $prospect $prospectForm->getData();
  80.             // Lead type = Demande de bilan
  81.             $prospect->setRequest('checkup');
  82.             // Récupérer la position de l'utilisateur en fonction de son code postal
  83.             $geocode $gmapsService->getLatitudeLongitudeFromAddress($prospect->getPostalcode());
  84.             // Recherche d'un store correspondant à la marque à proximité
  85.             // Critère de geociblage
  86.             if (!empty($geocode)) {
  87.                 $result $storeRepository->findStoreAroundLocationForHearingBrand($geocode[0], $geocode[1], -1$hearingBrand);
  88.             }
  89.             if ($result != null) {
  90.                 $store $result[0];
  91.                 //Create a prospect or redirect to a specific page if duplicate has been found
  92.                 $redirection $this->createProspectOrRedirect($prospect);
  93.                 //apply redirection if one is returned
  94.                 if (!is_null($redirection)) {
  95.                     return $redirection;
  96.                 }
  97.             }
  98.             $em->flush();
  99.             // Redirection page de confirmation
  100.             return $this->render('front_v4/mca/hearing_brand/single.html.twig', [
  101.                 'hearingBrand' => $hearingBrand,
  102.                 'nbOfCenter' => $nbOfCenter,
  103.                 'status' => 'send_success',
  104.                 'lead_number' => md5($prospect->getEmail()),
  105.                 'scroll_to_lead_form' => $scrollToLeadForm,
  106.             ]);
  107.         }
  108.         return $this->render('front_v4/mca/hearing_brand/single.html.twig', [
  109.             'hearingBrand' => $hearingBrand,
  110.             'nbOfCenter' => $nbOfCenter,
  111.             'prospectForm' => $prospectForm->createView(),
  112.             'scroll_to_lead_form' => $scrollToLeadForm,
  113.         ]);
  114.     }
  115. }