<?php
namespace App\Controller;
use App\Entity\Registration\Contact;
use App\Form\Registration\ContactType;
use App\Repository\Registration\ContactRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
#[Route('/', name: 'homepage')]
public function landing(): Response
{
return $this->render('landing/homepage.html.twig', [
'controller_name' => 'DefaultController',
]);
}
#[Route(path: '/partnership', name: 'partnership')]
public function partnership(): Response
{
return $this->render('landing/partnership.html.twig', [
]);
}
#[Route(path: '/technology', name: 'technology')]
public function technology(): Response
{
return $this->render('landing/technology.html.twig', [
]);
}
#[Route(path: '/consultants', name: 'consultants')]
public function consultants(): Response
{
return $this->render('landing/consultants.html.twig', [
]);
}
#[Route(path: '/corporate', name: 'corporate')]
public function corporate(): Response
{
return $this->render('landing/corporate_solutions.html.twig', [
]);
}
#[Route(path: '/financial', name: 'financial')]
public function financial(): Response
{
return $this->render('landing/financial_services.html.twig', [
]);
}
#[Route(path: '/contactUs', name: 'contactUs')]
public function contactUs(Request $request, ContactRepository $contactRepository, EntityManagerInterface $entityManager, MailerInterface $mailer): Response
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$contact->setCreatedAt(new \DateTimeImmutable('now'));
$email = (new TemplatedEmail())
->from('Odeveloper Inc <webmaster@amplexcorp.com>')
->to(new Address('guevararafnela@gmail.com'))
->subject('New contact registered')
->htmlTemplate('landing/email_new_contact.html.twig')
->context([
'name' => $contact->getFullName(),
'correo' => $contact->getEmail(),
'phone' => $contact->getPhone(),
'message' => $contact->getMessage()
])
;
$mailer->send($email);
$entityManager->persist($contact);
$entityManager->flush();
return $this->redirectToRoute('successful_registration');
}
return $this->render('landing/contact_us.html.twig', [
'form' => $form->createView()
]);
}
#[Route(path: '/successful_registration', name: 'successful_registration')]
public function successful_registration(): Response
{
return $this->render('landing/successful_registration.html.twig', [
]);
}
}