src/Controller/Front/ProductController.php line 463

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