src/Controller/Front/ProductController.php line 401

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Avis;
  4. use App\Entity\Pack;
  5. use App\Entity\User;
  6. use App\Entity\Ticket;
  7. use App\Form\AvisType;
  8. use App\Services\File;
  9. use App\Services\Mail;
  10. use App\Entity\Chambre;
  11. use App\Entity\Company;
  12. use App\Entity\Product;
  13. use App\Entity\Category;
  14. use App\Entity\Security;
  15. use App\Services\Filter;
  16. use App\Entity\Equipment;
  17. use App\Entity\Messaging;
  18. use App\Entity\LangueHote;
  19. use App\Entity\LitsChambre;
  20. use App\Entity\SalleDeBain;
  21. use App\Entity\SubCategory;
  22. use App\Entity\ActivityType;
  23. use App\Entity\ImageComment;
  24. use App\Entity\Caracteristic;
  25. use App\Entity\ProductOption;
  26. use App\Entity\ContactProduct;
  27. use App\Entity\PlanningCompany;
  28. use App\Entity\TypeHebergement;
  29. use App\Entity\TypeParticipant;
  30. use App\Form\TicketProductType;
  31. use App\Entity\TypeLocalisation;
  32. use App\Form\ContactProductType;
  33. use App\Traits\FilterPriceTrait;
  34. use App\Entity\MobilierExterieur;
  35. use Symfony\Component\Mime\Email;
  36. use App\Entity\EquipementsCuisine;
  37. use App\Repository\AvisRepository;
  38. use App\Entity\AccessoiresDeChambre;
  39. use App\Repository\TicketRepository;
  40. use App\Repository\CompanyRepository;
  41. use App\Repository\ProductRepository;
  42. use App\Repository\CategoryRepository;
  43. use App\Repository\LocationRepository;
  44. use App\Repository\SecurityRepository;
  45. use App\Repository\WishListRepository;
  46. use App\Entity\TransporteurWeightPrice;
  47. use App\Repository\EquipmentRepository;
  48. use App\Repository\AdminPromoRepository;
  49. use App\Repository\DepartmentRepository;
  50. use App\Repository\LangueHoteRepository;
  51. use Doctrine\ORM\EntityManagerInterface;
  52. use App\Repository\ReservationRepository;
  53. use App\Repository\SubCategoryRepository;
  54. use App\Repository\CaracteristicRepository;
  55. use App\Repository\ProductOptionRepository;
  56. use Knp\Component\Pager\PaginatorInterface;
  57. use App\Repository\TypePrestationRepository;
  58. use App\Repository\PlanningCompanyRepository;
  59. use App\Repository\TypeHebergementRepository;
  60. use Symfony\Component\HttpFoundation\Request;
  61. use Symfony\Component\Mailer\MailerInterface;
  62. use App\Repository\TypeLocalisationRepository;
  63. use Symfony\Component\HttpFoundation\Response;
  64. use App\Repository\OptionHebergementRepository;
  65. use Symfony\Component\Routing\Annotation\Route;
  66. use Symfony\Component\HttpFoundation\JsonResponse;
  67. use App\Repository\CaracteristiqueVehiculeRepository;
  68. use App\Repository\TransporteurWeightPriceRepository;
  69. use Symfony\Contracts\HttpClient\HttpClientInterface;
  70. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  71. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  72. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  73. use Symfony\Component\Serializer\SerializerInterface;
  74. class ProductController extends AbstractController
  75. {
  76.     use FilterPriceTrait;
  77.     /**
  78.      * @var EntityManagerInterface
  79.      */
  80.     private $em;
  81.     /**
  82.      * @var HttpClientInterface
  83.      */
  84.     private $client;
  85.     public function __construct(EntityManagerInterface $emHttpClientInterface $client)
  86.     {
  87.         $this->em $em;
  88.         $this->client $client;
  89.     }
  90.     /**
  91.      * @Route("/recherche/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_search")
  92.      */
  93.     public function searchFilter(int $pageRequest $requestDepartmentRepository $departmentRepositoryCategoryRepository $categoryRepositoryProductRepository $productRepositoryPaginatorInterface $paginatorSessionInterface $sessionLocationRepository $locationRepositoryReservationRepository $reservationRepository)
  94.     {
  95.         if ($request->isMethod('POST')) {
  96.             if (
  97.                 $request->get('keyword') || $request->get('type') || $request->get('department_filter') || $request->get('department_filter') || $request->get('city_filter') || $request->get('minprice_filter') ||
  98.                 $request->get('maxprice_filter') || $request->get('category') || $request->get('weddingdate') || $request->get('nb_guest') || $request->get('weddingdate_start') || $request->get('weddingdate_end')
  99.             ) {
  100.                 $parameters = [
  101.                     'department' => $request->get('department_filter') !== '' $request->get('department_filter') : null,
  102.                     'city' => $request->get('city_filter') !== '' $request->get('city_filter') : null,
  103.                     'categoryMaster' => $request->get('category_master') !== '' $request->get('category_master') : null,
  104.                     'min_price' => $request->get('minprice_filter') !== '' $request->get('minprice_filter') : null,
  105.                     'max_price' => $request->get('maxprice_filter') !== '' $request->get('maxprice_filter') : null,
  106.                     'weddingdate' => $request->get('weddingdate') !== '' $request->get('weddingdate') : null,
  107.                     'weddingdate_start' => $request->get('weddingdate_start') !== ''$request->get('weddingdate_start') : null,
  108.                     'weddingdate_end' => $request->get('weddingdate_end') !== ''$request->get('weddingdate_end') : null,
  109.                     'category' => !empty($request->get('category')) ? $request->get('category') : null,
  110.                     'nbGuest' => !empty($request->get('nb_guest')) ? $request->get('nb_guest') : null,
  111.                     'type' => !empty($request->get('type')) ? $request->get('type') : null,
  112.                     'keyword' => !empty($request->get('keyword')) ? $request->get('keyword') : null,
  113.                 ];
  114.                 $session->set('department'$request->get('department_filter'));
  115.                 $session->set('city'$request->get('city_filter'));
  116.                 $session->set('min_price'$request->get('minprice_filter'));
  117.                 $session->set('max_price'$request->get('maxprice_filter'));
  118.                 $session->set('category'$request->get('category'));
  119.                 $session->set('weddingdate'$request->get('weddingdate'));
  120.                 $session->set('weddingdate_start'$request->get('weddingdate_start'));
  121.                 $session->set('weddingdate_end'$request->get('weddingdate_end'));
  122.                 $session->set('nbGuest'$request->get('nb_guest'));
  123.                 $session->set('type'$request->get('type'));
  124.                 $session->set('keyword'$request->get('keyword'));
  125.                 // For displaying names
  126.                 if ($parameters['department'] && $parameters['department'] !== 'Lieu') {
  127.                     $department $departmentRepository->find($parameters['department']);
  128.                     $session->set('departmentName'$department->getName());
  129.                 }
  130.                 $categoryBackground null;
  131.                 if ($parameters['categoryMaster'] && !is_array($parameters['categoryMaster'])) {
  132.                     $category $categoryRepository->find($parameters['categoryMaster']);
  133.                     if ($category) {
  134.                         $categoryBackground $category;
  135.                         $session->set('categoryName'$category->getName());
  136.                     }
  137.                 }
  138.                 $products $productRepository->searchProduct($parameters);
  139.                 if ($parameters['weddingdate']) {
  140.                     $dateSearch str_replace('/''-'$parameters['weddingdate']);
  141.                     $datetime = new \DateTime($dateSearch);
  142.                     $datetime->format('Y-m-d');
  143.                 }
  144.             
  145.                 if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  146.                     $dateStartSearch str_replace('/''-'$parameters['weddingdate_start']);
  147.                     $dateEndSearch str_replace('/''-'$parameters['weddingdate_end']);
  148.                     $dateStart = new \DateTime($dateStartSearch);
  149.                     $dateEnd = new \DateTime($dateEndSearch);
  150.                 }
  151.                 // Calcul count services / products
  152.                 $countService 0;
  153.                 $countProducts 0;
  154.                 /** @var Product $product */
  155.                 foreach ($products as $key => $product) {
  156.                     $isService $product->getSubCategories()->filter(
  157.                         function ($entry) use ($countService$countProducts) {
  158.                             return $entry->getIsService();
  159.                         }
  160.                     );
  161.                     if ($isService) {
  162.                         $countService $countService 1;
  163.                     } else {
  164.                         $countProducts $countProducts 1;
  165.                     }
  166.                     if ($parameters['weddingdate']) {
  167.                         /** @var PlanningCompany $planning */
  168.                         foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  169.                             if ($planning->getDateStamp() == $datetime->getTimestamp()) {
  170.                                 unset($products[$key]);
  171.                             }
  172.                         }
  173.                     }
  174.                     if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  175.                         /** @var PlanningCompany $planning */
  176.                         foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  177.                             $planningDate = new \DateTime();
  178.                             $planningDate->setTimestamp($planning->getDateStamp());
  179.                             if (
  180.                                 ($planningDate >= $dateStart && $planningDate <= $dateEnd)
  181.                             ) {
  182.                                 unset($products[$key]);
  183.                             }
  184.                         }
  185.                     }
  186.                     if ($product->getTypePrestation()) {
  187.                         if ($product->getTypePrestation()->getLabel() == 'location') {
  188.                             $prodEnLocation $locationRepository->getLocationByProduit($product);
  189.                             foreach ($prodEnLocation as $lp) {
  190.                                 if ($parameters['weddingdate']) {
  191.                                     if (($datetime->getTimestamp() >= $lp->getStartAt()->getTimestamp()) && ($datetime->getTimestamp() <= $lp->getEndAt()->getTimestamp())) {
  192.                                         unset($products[$key]);
  193.                                     }
  194.                                 }
  195.                                 if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  196.                                     if (($dateStart->getTimestamp() >= $lp->getStartAt()->getTimestamp()) && ($dateEnd->getTimestamp() <= $lp->getEndAt()->getTimestamp())) {
  197.                                         unset($products[$key]);
  198.                                     }
  199.                                 }
  200.                             }
  201.                         } else {
  202.                             $prodEnReservation $reservationRepository->getreservationByProduit($product);
  203.                             foreach ($prodEnReservation as $reserv) {
  204.                                 if ($parameters['weddingdate']) {
  205.                                     if ($datetime->getTimestamp() == $reserv->getReservationPlannedAt()->getTimestamp()) {
  206.                                         unset($products[$key]);
  207.                                     }
  208.                                 }
  209.                                 if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  210.                                     if (($reserv->getReservationPlannedAt()->getTimestamp() >= $dateStart->getTimestamp()) && 
  211.                                         ($reserv->getReservationPlannedAt()->getTimestamp() <= $dateEnd->getTimestamp())) {
  212.                                         unset($products[$key]);
  213.                                     }
  214.                                 }
  215.                             }
  216.                         }
  217.                     }
  218.                 }
  219.                 $pagination $paginator->paginate(
  220.                     $products,
  221.                     $page/*page number*/
  222.                     15 /*limit per page*/
  223.                 );
  224.                 return $this->render('front/product/listSearch.html.twig', [
  225.                     'products' => $pagination,
  226.                     'countProducts' => $countProducts,
  227.                     'countServices' => $countService,
  228.                     'categoryBackground' => $categoryBackground
  229.                 ]);
  230.             }
  231.         } else {
  232.             $parameters = [
  233.                 'department' => $session->get('department'),
  234.                 'city' => $session->get('city'),
  235.                 'min_price' => $session->get('min_price'),
  236.                 'max_price' => $session->get('max_price'),
  237.                 'weddingdate' => $session->get('weddingdate'),
  238.                 'weddingdate_start' => $session->get('weddingdate_start'),
  239.                 'weddingdate_end' => $session->get('weddingdate_end'),
  240.                 'category' => $session->get('category'),
  241.                 'nbGuest' => $session->get('nbGuest'),
  242.                 'type' => $session->get('type'),
  243.                 'keyword' => $session->get('keyword')
  244.             ];
  245.             $products $productRepository->searchProduct($parameters);
  246.             $pagination $paginator->paginate(
  247.                 $products,
  248.                 $page/*page number*/
  249.                 15 /*limit per page*/
  250.             );
  251.             $categoryBackground null;
  252.             if (isset($parameters['categoryMaster']) && !is_array($parameters['categoryMaster'])) {
  253.                 $category $categoryRepository->find($parameters['categoryMaster']);
  254.                 if ($category) {
  255.                     $categoryBackground $category;
  256.                     $session->set('categoryName'$category->getName());
  257.                 }
  258.             }
  259.             $countService 0;
  260.             $countProducts 0;
  261.             if ($parameters['weddingdate']) {
  262.                 $dateSearch str_replace('/''-'$parameters['weddingdate']);
  263.                 $datetime = new \DateTime($dateSearch);
  264.                 $datetime->format('Y-m-d');
  265.             }
  266.         
  267.             if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  268.                 $dateStart \DateTime::createFromFormat('d/m/Y'$parameters['weddingdate_start'])->format('Y-m-d');
  269.                 $dateEnd \DateTime::createFromFormat('d/m/Y'$parameters['weddingdate_end'])->format('Y-m-d');
  270.             }
  271.             /** @var Product $product */
  272.             foreach ($products as $key => $product) {
  273.                 $isService $product->getSubCategories()->filter(
  274.                     function ($entry) use ($countService$countProducts) {
  275.                         return $entry->getIsService();
  276.                     }
  277.                 );
  278.                 if ($isService) {
  279.                     $countService $countService 1;
  280.                 } else {
  281.                     $countProducts $countProducts 1;
  282.                 }
  283.                 if ($parameters['weddingdate']) {
  284.                     /** @var PlanningCompany $planning */
  285.                     foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  286.                         if ($planning->getDateStamp() == $datetime->getTimestamp()) {
  287.                             unset($products[$key]);
  288.                         }
  289.                     }
  290.                 }
  291.                 if ($parameters['weddingdate_start'] && $parameters['weddingdate_end']) {
  292.                     /** @var PlanningCompany $planning */
  293.                     foreach ($product->getCompany()->getPlanningCompanies() as $planning) {
  294.                         $planningDate = new \DateTime();
  295.                         $planningDate->setTimestamp($planning->getDateStamp());
  296.         
  297.                         if ($planningDate >= new \DateTime($dateStart) && $planningDate <= new \DateTime($dateEnd)) {
  298.                             unset($products[$key]);
  299.                         }
  300.                     }
  301.                 }
  302.             }
  303.             // dd($pagination); // error source
  304.             return $this->render('front/product/listSearch.html.twig', [
  305.                 'products' => $pagination,
  306.                 'countProducts' => $countProducts,
  307.                 'countServices' => $countService,
  308.                 'categoryBackground' => $categoryBackground
  309.             ]);
  310.         }
  311.         $session->remove('department');
  312.         $session->remove('city');
  313.         $session->remove('min_price');
  314.         $session->remove('max_price');
  315.         $session->remove('category');
  316.         //$session->remove('weddingdate');
  317.         $session->remove('nbGuest');
  318.         $session->remove('departmentName');
  319.         $session->remove('categoryName');
  320.         return $this->redirectToRoute('front_product_products');
  321.     }
  322.     /**
  323.      * @Route("/services/categorie/{slug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category_slug")
  324.      */
  325.     public function listByCategory(SubCategoryRepository $subCatRint $pageCategory $categoryProductRepository $productRepositoryPaginatorInterface $paginator$slug)
  326.     {
  327.         $subCategory = new SubCategory;
  328.         $subCategory->setSubCategorySlug('string');
  329.         $products $productRepository->productsByCategory($category);
  330.         if (sizeof($subCatR->getSubCategoriesByCategory($category->getId())) > 0) {
  331.             $subCate $subCatR->getSubCategoriesByCategory($category->getId())[0]['id'];
  332.             $subCategory $subCatR->find($subCate);
  333.         }
  334.         $pagination $paginator->paginate(
  335.             $products,
  336.             $page/*page number*/
  337.             15 /*limit per page*/
  338.         );
  339.         return $this->render('front/product/list.html.twig', [
  340.             'products' => $pagination,
  341.             'subcategory' => $subCategory,
  342.             'countProducts' => count($products)
  343.         ]);
  344.     }
  345.     /**
  346.      * @Route("/services/evenements/{subCategorySlug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category_events")
  347.      */
  348.     public function listByCategoryEvent(SubCategory $subCategoryint $pageProductRepository $productRepositoryPaginatorInterface $paginator)
  349.     {
  350.         $products $productRepository->productsByCategoryMaster($subCategory);
  351.         $pagination $paginator->paginate(
  352.             $products,
  353.             $page/*page number*/
  354.             15 /*limit per page*/
  355.         );
  356.         return $this->render('front/product/list.html.twig', [
  357.             'products' => $pagination,
  358.             'subcategory' => $subCategory,
  359.             'countProducts' => count($products)
  360.         ]);
  361.     }
  362.     /**
  363.      * @Route("/services/ordre/{slug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_category")
  364.      */
  365.     public function orderByCategory(string $slugint $pageProductRepository $productRepositoryPaginatorInterface $paginator)
  366.     {
  367.         if ($slug === 'note') {
  368.             $products $productRepository->orderByNotes();
  369.         } elseif ($slug === 'reserved') {
  370.             $products $productRepository->orderByCommands();
  371.         }
  372.         $pagination $paginator->paginate(
  373.             $products,
  374.             $page/*page number*/
  375.             15 /*limit per page*/
  376.         );
  377.         return $this->render('front/product/list.html.twig', [
  378.             'products' => $pagination,
  379.             'countProducts' => count($products)
  380.         ]);
  381.     }
  382.     /**
  383.      * @Route("/services/sous-categorie/{subCategorySlug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_subcategory")
  384.      */
  385.     public function listBySubCategory(int $pageSubCategory $subCategoryProductRepository $productRepositoryPaginatorInterface $paginator)
  386.     {
  387.         $products $productRepository->productsBySubCategory($subCategory);
  388.         $pagination $paginator->paginate(
  389.             $products,
  390.             $page/*page number*/
  391.             15 /*limit per page*/
  392.         );
  393.         return $this->render('front/product/list.html.twig', [
  394.             'products' => $pagination,
  395.             'countProducts' => count($products)
  396.         ]);
  397.     }
  398.     /**
  399.      * @Route("/services/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_product_products")
  400.      */
  401.     public function products(
  402.         int $page,
  403.         ProductRepository $productRepository,
  404.         PaginatorInterface $paginator,
  405.         SessionInterface $session,
  406.         AdminPromoRepository $adminPRomoRepository
  407.     ) {
  408.         $session->remove('department');
  409.         $session->remove('min_price');
  410.         $session->remove('max_price');
  411.         $session->remove('category');
  412.         $products $productRepository->findAllServices();
  413.         // dd($products);
  414.         $pagination $paginator->paginate(
  415.             $products,
  416.             $page/*page number*/
  417.             15 /*limit per page*/
  418.         );
  419.         $today = new \DateTimeImmutable();
  420.         $isPromoAdmin $adminPRomoRepository->findOneByPeriod($today);
  421.         return $this->render('front/product/listSearch.html.twig', [
  422.             'products' => $pagination,
  423.             'countProducts' => count($products),
  424.             'isPromoAdmin' => $isPromoAdmin
  425.         ]);
  426.     }
  427.     /**
  428.      * @Route("/service/{slug}/{subCategorySlug}/{product_id}/{productSlug}", name="front_product_single", requirements={"productSlug"=".+"})
  429.      * @ParamConverter("product", options={"id" = "product_id"})
  430.      */
  431.     public function productSingle(
  432.         TicketRepository $ticketRepository,
  433.         $slug,
  434.         Request $request,
  435.         Product $product,
  436.         SessionInterface $session,
  437.         WishListRepository $wishListRepository,
  438.         ProductRepository $productRepository,
  439.         AvisRepository $avisRepository,
  440.         // User $user,
  441.         Mail $mail,
  442.         File $file,
  443.         PlanningCompanyRepository $planningCompanyRepository,
  444.         LocationRepository $locationrepo,
  445.         CaracteristiqueVehiculeRepository $caracteristiqueVehiculeRepo,
  446.         AdminPromoRepository $adminPRomoRepository
  447.     ) {
  448.         $category $slug;
  449.         $ticket = new Ticket();
  450.         $formTicket $this->createForm(TicketProductType::class, $ticket, ['company' => $this->getUser()])->handleRequest($request);
  451.         if ($formTicket->isSubmitted() && $formTicket->isValid()) {
  452.             if (!$this->getUser()) {
  453.                 $session->set('chatInCurse'true);
  454.                 return $this->redirectToRoute('app_login');
  455.             }
  456.             if ($this->getUser() != null) {
  457.                 $ticket->setNumero(strtoupper(uniqid()))
  458.                     ->setSubject('contact prestataire')
  459.                     ->setProduct($product)
  460.                     ->setCreatedBy($this->getUser());
  461.             } else {
  462.                 $session->set('chatInCurse'true);
  463.                 return $this->redirectToRoute('app_login');
  464.             }
  465.             $messaging = new Messaging();
  466.             $messaging->setText($request->request->get('ticket_product')['messagings']['text']);
  467.             $messaging->setTicket($ticket);
  468.             $messaging->setMessageUser($this->getUser());
  469.             $ticket->addMessaging($messaging);
  470.             $this->em->persist($ticket);
  471.             $this->em->persist($messaging);
  472.             $this->em->flush();
  473.             return $this->redirectToRoute('front_client_space_tickets');
  474.         }
  475.         // else if($this->getUser() == null) {
  476.         //     echo '<message class="alert alert-danger">Vous devez vous connecter</message>';
  477.         //     return $this->redirectToRoute('app_login');
  478.         // }
  479.         if ($session->get('products')) {
  480.             $productExistInSession false;
  481.             foreach ($session->get('products') as $productSession) {
  482.                 if (array_search($product->getId(), $productSession)) {
  483.                     $productExistInSession true;
  484.                 }
  485.             }
  486.         } else {
  487.             $productExistInSession false;
  488.         }
  489.         $avis = new Avis();
  490.         $form $this->createForm(AvisType::class, $avis)->handleRequest($request);
  491.         $lastProducts $productRepository->getOtherProductsCompanyNotSingle($product->getCompany(), $product);
  492.         if ($form->isSubmitted() && $form->isValid()) {
  493.             $avis->setProduct($product);
  494.             $avis->setClient($this->getUser());
  495.             $newGlobalNote = ($avis->getCommunication() + $avis->getPrice() + $avis->getConformDescription() + $avis->getFiability() + $avis->getServiceQuality() + $avis->getSpeed()) / 6;
  496.             $avis->setGlobalNote($newGlobalNote);
  497.             $this->em->persist($avis);
  498.             $this->em->flush();
  499.             if ($request->files->get('avis') !== null) {
  500.                 foreach ($request->files->get('avis')['imageComments'] as $image) {
  501.                     foreach ($image as $img) {
  502.                         if ($img !== null) {
  503.                             $commentimage $avisRepository->findById(['id' => $avis->getId()]);
  504.                             $imagecomment = new ImageComment();
  505.                             $filename $file->uploadImageComment($img);
  506.                             $imagecomment->setAvis($avis);
  507.                             $imagecomment->setUrl($filename);
  508.                             $this->em->persist($imagecomment);
  509.                         }
  510.                     }
  511.                 }
  512.                 $this->em->flush();
  513.             }
  514.             $this->addFlash('success''Merci pour votre avis !');
  515.             return $this->redirectToRoute('front_product_single', [
  516.                 // 'slug' => $product->getSubCategory()->getCategory()->getSlug(),
  517.                 'slug' => $product->getSubCategories()->toArray()[0]->getCategories()->toArray()[0]->getSlug(),
  518.                 'subCategorySlug' => $product->getSubCategories()->toArray()[0]->getSubCategorySlug(),
  519.                 'product_id' => $product->getId(),
  520.                 'productSlug' => $product->getProductSlug()
  521.             ]);
  522.         }
  523.         $contactProduct = new ContactProduct();
  524.         $formContactProduct $this->createForm(ContactProductType::class, $contactProduct)->handleRequest($request);
  525.         if ($formContactProduct->isSubmitted() && $formContactProduct->isValid()) {
  526.             $contactProduct->setProduct($product);
  527.             $this->em->persist($contactProduct);
  528.             $this->em->flush();
  529.             $mail->contactProvider($product->getCompany(), $contactProduct);
  530.             return $this->json([
  531.                 'status' => 'ok',
  532.                 'message' => 'Message envoyé !'
  533.             ]);
  534.         }
  535.         $productComments $avisRepository->getCommentsByArticle($product);
  536.         $productAvis $avisRepository->findBy(['product' => $product]);
  537.         $globalNote = ['totalNote' => 0'count' => 0];
  538.         $qualityService = ['totalNote' => 0'count' => 0];
  539.         $fiablity = ['totalNote' => 0'count' => 0];
  540.         $price = ['totalNote' => 0'count' => 0];
  541.         $speed = ['totalNote' => 0'count' => 0];
  542.         $conformDescription = ['totalNote' => 0'count' => 0];
  543.         $communication = ['totalNote' => 0'count' => 0];
  544.         foreach ($productAvis as $avis) {
  545.             $globalNote['totalNote'] = $globalNote['totalNote'] + $avis->getGlobalNote();
  546.             $globalNote['count'] = $globalNote['count'] + 1;
  547.             $qualityService['totalNote'] = $qualityService['totalNote'] + $avis->getServiceQuality();
  548.             $qualityService['count'] = $qualityService['count'] + 1;
  549.             $fiablity['totalNote'] = $fiablity['totalNote'] + $avis->getFiability();
  550.             $fiablity['count'] = $fiablity['count'] + 1;
  551.             $price['totalNote'] = $price['totalNote'] + $avis->getPrice();
  552.             $price['count'] = $price['count'] + 1;
  553.             $speed['totalNote'] = $speed['totalNote'] + $avis->getSpeed();
  554.             $speed['count'] = $speed['count'] + 1;
  555.             $conformDescription['totalNote'] = $conformDescription['totalNote'] + $avis->getConformDescription();
  556.             $conformDescription['count'] = $conformDescription['count'] + 1;
  557.             $communication['totalNote'] = $communication['totalNote'] + $avis->getCommunication();
  558.             $communication['count'] = $communication['count'] + 1;
  559.         }
  560.         $caracteristiqueVId $product->getCaracteristiqueVehicule() ? $product->getCaracteristiqueVehicule()->getId() : null;
  561.         if($caracteristiqueVId){
  562.             $caracteristiqueVehicules$caracteristiqueVehiculeRepo->findOneBy(['id'=>$caracteristiqueVId]);
  563.             $caracteristiqueVehiculesDatas = [
  564.                 'isAirConditioned'=>$caracteristiqueVehicules->getIsAirConditioned() ?: null,
  565.                 'doorCount'=>$caracteristiqueVehicules->getDoorCount()?: null,
  566.                 'seatCount'=>$caracteristiqueVehicules->getSeatCount()?: null,
  567.                 'speedLimit'=>$caracteristiqueVehicules->getSpeedLimit()?: null,
  568.                 'gearboxType'=>$caracteristiqueVehicules->getGearboxType()?$caracteristiqueVehicules->getGearboxType()->getType(): null,
  569.                 'fuelType'=>$caracteristiqueVehicules->getFuelType()? $caracteristiqueVehicules->getFuelType()->getFuel() : null
  570.             ];
  571.         }elseif(!$caracteristiqueVId){
  572.             $caracteristiqueVehiculesDatas = [
  573.                 'isAirConditioned'=>null,
  574.                 'doorCount'=>null,
  575.                 'seatCount'=>null,
  576.                 'speedLimit'=>null,
  577.                 'gearboxType'=>null,
  578.                 'fuelType'=>null
  579.             ];
  580.         }
  581.         // dd($caracteristiqueVehiculesDatas);
  582.         $today = new \DateTimeImmutable();
  583.         $isPromoAdmin $adminPRomoRepository->findOneByPeriod($today);
  584.        
  585.         return $this->render('front/product/single.html.twig', [
  586.             'plannings' => $planningCompanyRepository->findBy(['company' => $product->getCompany()]),
  587.             'planningClients' => $locationrepo->getLocationByCompany($product->getCompany()),
  588.             'product' => $product,
  589.             'otherProducts' => $lastProducts,
  590.             'category' => $category,
  591.             'btnForm' => $productExistInSession,
  592.             'isWish' => $wishListRepository->findOneBy(['user' => $this->getUser(), 'product' => $product]),
  593.             'formComment' => $form->createView(),
  594.             'formTicket' => $formTicket->createView(),
  595.             'formContact' => $formContactProduct->createView(),
  596.             'productAvis' => $productComments,
  597.             'notes' => [
  598.                 'globalNote' => $globalNote,
  599.                 'qualityService' => $qualityService,
  600.                 'price' => $price,
  601.                 'speed' => $speed,
  602.                 'conformDescription' => $conformDescription,
  603.                 'communication' => $communication,
  604.             ],
  605.             'caracteristiques'=> $caracteristiqueVehiculesDatas,
  606.             'isPromoAdmin' => $isPromoAdmin
  607.         ]);
  608.     }
  609.     /**
  610.      *@Route("/sendMessageAbout/{product_id}/{productSlug}", name="connection-test")
  611.      *@ParamConverter("product", options={"id" = "product_id"})
  612.      */
  613.     public function connectionTest(
  614.         SessionInterface $session
  615.     ) {
  616.         if ($this->getUser() == NULL) {
  617.             $session->set('chatInCurse'true);
  618.             return $this->redirectToRoute('app_login');
  619.         }
  620.     }
  621.     /**
  622.      * @Route("/ajout-produit/{id}", name="front_product_add_product_basket")
  623.      */
  624.     public function addProductBasket(Product $productRequest $requestSessionInterface $sessionSubCategoryRepository $subrepoProductOptionRepository $prodOptionrepo)
  625.     {
  626.         // dd(json_decode($request->get('groupOption')));
  627.         // dd($product->getProductOptions()->toArray());
  628.         $options $product->getProductOptions()->toArray();
  629.         // dd($options[1]);
  630.         // foreach ($request->get('qtyOption') as $key => $value) {
  631.         //     echo $value . "<br>";
  632.         // }
  633.         foreach ($options as $key => $value) {
  634.             // dd($value->getPQte());
  635.             if (isset($request->get('qtyOption')[$value->getId()]) && $request->get('qtyOption')[$value->getId()] > $value->getPQte()) {
  636.                 // return $this->json([
  637.                 //     'message' => 'error',
  638.                 //     'response' => 'Quantité option non disponible'
  639.                 // ]);
  640.             }
  641.         }
  642.         if (!$request->get('quantity')) {
  643.             return $this->json([
  644.                 'message' => 'error',
  645.                 'response' => 'Quantité incorrecte'
  646.             ]);
  647.         }
  648.         if ($request->get('quantity') > $product->getQuantity()) {
  649.             return $this->json([
  650.                 'message' => 'error',
  651.                 'response' => 'Quantité non disponible'
  652.             ]);
  653.         }
  654.         // $archivoption="";
  655.         if ($session->get('products')) {
  656.             $allProducts $session->get('products');
  657.             $productExistInSession false;
  658.             foreach ($session->get('products') as $key => $productSession) {
  659.                 // if (!empty($productSession['options_fairepar'])) {
  660.                 //     $archivoption =$productSession['options_fairepar'];
  661.                 // }
  662.                 if (array_search($product->getId(), $productSession)) {
  663.                     $productExistInSession true;
  664.                     unset($allProducts[$key]);
  665.                     $session->set('products'$allProducts);
  666.                 }
  667.             }
  668.         } else {
  669.             $productExistInSession false;
  670.         }
  671.         if ($productExistInSession) {
  672.             return $this->json([
  673.                 'message' => 'ok',
  674.                 'response' => 'removed'
  675.             ]);
  676.         }
  677.         $sub $subrepo->getSubcategoryByProduit($product);
  678.         if ($sub[0]->getSubCategorySlug() == "faire-part") {
  679.             $tabOption = [];
  680.             $tabId = [];
  681.             if (!empty($request->get('options'))) {
  682.                 foreach ($request->get('options') as $key => $value) {
  683.                     $tabId[] = $key;
  684.                 }
  685.             }
  686.             if (!empty($request->get('idoptions'))) {
  687.                 $idoption $request->get('idoptions');
  688.                 $tabId explode(','$idoption);
  689.             }
  690.             for ($f 0$f sizeof($tabId); $f++) {
  691.                 $existe1 false;
  692.                 if (!empty($request->get('tail'))) {
  693.                     for ($i 0$i json_decode($request->get('tail')); $i++) {
  694.                         if (json_decode($request->get('OpId_' $i))->idoption == $tabId[$f]) {
  695.                             $existe1 true;
  696.                             $tabOption["option_" $f]["idoption"] = json_decode($request->get('OpId_' $i))->idoption json_decode($request->get('OpId_' $i))->idoption null;
  697.                             $tabOption["option_" $f]["nomoption"] = json_decode($request->get('OpId_' $i))->nomoption json_decode($request->get('OpId_' $i))->nomoption null;
  698.                             $tabOption["option_" $f]["imageoption"] = json_decode($request->get('OpId_' $i))->imageoption json_decode($request->get('OpId_' $i))->imageoption null;
  699.                             $tabOption["option_" $f]["color"] = json_decode($request->get('OpId_' $i))->color json_decode($request->get('OpId_' $i))->color null;
  700.                             $tabOption["option_" $f]["form"] = json_decode($request->get('OpId_' $i))->form json_decode($request->get('OpId_' $i))->form null;
  701.                             $tabOption["option_" $f]["finition"] = json_decode($request->get('OpId_' $i))->finition json_decode($request->get('OpId_' $i))->finition null;
  702.                             $tabOption["option_" $f]["papier"] = json_decode($request->get('OpId_' $i))->papier json_decode($request->get('OpId_' $i))->papier null;
  703.                             $tabOption["option_" $f]["etiquette"] = json_decode($request->get('OpId_' $i))->etiquette json_decode($request->get('OpId_' $i))->etiquette null;
  704.                             $tabOption["option_" $f]["ruban"] = json_decode($request->get('OpId_' $i))->ruban json_decode($request->get('OpId_' $i))->ruban null;
  705.                             if (json_decode($request->get('OpId_' $i))->quantite != null && json_decode($request->get('OpId_' $i))->quantite != "Échantillon (0,00 €)") {
  706.                                 $tabOption["option_" $f]["quantite"] = json_decode($request->get('OpId_' $i))->quantite ? (int)explode(" "json_decode($request->get('OpId_' $i))->quantite)[0] : null;
  707.                                 $tabOption["option_" $f]["price"] = json_decode($request->get('OpId_' $i))->quantite ? (int)explode(" "json_decode($request->get('OpId_' $i))->quantite)[2] : null;
  708.                             } else {
  709.                                 $tabOption["option_" $f]["quantite"] = 1;
  710.                                 $tabOption["option_" $f]["price"] = 0.00;
  711.                             }
  712.                         }
  713.                     }
  714.                 }
  715.                 if (!$existe1) {
  716.                     foreach ($prodOptionrepo->findProduitOptionchecked($tabId[$f]) as $optionsProd) {
  717.                         $tabOption["option_" $f]["idoption"] = $optionsProd->getId() ? $optionsProd->getId() : null;
  718.                         $tabOption["option_" $f]["nomoption"] = $optionsProd->getName() ? $optionsProd->getName() : null;
  719.                         $tabOption["option_" $f]["imageoption"] = $optionsProd->getImage1() ? $optionsProd->getImage1() : null;
  720.                         $tabOption["option_" $f]["color"] = $optionsProd->getColorsOption() ? $optionsProd->getColorsOption()[0] : null;
  721.                         $tabOption["option_" $f]["form"] = $optionsProd->getFormat() ? $optionsProd->getFormat()[0] : null;
  722.                         $tabOption["option_" $f]["finition"] = $optionsProd->getFinition() ? $optionsProd->getFinition()[0] : null;
  723.                         $tabOption["option_" $f]["papier"] = $optionsProd->getPapier() ? $optionsProd->getPapier()[0] : null;
  724.                         $tabOption["option_" $f]["etiquette"] = $optionsProd->getEtiquette() ? $optionsProd->getEtiquette()[0] : null;
  725.                         $tabOption["option_" $f]["ruban"] = $optionsProd->getRuban() ? $optionsProd->getRuban()[0] : null;
  726.                         $tabOption["option_" $f]["quantite"] = 1;
  727.                         $tabOption["option_" $f]["price"] = 0.00;
  728.                     }
  729.                 }
  730.             }
  731.             $product = [
  732.                 'productId' => $product->getId(),
  733.                 'quantity' => $request->get('quantity'),
  734.                 'size' => $request->get('size') ? $request->get('size') : null,
  735.                 'sizeRing' => $request->get('size_ring') ? $request->get('size_ring') : null,
  736.                 'nbGuest' => $request->get('nb_guest') ? $request->get('nb_guest') : null,
  737.                 'color' => $request->get('color') ? $request->get('color') : null,
  738.                 'options' => null,
  739.                 'options_fairepar' => $tabOption $tabOption null,
  740.                 'qtyOption' => $request->get('qtyOption') ? $request->get('qtyOption') : null
  741.             ];
  742.         } else {
  743.             $options = [];
  744.             // for ($g=0; $g < sizeof(json_decode($request->get('groupOption'))); $g++) { 
  745.             //     $options[]=json_decode($request->get('groupOption'))[g]['idoption'];
  746.             // }
  747.             $groupsOption json_decode($request->get('groupOption'));
  748.             if (empty($groupsOption) || $groupsOption == null) {
  749.             } else {
  750.                 foreach ($groupsOption as $key => $gropOption) {
  751.                     foreach ($gropOption->labelo as $key => $lab) {
  752.                         $options[$gropOption->idoption][] = [
  753.                             "valeur" => explode("#_#"$lab)[0],
  754.                             "prix" => explode("#_#"$lab)[1],
  755.                             "qte" => $gropOption->qte[$key]
  756.                         ];
  757.                     }
  758.                     // $options[]=$valer_prix; 
  759.                     // $options[]=$gropOption; 
  760.                     // $options[$gropOption->idoption]=$gropOption->labelo;
  761.                     // $options[$gropOption->idoption]['qte']=$gropOption->qte;
  762.                 }
  763.             }
  764.             // dd($options);
  765.             $product = [
  766.                 'productId' => $product->getId(),
  767.                 'quantity' => $request->get('quantity'),
  768.                 'size' => $request->get('size') ? $request->get('size') : null,
  769.                 'sizeRing' => $request->get('size_ring') ? $request->get('size_ring') : null,
  770.                 'nbGuest' => $request->get('nb_guest') ? $request->get('nb_guest') : null,
  771.                 'color' => $request->get('color') ? $request->get('color') : null,
  772.                 // 'options' => $request->get('options') ? $request->get('options') : null,
  773.                 // 'qtyOption' => $request->get('qtyOption') ? $request->get('qtyOption') : null
  774.                 'options' => $options
  775.             ];
  776.         }
  777.         //    dd($product);
  778.         if ($session->get('products')) {
  779.             $products $session->get('products');
  780.             array_push($products$product);
  781.             $session->set('products'$products);
  782.         } else {
  783.             $session->set('products', [$product]);
  784.         }
  785.         if (!empty($tabOption)) {
  786.             $session->set('archive'$tabOption);
  787.         }
  788.         return $this->json([
  789.             'message' => 'ok',
  790.             'response' => 'added'
  791.         ]);
  792.     }
  793.     /**
  794.      * @Route("/ajout-pack/{id}", name="front_product_add_pack_basket")
  795.      */
  796.     public function addPackToBasket(Pack $packSessionInterface $sessionRequest $request)
  797.     {
  798.         if (!$session->get('packs')) {
  799.             $session->set('packs'$pack->getId());
  800.         } else {
  801.             $session->remove('packs');
  802.             return $this->json([
  803.                 'message' => "ok",
  804.                 'response' => 'removed'
  805.             ]);
  806.         }
  807.         return $this->json([
  808.             'message' => 'ok',
  809.             'response' => 'added'
  810.         ]);
  811.     }
  812.     /**
  813.      * @Route("/get-subcategory", name="front_company_get_subcategory")
  814.      */
  815.     public function getSubCategory(
  816.         Request $request,
  817.         SubCategoryRepository $subCategoryRepository,
  818.         TypeLocalisationRepository $typLocalRep,
  819.         TypeHebergementRepository $typHebRep,
  820.         LangueHoteRepository $langHoteRep,
  821.         EquipmentRepository $equipmRep,
  822.         SecurityRepository $secureRep,
  823.         CaracteristicRepository $caracteristicRep
  824.     ) {
  825.         $typLocalisations $typLocalRep->findAll();
  826.         $typeHebergements $typHebRep->findAll();
  827.         $securities $secureRep->findAll();
  828.         $hoteLanguages $langHoteRep->findAll();
  829.         $equipments $equipmRep->findAll();
  830.         $caracteristics $caracteristicRep->findAll();
  831.         // Activités liées aux activités
  832.         // $activities = $subCategoryRepository->findCategoryBySubCategorySlug('activites');
  833.         $activities $this->em->getRepository(ActivityType::class)->findAll();
  834.         if ($request->get('data')) {
  835.             $idCategories json_decode($request->get('data'));
  836.             $isClothing false;
  837.             $isColor false;
  838.             $isClothingRing false;
  839.             $isNbGuest false;
  840.             $isService false;
  841.             $isVehicle false;
  842.             $slugs = [];
  843.             $slug '';
  844.             $categoryHebergement $this->em->getRepository(Category::class)->findOneBy(['slug' => 'hebergements']);
  845.             $subCategoryHebergements $categoryHebergement->getSubCategories()->toArray();
  846.             $subCategorySlugHebergement = [];
  847.             foreach ($subCategoryHebergements as $subCategoryHebergement) {
  848.                 $subCategorySlugHebergement[] = $subCategoryHebergement->getSubCategorySlug();
  849.             }
  850.             if ($idCategories->idCategory) {
  851.                 foreach ($idCategories as $idCategory) {
  852.                     foreach ($idCategory as $idcat) {
  853.                         $subCategory $subCategoryRepository->find($idcat);
  854.                         $slugs[] = $subCategory->getSubCategorySlug();
  855.                         $slug $subCategory->getSubCategorySlug();
  856.                         $isClothing $subCategory->getIsClothing() ? true $isClothing;
  857.                         $isColor $subCategory->getIsColor() ? true $isColor;
  858.                         $isClothingRing $subCategory->getIsClothingRing() ? true $isClothingRing;
  859.                         $isNbGuest $subCategory->getIsNbGuest() ? true $isNbGuest;
  860.                         $isService $subCategory->getIsService() ? true $isService;
  861.                         $isVehicle $subCategory->getIsVehicle() ? true $isVehicle;
  862.                     }
  863.                 }
  864.             }
  865.             //    dd($isColor,$isFomat,$isFinition);
  866.             return $this->json([
  867.                 'subCategSlugs' => $slugs,
  868.                 'subCategSlug' => $slug,
  869.                 'isClothing' => $isClothing,
  870.                 'isColor' => $isColor,
  871.                 'isNbGuest' => $isNbGuest,
  872.                 'isClothingRing' => $isClothingRing,
  873.                 'isService' => $isService,
  874.                 'isVehicle' => $isVehicle,
  875.                 'subCategorySlugHebergement' => $subCategorySlugHebergement,
  876.                 'isHebergementHTML' => $this->render('front/html/choix_type_hebergement.html.twig', [
  877.                     'typLocalisations' => $typLocalisations,
  878.                     'typeHebergements' => $typeHebergements,
  879.                     'securities' => $securities,
  880.                     'hoteLanguages' => $hoteLanguages,
  881.                     'equipments' => $equipments,
  882.                     'caracteristics' => $caracteristics
  883.                 ]),
  884.                 'isClothingHTML' => $this->render('front/html/clothing.html.twig'),
  885.                 'isColorHTML' => $this->render('front/html/colors.html.twig'),
  886.                 'isNbGuestHTML' => $this->render('front/html/quantity.html.twig'),
  887.                 'isClothingRingHTML' => $this->render('front/html/clothing_ring.html.twig'),
  888.                 'isActivitesHTML' => $this->render('front/html/choix_type_activite.html.twig', [
  889.                     'activities' => $activities
  890.                 ])
  891.             ]);
  892.         }
  893.     }
  894.     /**
  895.      * @Route("/get-subcategory-hebergement", name="front_company_get_subcategory_hebergement")
  896.      */
  897.     public function getSubCategoryHebergement(
  898.         Request $request,
  899.         SubCategoryRepository $subCategoryRepository,
  900.         TypeLocalisationRepository $typLocalRep,
  901.         TypeHebergementRepository $typHebRep,
  902.         LangueHoteRepository $langHoteRep,
  903.         EquipmentRepository $equipmRep,
  904.         SecurityRepository $secureRep,
  905.         CaracteristicRepository $caracteristicRep
  906.     ) {
  907.         $typLocalisations $typLocalRep->findAll();
  908.         $typeHebergements $typHebRep->findAll();
  909.         $securities $secureRep->findAll();
  910.         $hoteLanguages $langHoteRep->findAll();
  911.         $equipments $equipmRep->findAll();
  912.         $caracteristics $caracteristicRep->findAll();
  913.         if ($request->get('data')) {
  914.             $idCategories json_decode($request->get('data'));
  915.             $isClothing false;
  916.             $isColor false;
  917.             $isClothingRing false;
  918.             $isNbGuest false;
  919.             $isService false;
  920.             $slugs = [];
  921.             $slug '';
  922.             $categoryHebergement $this->em->getRepository(Category::class)->findOneBy(['slug' => 'hebergement']);
  923.             $subCategoryHebergements $categoryHebergement->getSubCategories()->toArray();
  924.             foreach ($subCategoryHebergements as $subCategoryHebergement) {
  925.                 $subCategorySlugHebergement[] = $subCategoryHebergement->getSubCategorySlug();
  926.             }
  927.             if ($idCategories->idCategory) {
  928.                 foreach ($idCategories as $idCategory) {
  929.                     foreach ($idCategory as $idcat) {
  930.                         $subCategory $subCategoryRepository->find($idcat);
  931.                         $slugs[] = $subCategory->getSubCategorySlug();
  932.                         $slug $subCategory->getSubCategorySlug();
  933.                         $isClothing $subCategory->getIsClothing() ? true $isClothing;
  934.                         $isColor $subCategory->getIsColor() ? true $isColor;
  935.                         $isClothingRing $subCategory->getIsClothingRing() ? true $isClothingRing;
  936.                         $isNbGuest $subCategory->getIsNbGuest() ? true $isNbGuest;
  937.                         $isService $subCategory->getIsService() ? true $isService;
  938.                     }
  939.                 }
  940.             }
  941.             //    dd($isColor,$isFomat,$isFinition);
  942.             return $this->json([
  943.                 'subCategSlugs' => $slugs,
  944.                 'subCategSlug' => $slug,
  945.                 'isClothing' => $isClothing,
  946.                 'isColor' => $isColor,
  947.                 'isNbGuest' => $isNbGuest,
  948.                 'isClothingRing' => $isClothingRing,
  949.                 'isService' => $isService,
  950.                 'subCategorySlugHebergement' => $subCategorySlugHebergement,
  951.                 'isHebergementHTML' => $this->render('front/html/optionHebergement.html.twig', [
  952.                     'typLocalisations' => $typLocalisations,
  953.                     'typeHebergements' => $typeHebergements,
  954.                     'securities' => $securities,
  955.                     'hoteLanguages' => $hoteLanguages,
  956.                     'equipments' => $equipments,
  957.                     'caracteristics' => $caracteristics
  958.                 ]),
  959.                 'isClothingHTML' => $this->render('front/html/clothing.html.twig'),
  960.                 'isColorHTML' => $this->render('front/html/colors.html.twig'),
  961.                 'isNbGuestHTML' => $this->render('front/html/quantity.html.twig'),
  962.                 'isClothingRingHTML' => $this->render('front/html/clothing_ring.html.twig')
  963.             ]);
  964.         }
  965.     }
  966.     /**
  967.      * @Route("/get-subCategoryAdded", name="front_company_get_subCategoryAdded")
  968.      */
  969.     public function subCategoryAdded(Request $requestSubCategoryRepository $subCategRepCategoryRepository $categRep)
  970.     {
  971.         $subCategSelected = [];
  972.         $slugSubCateg = [];
  973.         if ($request->get('data')) {
  974.             $subCategAdded json_decode($request->get('data'));
  975.             if ($subCategAdded) {
  976.                 foreach ($subCategAdded as $idSubCateg) {
  977.                     $subCategSelected[] = $subCategRep->find($idSubCateg);
  978.                 }
  979.             }
  980.         }
  981.         if ($subCategSelected) {
  982.             foreach ($subCategSelected as $subCateg) {
  983.                 $slugSubCateg[] = $subCateg->getSubCategorySlug();
  984.             }
  985.         }
  986.         $criteres['slug'] = 'hebergements';
  987.         $subCategHebergm $categRep->findByCriteres($criteres)[0]->getSubCategories()->toArray();
  988.         foreach ($subCategHebergm as $subHebg) {
  989.             $allSubCategHeberg[] = $subHebg->getSubCategorySlug();
  990.         }
  991.         return $this->json([
  992.             'subCategSelected' => $slugSubCateg,
  993.             'allSubCategHeberg' => $allSubCategHeberg
  994.         ]);
  995.     }
  996.     /**
  997.      * @Route("/get-typeLocalisationAdded", name="front_company_get_typeLocalisationAdded")
  998.      */
  999.     public function typeLocalisationAdded(Request $requestTypeLocalisationRepository $typLocalRep)
  1000.     {
  1001.         $typeLocalisationSelected = [];
  1002.         if ($request->get('data')) {
  1003.             $typeLocalisationAdded json_decode($request->get('data'));
  1004.             if ($typeLocalisationAdded) {
  1005.                 foreach ($typeLocalisationAdded as $idTypeLocal) {
  1006.                     $typeLocalisationSelected[] = $typLocalRep->find($idTypeLocal);
  1007.                 }
  1008.             }
  1009.         }
  1010.         return $this->json([
  1011.             'typeLocalisationSelected' => $typeLocalisationSelected
  1012.         ]);
  1013.     }
  1014.     /**
  1015.      * @Route("/get-subcategory-fairepart", name="front_company_get_subcategory-fairepart")
  1016.      */
  1017.     public function getSubCatFairepart(Request $requestSubCategoryRepository $subCategoryRepositoryFilter $filtre)
  1018.     {
  1019.         if ($request->get('data')) {
  1020.             $idCategories json_decode($request->get('data'));
  1021.             $isFairepart false;
  1022.             if ($idCategories->idCategory) {
  1023.                 foreach ($idCategories as $idCategory) {
  1024.                     foreach ($idCategory as $idcat) {
  1025.                         $subCategory $subCategoryRepository->find($idcat);
  1026.                         $isFairepart $subCategory->getIsFairepart() ? true $isFairepart;
  1027.                     }
  1028.                 }
  1029.             }
  1030.             return $this->json([
  1031.                 'isFairepart' =>  $isFairepart,
  1032.                 'couleurs' => $filtre->listecouleurs()
  1033.             ]);
  1034.         }
  1035.     }
  1036.     /**
  1037.      * @Route("/get-typeHebergementAdded", name="front_company_get_typeHebergementAdded")
  1038.      */
  1039.     public function typeHebergementAdded(Request $requestTypeHebergementRepository $typHebgRep)
  1040.     {
  1041.         $typLocalisations $this->em->getRepository(TypeLocalisation::class)->findAll();
  1042.         $typeHebergements $this->em->getRepository(TypeHebergement::class)->findAll();
  1043.         $securities $this->em->getRepository(Security::class)->findAll();
  1044.         $hoteLanguages $this->em->getRepository(LangueHote::class)->findAll();
  1045.         $equipments $this->em->getRepository(Equipment::class)->findAll();
  1046.         $caracteristics $this->em->getRepository(Caracteristic::class)->findAll();
  1047.         $equipementsCuisine $this->em->getRepository(EquipementsCuisine::class)->findAll();
  1048.         $salleDeBain $this->em->getRepository(SalleDeBain::class)->findAll();
  1049.         $accessoiresDeChambre $this->em->getRepository(AccessoiresDeChambre::class)->findAll();
  1050.         $mobilierExterieur $this->em->getRepository(MobilierExterieur::class)->findAll();
  1051.         $typHebergSelected = [];
  1052.         if ($request->get('data')) {
  1053.             $typeHebergementAdded json_decode($request->get('data'));
  1054.             if ($typeHebergementAdded) {
  1055.                 $typHebergSelected $typHebgRep->find($typeHebergementAdded[0]);
  1056.             }
  1057.             $typeHebergement $typHebergSelected->getSlugTypeHebergm();
  1058.         }
  1059.         if ($typeHebergement == "hotel") {
  1060.             $type $this->render('front/html/typeHebergement/HotelHebergement.html.twig', [
  1061.                 'typLocalisations' => $typLocalisations,
  1062.                 'securities' => $securities,
  1063.                 'hoteLanguages' => $hoteLanguages,
  1064.                 'equipments' => $equipments,
  1065.                 'caracteristics' => $caracteristics,
  1066.                 'equipementsCuisine' => $equipementsCuisine,
  1067.                 'salleDeBain' => $salleDeBain,
  1068.                 'accessoiresDeChambre' => $accessoiresDeChambre,
  1069.                 'mobilierExterieur' => $mobilierExterieur
  1070.             ]);
  1071.         } else if ($typeHebergement == "appartement") {
  1072.             $type $this->render('front/html/typeHebergement/appartement.html.twig', [
  1073.                 'typLocalisations' => $typLocalisations,
  1074.                 'securities' => $securities,
  1075.                 'hoteLanguages' => $hoteLanguages,
  1076.                 'equipments' => $equipments,
  1077.                 'caracteristics' => $caracteristics,
  1078.                 'equipementsCuisine' => $equipementsCuisine,
  1079.                 'salleDeBain' => $salleDeBain,
  1080.                 'accessoiresDeChambre' => $accessoiresDeChambre,
  1081.                 'mobilierExterieur' => $mobilierExterieur
  1082.             ]);
  1083.         } else if ($typeHebergement == "maison" || $typeHebergement == "villa" || $typeHebergement == "camping" || $typeHebergement == "bateau" || $typeHebergement == "chalet") {
  1084.             $type $this->render('front/html/typeHebergement/maisonHebergement.html.twig', [
  1085.                 'typLocalisations' => $typLocalisations,
  1086.                 'securities' => $securities,
  1087.                 'hoteLanguages' => $hoteLanguages,
  1088.                 'equipments' => $equipments,
  1089.                 'caracteristics' => $caracteristics,
  1090.                 'equipementsCuisine' => $equipementsCuisine,
  1091.                 'salleDeBain' => $salleDeBain,
  1092.                 'accessoiresDeChambre' => $accessoiresDeChambre,
  1093.                 'mobilierExterieur' => $mobilierExterieur
  1094.             ]);
  1095.         }
  1096.         return $this->json([
  1097.             'typHebergSelected' => $typHebergSelected,
  1098.             'isHebergementHTML' => $type
  1099.         ]);
  1100.     }
  1101.     /**
  1102.      * @Route("/get-languagesAdded", name="front_company_get_languagesAdded")
  1103.      */
  1104.     public function languagesAdded(Request $requestLangueHoteRepository $langHoteRep)
  1105.     {
  1106.         $selectLanguage = [];
  1107.         if ($request->get('data')) {
  1108.             $languagesAdded json_decode($request->get('data'));
  1109.             if ($languagesAdded) {
  1110.                 foreach ($languagesAdded as $idLangue) {
  1111.                     $selectLanguage[] = $langHoteRep->find($idLangue);
  1112.                 }
  1113.             }
  1114.         }
  1115.         return $this->json([
  1116.             'selectLanguage' => $selectLanguage
  1117.         ]);
  1118.     }
  1119.     /**
  1120.      * @Route("/get-equipementsAdded", name="front_company_get_equipementsAdded")
  1121.      */
  1122.     public function equipemenstAdded(Request $requestEquipmentRepository $equipmRep)
  1123.     {
  1124.         $selectedEquipement = [];
  1125.         if ($request->get('data')) {
  1126.             $equipemenstAdded json_decode($request->get('data'));
  1127.             if (!empty($equipemenstAdded)) {
  1128.                 foreach ($equipemenstAdded as $idEqupm) {
  1129.                     $selectedEquipement[] = $equipmRep->find($idEqupm);
  1130.                 }
  1131.             }
  1132.         }
  1133.         return $this->json([
  1134.             'selectedEquipement' => $selectedEquipement
  1135.         ]);
  1136.     }
  1137.     /**
  1138.      * @Route("/get-securitiesAdded", name="front_company_get_securitiesAdded")
  1139.      */
  1140.     function securitiesAdded(Request $requestSecurityRepository $secureRep)
  1141.     {
  1142.         $selectedSecurities = [];
  1143.         if ($request->get('data')) {
  1144.             $securitiesAdded json_decode($request->get('data'));
  1145.             if (!empty($securitiesAdded)) {
  1146.                 foreach ($securitiesAdded as $idSecure) {
  1147.                     $selectedSecurities[] = $secureRep->find($idSecure);
  1148.                 }
  1149.             }
  1150.         }
  1151.         return $this->json([
  1152.             'selectedSecurities' => $selectedSecurities
  1153.         ]);
  1154.     }
  1155.     /**
  1156.      * @Route("/get-caracteristicAdded", name="front_company_get_availableCaracteristic")
  1157.      */
  1158.     public function caracteristicAdded(Request $requestCaracteristicRepository $caractikRep)
  1159.     {
  1160.         $caracteristicSelected = [];
  1161.         if ($request->get('data')) {
  1162.             $caracteristicAdded json_decode(($request->get('data')));
  1163.             if (!empty($caracteristicAdded)) {
  1164.                 foreach ($caracteristicAdded as $idCaracteristic) {
  1165.                     $caracteristicSelected[] = $caractikRep->find($idCaracteristic);
  1166.                 }
  1167.             }
  1168.         }
  1169.         return $this->json([
  1170.             'caracteristicSelected' => $caracteristicSelected
  1171.         ]);
  1172.     }
  1173.     /**
  1174.      * @Route("/get-type-prestation", name="front_company_get_typePrestation")
  1175.      */
  1176.     public function type_prestation(Request $requestTypePrestationRepository $typePrestationRepository)
  1177.     {
  1178.         if ($request->get('data')) {
  1179.             $idtypePrests json_decode($request->get('data'));
  1180.             // dd( $idtypePrests->idtypPrest);
  1181.             $id 1;
  1182.             $type $typePrestationRepository->find($idtypePrests->idtypPrest);
  1183.             $data['status'] = 200;
  1184.             $data['data'] = $type;
  1185.             return $this->json($data200, [], [
  1186.                 "groups" => "location:read"
  1187.             ]);
  1188.         } else {
  1189.             return $this->json([
  1190.                 'status' => 400
  1191.             ]);
  1192.         }
  1193.     }
  1194.     /**
  1195.      * @Route("/delete/{roomOption}/roomOption", name="front_company_delete_roomOption")
  1196.      */
  1197.     public function deleteRoomOption(Chambre $roomOption)
  1198.     {
  1199.         $entityManager $this->getDoctrine()->getManager();
  1200.         $entityManager->remove($roomOption);
  1201.         $entityManager->flush();
  1202.         return $this->json([
  1203.             'status' => 200
  1204.         ]);
  1205.     }
  1206.     /**
  1207.      * @Route("/get-litChambreData", name="front_company_get_litChambreData")
  1208.      */
  1209.     public function getLitChambreData()
  1210.     {
  1211.         $litsChambres $this->em->getRepository(LitsChambre::class)->findAll();
  1212.         $typeParticipants $this->em->getRepository(TypeParticipant::class)->findAll();
  1213.         $data['status'] = 200;
  1214.         $data['data'] = $litsChambres;
  1215.         foreach ($litsChambres as $litsChambre) {
  1216.             $slug[] = $litsChambre->getSlug();
  1217.             $type[] = $litsChambre->getType();
  1218.         }
  1219.         foreach ($typeParticipants as $typeParticipant) {
  1220.             $typeParticipantSlug[] = $typeParticipant->getSlugTypeParticipant();
  1221.             $typeParticipantType[] = $typeParticipant->getTypeParticipant();
  1222.         }
  1223.         $typeDeParticipants = array();
  1224.         for ($i 0$i count($typeParticipantSlug); $i++) {
  1225.             $typeDeParticipants[] = array(
  1226.                 'slug' => $typeParticipantSlug[$i],
  1227.                 'type' => $typeParticipantType[$i]
  1228.             );
  1229.         }
  1230.         return $this->json([
  1231.             // "groups" => "location:read",
  1232.             "slugs" => $slug,
  1233.             "types" => $type,
  1234.             "typeDeParticipants" => $typeDeParticipants
  1235.         ]);
  1236.     }
  1237.     /**
  1238.      * @Route("/transporteur/calcul-cout", name="front_front_product_calcul_transporteur", methods={"POST"})
  1239.      */
  1240.     public function getTransporteursPrice(Request $requestTransporteurWeightPriceRepository $transporteurWeightPriceRepository)
  1241.     {
  1242.         $data json_decode($request->get('data'));
  1243.         if ($data->weightProduct) {
  1244.             $transporteursWeight $transporteurWeightPriceRepository->getTransporteursPriceByWeight($data->weightProduct);
  1245.             return $this->json([
  1246.                 'transporteurs' => $this->render('front/html/form_transporteurs.html.twig', ['transporteursWeight' => $transporteursWeight])
  1247.             ]);
  1248.         }
  1249.     }
  1250.     /**
  1251.      * @Route("/transporteur/getable", name="front_front_transporteur_getable", methods={"POST"})
  1252.      */
  1253.     public function getCompanyTransporteursPrice(Request $requestTransporteurWeightPriceRepository $transporteurWeightPriceRepository)
  1254.     {
  1255.         $data json_decode($request->get('data'));
  1256.         if ($data->weightProduct) {
  1257.             //$transporteursWeight = $transporteurWeightPriceRepository->getTransporteursPriceByWeight($data->weightProduct);
  1258.             $transporteursWeight $transporteurWeightPriceRepository->getActiveTransporteursPriceByWeight($data->weightProduct);
  1259.             return $this->json([
  1260.                 'transporteurs' => $this->render('front/html/form_transporteurs.html.twig', ['transporteursWeight' => $transporteursWeight])
  1261.             ]);
  1262.         }
  1263.     }
  1264.     /**
  1265.      * @Route("option/{id}", name="Options")
  1266.      */
  1267.     public function Option(ProductOption $prodOption)
  1268.     {
  1269.         $data['options'] = $prodOption;
  1270.         // dd($data);
  1271.         return $this->json($data200, [], ['groups' => 'post:read']);
  1272.     }
  1273.     /**
  1274.      * @Route("tousoption/{id}", name="productOption")
  1275.      */
  1276.     public function prodOption(ProductOptionRepository $optiorepoProduct $productSessionInterface $session)
  1277.     {
  1278.         $optionProd $optiorepo->findProduitOptionByProduit($product);
  1279.         // dd($optionProd);
  1280.         $data['options'] = $optionProd;
  1281.         if ($session->get('products')) {
  1282.             $data['opt_pre'] = $session->get('archive');
  1283.         }
  1284.         return $this->json($data200, [], ['groups' => 'post:read']);
  1285.     }
  1286.     /**
  1287.      * @Route("tous-options-product/{id}", name="option_product")
  1288.      */
  1289.     public function option_produit(ProductOptionRepository $optiorepoProduct $productSessionInterface $session)
  1290.     {
  1291.         $optionProd $optiorepo->findProduitOptionByProduit($product);
  1292.         // dd($session->get('products'));
  1293.         // if ($session->get('products')) {
  1294.         //     $data['group_pre']=$session->get('archive');
  1295.         // }
  1296.         $optiongropeMVew =  $this->render('front/product/cart/optionHtml/row.html.twig', [
  1297.             'optiongroups' => $optionProd
  1298.         ]);
  1299.         return $this->json($optiongropeMVew->getContent());
  1300.     }
  1301.     /**
  1302.      * @Route("tous-options-groups/{id}", name="options_groups")
  1303.      */
  1304.     public function ajout_options_groups(ProductOptionRepository $optiorepoProduct $productSessionInterface $session)
  1305.     {
  1306.         $optionProd $optiorepo->findProduitOptionByProduit($product);
  1307.         // dd($product);
  1308.         if ($session->get('products')) {
  1309.             $pre_commande = [];
  1310.             foreach ($session->get('products') as $cle => $productOption) {
  1311.                 $pre_commande $productOption['options'];
  1312.                 // foreach ($productOption['options'] as $idopt => $valueOptions) {
  1313.                 //     //    $pre_commande[$idopt.'_'.$key]= $valueOption;
  1314.                 //     foreach ($valueOptions as $key => $valueOption) {
  1315.                 //         $pre_commande[$idopt][$key]=$valueOption['valeur'];
  1316.                 //     }
  1317.                 // }
  1318.             }
  1319.         }
  1320.         // dd( $pre_commande,$optionProd);
  1321.         $optiongropeMVewm =  $this->render('front/command/modifgroupbasket/modifGroup.html.twig', [
  1322.             'optiongroups' => $optionProd,
  1323.             'dansPanier' => $pre_commande,
  1324.             'produit' => $product
  1325.         ]);
  1326.         return $this->json($optiongropeMVewm->getContent());
  1327.     }
  1328.     /**
  1329.      * @Route("/hebergement/filtre{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="heb_filtre", methods={"POST"})
  1330.      */
  1331.     public function filtreHeberge(int $pageRequest $requestProductRepository $hebCaracteristicRepository $hebCarPaginatorInterface $paginatorLocationRepository $locationRepository)
  1332.     {
  1333.         // dd($request); 
  1334.         if ($request->isMethod('POST')) {
  1335.             $parameters = [
  1336.                 'prix' => $request->get('prix') ? $request->get('prix') : null,
  1337.                 'avis' => $request->get('avis') ? $request->get('avis') : null,
  1338.                 'nbrAdulte' => $request->get('nbrAdulte') ? $request->get('nbrAdulte') : null,
  1339.                 'nbrEnfant' => $request->get('nbrEnfant') ? $request->get('nbrEnfant') : null,
  1340.                 'nbrBebe' => $request->get('nbrBebe') ? $request->get('nbrBebe') : null,
  1341.                 'nbrEnfant' => $request->get('nbrEnfant') ? $request->get('nbrEnfant') : null,
  1342.                 'equipements' => $request->get('equipements') ? $request->get('equipements') : null,
  1343.                 'caracteristics' => $request->get('caracteristique') ? $request->get('caracteristique') : null,
  1344.                 'typeLocalisations' => $request->get('localisation') ? $request->get('localisation') : null,
  1345.                 'securities' => $request->get('securite') ? $request->get('securite') : null,
  1346.                 'langueHotes' => $request->get('langue') ? $request->get('langue') : null,
  1347.             ];
  1348.             // $products = $productRepository->searchProductCompany($parameters, $this->getUser());
  1349.             $products $heb->Hebergement($parameters);
  1350.         } else {
  1351.             $products $heb->findBy(['company' => $this->getUser()], ['id' => 'DESC']);
  1352.         }
  1353.         $pagination $paginator->paginate(
  1354.             $products,
  1355.             $page/*page number*/
  1356.             15 /*limit per page*/
  1357.         );
  1358.         $countService 0;
  1359.         $countProducts 0;
  1360.         foreach ($products as $key => $product) {
  1361.             $isService $product->getSubCategories()->filter(
  1362.                 function ($entry) use ($countService$countProducts) {
  1363.                     return $entry->getIsService();
  1364.                 }
  1365.             );
  1366.             if ($isService) {
  1367.                 $countService $countService 1;
  1368.             } else {
  1369.                 $countProducts $countProducts 1;
  1370.             }
  1371.         }
  1372.         // dd($products[0]->getSubCategories()->toArray());
  1373.         $categoryBackground null;
  1374.         $result $this->render('front/product/recherceHebergement.html.twig', [
  1375.             'products' => $pagination,
  1376.             'countProducts' => $countProducts,
  1377.             'countServices' => $countService,
  1378.             'categoryBackground' => $categoryBackground
  1379.         ]);
  1380.         return $this->json($result->getContent());
  1381.     }
  1382. /**
  1383.  * @Route("/get-commune", methods={"GET"}, name="get_commune")
  1384.  */
  1385. public function getCommune(Request $request): JsonResponse
  1386. {
  1387.     try {
  1388.         $page $request->query->getInt('page'1);
  1389.         $limit $request->query->getInt('limit'50);
  1390.         $searchTerm $request->query->get('q''');  // Terme de recherche
  1391.         $url 'https://geo.api.gouv.fr/communes?fields=nom,code&format=json';
  1392.         $response $this->client->request('GET'$url);
  1393.         $communes $response->toArray();
  1394.         // Filtrer les communes par le terme de recherche (si renseigné)
  1395.         if (!empty($searchTerm)) {
  1396.             $communes array_filter($communes, function ($commune) use ($searchTerm) {
  1397.                 return stripos($commune['nom'], $searchTerm) !== false;
  1398.             });
  1399.         }
  1400.         // Pagination manuelle
  1401.         $offset = ($page 1) * $limit;
  1402.         $paginatedCommunes array_slice($communes$offset$limit);
  1403.         $communeData array_map(function ($commune) {
  1404.             return [
  1405.                 'id' => $commune['code'],
  1406.                 'text' => $commune['nom']
  1407.             ];
  1408.         }, $paginatedCommunes);
  1409.         return new JsonResponse($communeDataJsonResponse::HTTP_OK);
  1410.     } catch (\Exception $e) {
  1411.         return new JsonResponse(['error' => 'Impossible de récupérer les communes'], JsonResponse::HTTP_BAD_REQUEST);
  1412.     }
  1413. }
  1414.     /**
  1415.      * @Route("/get-annonce-subcategory", name="get_annonce_subcategory", methods={"POST"})
  1416.      */
  1417.     public function getAnnonceSubcategory(Request $requestSubCategoryRepository $subCategoryRepositoryCategoryRepository $categoryRepositorySerializerInterface $serializer): JsonResponse {
  1418.         $data json_decode($request->get('data_object'));
  1419.         $subcategories = [];
  1420.         $activiteShoppingCategory $categoryRepository->findOneBy(['slug' => 'activites-shopping']);
  1421.         
  1422.         if ($data->id_type) {
  1423.             $subcategories $subCategoryRepository->getSubCategoriesByAnnonceType($data->id_type$activiteShoppingCategory);
  1424.         }
  1425.         // Serialize to JSON
  1426.         $json $serializer->serialize($subcategories'json', [
  1427.             'groups' => ["subcategory:read"], // optional, if you use serialization groups
  1428.         ]);
  1429.         return new JsonResponse($jsonJsonResponse::HTTP_OK);     
  1430.     }
  1431. }