Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
www.humitest.fr
/
htdocs
/
src
/
Controller
/
front
/
/srv/data/web/vhosts/www.humitest.fr/htdocs/src/Controller/front/PagesController.php
<?php namespace App\Controller\front; use App\Entity\Page; use App\Entity\Contact; use App\Services\Mailer; use App\Entity\Propertie; use App\Form\ContactType; use App\Form\ProductType; use App\Entity\Recruitment; use App\Form\RecruitmentType; use App\Form\ProductFilterType; use App\Repository\UserRepository; use App\Repository\SliderRepository; use App\Repository\ProductRepository; use App\Repository\CategoryRepository; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class PagesController extends AbstractController { /** * @Route("/", name="home") */ public function index(ProductRepository $productRepository, SliderRepository $sliderRepository, CategoryRepository $categoryRepository): Response { $Flagship = $productRepository->isFlagship(); // dd('hello'); $searchForm = $this->createForm(ProductFilterType::class, null, [ 'csrf_protection' => false, 'method' => 'GET', 'translation_domain' => 'front_messages', 'action' => $this->generateUrl('product_all', ['page' => 1]), ]) ->add('search', TextType::class, [ 'label' => false, 'attr' => [ 'placeholder' => 'Rechercher un produit', ], 'required' => false, ])->remove('number_by_page'); return $this->render('front/pages/index.html.twig', [ 'sliders' => $sliderRepository->findAll(), 'categories' => $categoryRepository->findAll(), 'products' => $productRepository->findBy(['isActive' => true], ['updatedAt' => 'DESC'], 6), 'isFlagship' => $Flagship, 'slug' => 'home', 'product_search_form' => $searchForm->createView(), ]); } /** * @Route("/search-product-yvi", name="ajax_search",methods={"GET"}) */ public function searchAction(Request $request, ProductRepository $productRepository) { // $em = $this->getDoctrine()->getManager(); // // https://gist.github.com/aimeric/f98af4a3f728bea9e3c9a0918d2a7e2b // https://stackoverflow.com/questions/48897415/render-view-and-new-json-response-in-symfony-controller $requestString = $request->get('q'); $products = $productRepository->findProductsByString($requestString); if (!$products) { $result['products']['error'] = "Aucune entrée trouvée"; } else { $result['products'] = $this->getRealEntities($products); } // $result_ = new Response(json_encode($result)); // return new Response(json_encode($result)); return $this->render('front/pages/searchProduct.html.twig', [ 'result' => new Response(json_encode($result)), ]); // return new JsonResponse([ // // 'result' => json_encode($result), // 'html' => $this->renderView('front/pages/searchProduct.html.twig', []/* template parameters goes here */), // ]); } public function getRealEntities($products) { foreach ($products as $product) { $realEntities[$product->getId()] = $product->getTitle(); } return $realEntities; } /** * @Route("/contact", name="contact", methods="GET|POST") */ public function contact(UserRepository $userRepository, Request $request, Mailer $mailer): Response { $contact = new Contact(); $form = $this->createForm(ContactType::class, $contact); $form->handleRequest($request); // $error_captcha = false; if ($form->isSubmitted() && $form->isValid()) { // $donnee = [ //vérification du captcha // 'secret' => '6LdVeSgoAAAAAMLOMKaquY5bPr1EuvJoLw5EKkWF', // 'response' => @$_POST['g-recaptcha-response'] // ]; // $curl = curl_init(); // curl_setopt($curl, CURLOPT_POST, true); // curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify'); // curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($donnee)); // $response = curl_exec($curl); // $response = json_decode($response, true); // if ($response['success'] === true) { $em = $this->getDoctrine()->getManager(); $em->persist($contact); $conf_company_name = $this->getParameter('conf_company_name'); $conf_company_email = $this->getParameter('conf_company_email'); $conf_company_email2 = $this->getParameter('conf_company_email2'); $conf_server_email = $this->getParameter('conf_server_email'); $contactType = $contact->getType(); $contactName = $contact->getFirstName() . ' ' . $contact->getLastName(); $contactEmail = $contact->getEmail(); $contactPhone = $contact->getPhone(); $contactMessage = $contact->getMessage(); $em->flush(); // on utilise le service Mailer créé $em->flush();récédemment $bodyMailConfirmation = $mailer->createBodyMail('front/pages/mail/mail_confirmation.html.twig', [ 'conf_company_name' => $conf_company_name, 'contact_name' => $contactName, ]); $mailer->sendMessage($conf_company_name, $conf_server_email, $contact->getEmail(), 'Confirmation - ' . $conf_company_name, $bodyMailConfirmation); // on utilise le service Mailer créé précédemment $bodyMailContact = $mailer->createBodyMail('front/pages/mail/mail_contact.html.twig', [ 'contact_type' => $contactType, 'contact_name' => $contactName, 'contact_email' => $contactEmail, 'contact_phone' => $contactPhone, 'contact_message' => $contactMessage, 'conf_company_name' => $conf_company_name, ]); $mailer->sendMessage($conf_company_name, $conf_server_email, $conf_company_email, 'Contact - ' . $conf_company_name, $bodyMailContact, $conf_company_email2); $this->addFlash('success', 'Message reçu ! Nous vous recontactons dans les plus brefs délais le temps de préparer une réponse ou une offre adaptée à votre besoin.'); return $this->redirectToRoute('home'); // } else { // $error_captcha = true; // } } return $this->render('front/pages/contact.html.twig', [ 'slug' => 'contact', 'form' => $form->createView(), // "captcha_error" => $error_captcha ]); } // /** // * @Route("/{id}/{title}", name="page_read", methods="GET" , requirements={"id"="\d+"}) // */ // public function read(Page $page): Response // { // return $this->render('front/pages/read.html.twig', [ // 'page' => $page, // 'slug' => 'page', // ]); // } /** * @Route("/qui-sommes-nous", name="qui-sommes-nous") */ public function qui_sommes_nous() { return $this->render('front/pages/qui-sommes-nous.html.twig', [ 'slug' => 'qui-sommes-nous', ]); } /** * @Route("/references", name="references") */ public function references() { return $this->render('front/pages/references.html.twig', [ 'slug' => 'references', ]); } /** * @Route("/conditions-generales-de-ventes/", name="condition-vente") */ public function condition_vente() { return $this->render('front/pages/condition-vente.html.twig', [ 'slug' => 'condition-vente', ]); } /** * @Route("/mentions-legales/", name="mentions-legales") */ public function mentions_legales() { return $this->render('front/pages/mentions-legales.html.twig', [ 'slug' => 'mentions-legales', ]); } /** * @Route("/politique-de-confidentialite", name="politique-de-confidentialite") */ public function politiqueConfidentiaolite() { return $this->render('front/pages/politique-de-confidentialite.html.twig', [ 'slug' => 'politique-de-confidentialite', ]); } }