src/Controller/Front/ProductController.php line 556

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