src/Controller/DefaultController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Registration\Contact;
  4. use App\Form\Registration\ContactType;
  5. use App\Repository\Registration\ContactRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Mailer\MailerInterface;
  12. use Symfony\Component\Mime\Address;
  13. use Symfony\Component\Mime\Email;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class DefaultController extends AbstractController
  16. {
  17.     #[Route('/'name'homepage')]
  18.     public function landing(): Response
  19.     {
  20.         return $this->render('landing/homepage.html.twig', [
  21.             'controller_name' => 'DefaultController',
  22.         ]);
  23.     }
  24.     #[Route(path'/partnership'name'partnership')]
  25.     public function partnership(): Response
  26.     {
  27.         return $this->render('landing/partnership.html.twig', [
  28.         ]);
  29.     }
  30.     #[Route(path'/technology'name'technology')]
  31.     public function technology(): Response
  32.     {
  33.         return $this->render('landing/technology.html.twig', [
  34.         ]);
  35.     }
  36.     #[Route(path'/consultants'name'consultants')]
  37.     public function consultants(): Response
  38.     {
  39.         return $this->render('landing/consultants.html.twig', [
  40.         ]);
  41.     }
  42.     
  43.     #[Route(path'/corporate'name'corporate')]
  44.     public function corporate(): Response
  45.     {
  46.         return $this->render('landing/corporate_solutions.html.twig', [
  47.         ]);
  48.     }
  49.     #[Route(path'/financial'name'financial')]
  50.     public function financial(): Response
  51.     {
  52.         return $this->render('landing/financial_services.html.twig', [
  53.         ]);
  54.     }
  55.     #[Route(path'/contactUs'name'contactUs')]
  56.     public function contactUs(Request $requestContactRepository $contactRepositoryEntityManagerInterface $entityManagerMailerInterface $mailer): Response
  57.     {
  58.         $contact = new Contact();
  59.         $form $this->createForm(ContactType::class, $contact);
  60.         $form->handleRequest($request);
  61.         if ($form->isSubmitted() && $form->isValid()) {
  62.             $contact->setCreatedAt(new \DateTimeImmutable('now'));
  63.             $email = (new TemplatedEmail())
  64.                 ->from('Odeveloper Inc <webmaster@amplexcorp.com>')
  65.                 ->to(new Address('guevararafnela@gmail.com'))
  66.                 ->subject('New contact registered')
  67.                 ->htmlTemplate('landing/email_new_contact.html.twig')
  68.                 ->context([
  69.                     'name' => $contact->getFullName(),
  70.                     'correo' => $contact->getEmail(),
  71.                     'phone' => $contact->getPhone(),
  72.                     'message' => $contact->getMessage() 
  73.                 ])
  74.             ;
  75.     
  76.             $mailer->send($email);
  77.             $entityManager->persist($contact);
  78.             $entityManager->flush();
  79.            
  80.             return $this->redirectToRoute('successful_registration');
  81.         }
  82.         return $this->render('landing/contact_us.html.twig', [
  83.             'form' => $form->createView()
  84.         ]);
  85.     }
  86.     #[Route(path'/successful_registration'name'successful_registration')]
  87.     public function successful_registration(): Response
  88.     {
  89.         return $this->render('landing/successful_registration.html.twig', [
  90.         ]);
  91.     }
  92. }