src/Controller/HomePageController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Banners;
  4. use App\Entity\Products;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Mailer\MailerInterface;
  11. use Symfony\Component\Mime\Email;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class HomePageController extends AbstractController
  14. {
  15.     private $em;
  16.     public function __construct(EntityManagerInterface $em)
  17.     {
  18.         $this->em $em;
  19.     }
  20.     #[Route('/'name'home_page')]
  21.     public function index(): Response
  22.     {
  23.         $banners $this->em->getRepository(Banners::class)->findHomePage();
  24.         $products $this->em->getRepository(Products::class)->findByRand();
  25.         return $this->render('frontend/index.html.twig', [
  26.             'banners' => $banners,
  27.             'products' => $products,
  28.         ]);
  29.     }
  30.     #[Route('/contact-form'name'contact_form')]
  31.     public function contactForm(Request $requestMailerInterface $mailer): Response
  32.     {
  33.         $data $request->request;
  34.         $name $data->get('name');
  35.         $telephone $data->get('telephone');
  36.         $email $data->get('email');
  37.         $message $data->get('message');
  38.         $html '
  39.         <table border="0" cellpadding="8" cellspacing="0">
  40.             <tr>
  41.                 <td colspan="2">
  42.                     <h3>Fluid Enquiry</h3>
  43.                 </td>
  44.             </tr>
  45.             <tr>
  46.                 <td colspan="2">&nbsp;</td>
  47.             </tr>
  48.             <tr>
  49.                 <td>
  50.                     <b>Date: </b>
  51.                 </td>
  52.                 <td>
  53.                     'date('Y-m-d H:i') .'
  54.                 </td>
  55.             </tr>
  56.             <tr>
  57.                 <td>
  58.                     <b>Name: </b>
  59.                 </td>
  60.                 <td>
  61.                     '$name .'
  62.                 </td>
  63.             </tr>
  64.             <tr>
  65.                 <td>
  66.                     <b>Telephone: </b>
  67.                 </td>
  68.                 <td>
  69.                     '$telephone .'
  70.                 </td>
  71.             </tr>
  72.             <tr>
  73.                 <td>
  74.                     <b>Email: </b>
  75.                 </td>
  76.                 <td>
  77.                     '$email .'
  78.                 </td>
  79.             </tr>
  80.             <tr>
  81.                 <td valign="top">
  82.                     <b>Message:</b>
  83.                 </td>
  84.                 <td>
  85.                     '$message .'
  86.                 </td>
  87.             </tr>
  88.         </table>
  89.         ';
  90.         $body $this->forward('App\Controller\ResetPasswordController::emailFooter', [
  91.             'html'  => $html,
  92.         ])->getContent();
  93.         $subject 'Fluid General Enquiry';
  94.         exec(__DIR__ '/../../bin/console app:send-email "'$subject .'" "'addslashes($body) .'" "'$this->getParameter('app.email_admin') .'" "'serialize([]) .'" "'serialize([]) .'" "'true .'" > /dev/null 2>&1 &');
  95.         $flash '<b><i class="fas fa-check-circle"></i> Enquiry successfully sent.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  96.         return new JsonResponse($flash);
  97.     }
  98.     #[Route('/error'name'frontend_error_500')]
  99.     public function frontend500ErrorAction(Request $request): Response
  100.     {
  101.         return $this->render('bundles/TwigBundle/Exception/error500.html.twig', [
  102.             'type' => 'frontend',
  103.             'id' => 0,
  104.         ]);
  105.     }
  106. }