src/Controller/PageController.php line 29
<?php
namespace App\Controller;
use App\Form\ContactType;
use Symfony\Component\Mime\Email;
use App\Repository\PageRepository;
use App\Repository\VenteRepository;
use Symfony\Component\Mime\Address;
use App\Repository\AvocatRepository;
use App\Repository\CabinetRepository;
use App\Repository\DomaineRepository;
use App\Repository\SettingRepository;
use App\Repository\CategoryRepository;
use App\Repository\HomepageRepository;
use App\Repository\HonoraireRepository;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PageController extends AbstractController
{
/* Page Ventes immobilière pour pagination */
#[Route('/ventes-immobilieres/ventes', name: 'app_page_vente')]
public function pagevente(
SettingRepository $settingRepository,
HomepageRepository $homepageRepository,
PageRepository $pageRepository,
CategoryRepository $categoryRepository,
VenteRepository $venteRepository,
Request $request,
PaginatorInterface $paginator,
EntityManagerInterface $em
): Response
{
// Pathinfo de la page
$pathInfo = $request->getPathInfo();
// Pagination Ventes Immobilières
$dql = "SELECT v FROM App:Vente v";
$query = $em->createQuery($dql);
$ventes = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
6 /*limit per page*/
);
return $this->render('pages/page.ventes.html.twig', [
'pageTitle' => 'ventes',
'settings' => $settingRepository->findAll(),
'homepage' => $homepageRepository->findAll(),
'pages' => $pageRepository->findBy(['isEnabled' => true], []),
'page' => $pageRepository->findByPage('ventes'),
'categories' => $categoryRepository->findAll(),
'ventes' => $ventes,
'pathInfo' =>$pathInfo
]);
}
/* Page Ventes immobilières Détails */
#[Route('/ventes-immobilieres/{page}/{id}', name: 'app_page_vente_show')]
public function vente(
SettingRepository $settingRepository,
HomepageRepository $homepageRepository,
PageRepository $pageRepository,
CategoryRepository $categoryRepository,
VenteRepository $venteRepository,
Request $request,
$page,
$id
): Response
{
// Pathinfo de la page
$pathInfo = $request->getPathInfo();
return $this->render('pages/page.vente-details.html.twig', [
'pageTitle' => $page,
'settings' => $settingRepository->findAll(),
'homepage' => $homepageRepository->findAll(),
'pages' => $pageRepository->findBy(['isEnabled' => true], []),
'page' => $pageRepository->findByPage($page),
'categories' => $categoryRepository->findAll(),
'ventes' => $venteRepository->findAll(),
'vente' => $venteRepository->findByVente($id),
'pathInfo' =>$pathInfo,
]);
}
/* Page Avocat Détails */
#[Route('/lequipe/{page}/{nom}', name: 'app_page_avocat_show')]
public function avocat(
SettingRepository $settingRepository,
HomepageRepository $homepageRepository,
PageRepository $pageRepository,
CategoryRepository $categoryRepository,
AvocatRepository $avocatRepository,
Request $request,
$page,
$nom
): Response
{
// Pathinfo de la page
$pathInfo = $request->getPathInfo();
return $this->render('pages/page.avocat-details.html.twig', [
'pageTitle' => $page,
'settings' => $settingRepository->findAll(),
'homepage' => $homepageRepository->findAll(),
'pages' => $pageRepository->findBy(['isEnabled' => true], []),
'page' => $pageRepository->findByPage($page),
'categories' => $categoryRepository->findAll(),
'avocats' => $avocatRepository->findBy([], ['sortOrder' => 'ASC']),
'avocat' => $avocatRepository->findByAvocat($nom),
'pathInfo' =>$pathInfo,
]);
}
/* Les pages - route généraliste */
#[Route('/{cat}/{page}', name: 'app_page')]
public function index(
SettingRepository $settingRepository,
PageRepository $pageRepository,
CategoryRepository $categoryRepository,
HomepageRepository $homepageRepository,
AvocatRepository $avocatRepository,
DomaineRepository $domaineRepository,
CabinetRepository $cabinetRepository,
HonoraireRepository $honoraireRepository,
Request $request,
PaginatorInterface $paginator,
EntityManagerInterface $em,
MailerInterface $mailer,
$page,
$cat
): Response
{
// Dossier du template de la page
$pageTemplate = 'pages/page.' . $page . '.html.twig';
// Pathinfo de la page
$pathInfo = $request->getPathInfo();
// // Pagination Ventes Immobilières
// $dql = "SELECT v FROM App:Vente v";
// $query = $em->createQuery($dql);
// $ventes = $paginator->paginate(
// $query, /* query NOT result */
// $request->query->getInt('page', 1), /*page number*/
// 6 /*limit per page*/
// );
// Page contact
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
// On recherche l'email et le nom du site dans Setting
// pour injecter dans le mail
$dataMail = $settingRepository->findAll();
$siteEmail = $dataMail[0]->getSiteEmail();
$siteName = $dataMail[0]->getSiteName();
$siteUrl = $dataMail[0]->getSiteUrl();
if ($form->isSubmitted() && $form->isValid()) {
$contactFormData = $form->getData();
// Si le champ adresse est rempli...
if ($contactFormData['email'] != null) {
// On met l'adresse de la personne
$emailOrig = $contactFormData['email'];
} else {
// Sinon on met l'adresse du site
$emailOrig = 'noreply@gerigny-associes.com';
}
$email = (new Email())
//->from($contactFormData['email'])
->from($emailOrig)
->to(new Address($siteEmail, $siteName))
->subject('Message depuis ' . $siteUrl . ' : ' . $contactFormData['sujet'])
->html(
'<h4 style="color: #153860; font-weight: bold;">Message envoyé depuis le site web ' . $siteUrl . '</h4>' .
'<span style="color: #153860; font-weight: bold;">De :</span> ' . $contactFormData['prenom'] . ' ' . $contactFormData['nom'] . '<br>' .
'<span style="color: #153860; font-weight: bold;">E-mail :</span> ' . $contactFormData['email'] . '<br>' .
'<span style="color: #153860; font-weight: bold;">Sujet : </span> ' . $contactFormData['sujet'] . '<br>' .
'<span style="color: #153860; font-weight: bold;">Téléphone : </span> ' . $contactFormData['telephone'] .
'<p><span style="color: #153860; font-weight: bold;">Message</span> : <br>' . $contactFormData['message'] . '</p>',
'text/plain'
);
;
$mailer->send($email);
$this->addFlash('success', 'Le message a bien été envoyé !');
return $this->redirect('/contact/contactez-nous');
}
return $this->render($pageTemplate, [
'settings' => $settingRepository->findAll(),
'pages' => $pageRepository->findBy(['isEnabled' => true], []),
'page' => $pageRepository->findByPage($page),
'category' => $categoryRepository->findByCat($cat),
'categories' => $categoryRepository->findAll(),
'pageTitle' => $page,
'pathInfo' =>$pathInfo,
'homepage' => $homepageRepository->findAll(),
'avocats' => $avocatRepository->findBy([], ['sortOrder' => 'ASC']),
'domaines' => $domaineRepository->findAll(),
'cabinets' => $cabinetRepository->findAll(),
// 'ventes' => $ventes,
'honoraires' => $honoraireRepository->findAll(),
'form' => $form->createView(),
]);
}
}