<?php
namespace App\Controller;
use App\Entity\Annonce;
use App\Entity\AnnonceSearch;
use App\Entity\Type;
use App\Form\AnnonceSearchType;
use App\Repository\AnnonceRepository;
use App\Repository\CategorieRepository;
use App\Repository\TypeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* @Route("/")
* * @Route("/home", name="app_home")
*/
public function index(CategorieRepository $categorieRepository, TypeRepository $typeRepository, AnnonceRepository $annonceRepository): Response
{
return $this->render('home/index.html.twig', [
'types' => $typeRepository->findAll(),
'categories' => $categorieRepository->findAll(),
'annonces' => $annonceRepository->findAll()
]);
}
/**
* * @Route("/liste", name="app_liste")
*/
public function liste(Request $request, CategorieRepository $categorieRepository, TypeRepository $typeRepository, AnnonceRepository $annonceRepository): Response
{
$search = new AnnonceSearch();
$form=$this->createForm(AnnonceSearchType::class, $search);
$form->handleRequest($request);
$annonces = $annonceRepository->findAllVisibleQuery($search)->getResult();
return $this->render('home/listeannonce.html.twig', [
'types' => $typeRepository->findAll(),
'categories' => $categorieRepository->findAll(),
'annonces' => $annonces,
'form' =>$form->createView()
]);
}
/**
* * @Route("/annonce/{id}", name="details_annonce")
*/
public function detailsannonce(CategorieRepository $categorieRepository, TypeRepository $typeRepository, Annonce $annonce): Response
{
if ($annonce->getGeneral() != null) {
$general = implode(' ', array_column(json_decode($annonce->getGeneral()), 'value'));
$generals = explode(" ", $general);
} else {
$generals = [];
}
if ($annonce->getEspext()) {
$espext = implode(' ', array_column(json_decode($annonce->getEspext()), 'value'));
$espexts = explode(" ", $espext);
} else {
$espexts = [];
}
if ($annonce->getParking() != null) {
$parking = implode(' ', array_column(json_decode($annonce->getParking()), 'value'));
$parkings = explode(" ", $parking);
} else {
$parkings = [];
}
if ($annonce->getChauffage() != null) {
$chauffage = implode(' ', array_column(json_decode($annonce->getChauffage()), 'value'));
$chauffages = explode(" ", $chauffage);
} else {
$chauffages = [];
}
if ($annonce->getCuisine() != null) {
$cuisine = implode(' ', array_column(json_decode($annonce->getCuisine()), 'value'));
$cuisines = explode(" ", $cuisine);
} else {
$cuisines = [];
}
if ($annonce->getClimatisation() != null) {
$climatisation = implode(' ', array_column(json_decode($annonce->getClimatisation()), 'value'));
$climatisations = explode(" ", $climatisation);
} else {
$climatisations = [];
}
return $this->render('home/detailsannonce.html.twig', [
'types' => $typeRepository->findAll(),
'categories' => $categorieRepository->findAll(),
'annonce' => $annonce,
'generals' => $generals,
'espexts' => $espexts,
'parkings' => $parkings,
'chauffages' => $chauffages,
'cuisines' => $cuisines,
'climatisations' => $climatisations,
]);
}
/**
* * @Route("/liste/type/{id}/{categorie}", name="app_liste_type")
*/
public function listetype(Request $request, CategorieRepository $categorieRepository, Type $type, TypeRepository $typeRepository, AnnonceRepository $annonceRepository): Response
{
$categorie = $categorieRepository->findOneBy(['nom' => $request->get('categorie')]);
return $this->render('home/listeannoncetype.html.twig', [
'types' => $typeRepository->findAll(),
'categories' => $categorieRepository->findAll(),
'annonces' => $annonceRepository->findBy(['type' => $type, 'categorie' => $categorie])
]);
}
/**
* @Route("/sendmessage", name="sendmessage")
*/
public function sendmessage(Request $request, \Swift_Mailer $mailer, AnnonceRepository $annonceRepository): Response
{
$annonce = $annonceRepository->findOneBy(['id' => $request->get('idannonce')]);
$tel = $annonce->getPublierpar()->getTel();
$email = $annonce->getPublierpar()->getEmail();
$nom = $annonce->getPublierpar()->getNom();
$msg = $request->get('message');
$message = (new \Swift_Message($annonce->getTitre()))
->setFrom($email)
->setTo('innoyadev@gmail.com')
->setBody('
<html><body>
<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>
<tr><td height="30" colspan="2" align=
"left" valign="middle"><span style="font-family:Arial;font-size:16px;font-weight:600;color:#006699"> Détails d\'émail - Depuis le Site Web</span>
</td></tr>
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Nom & Prénom : </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . $nom . '</span></td></tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Email : </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px">' . $email . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Téléphone: </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . nl2br($tel) . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Message: </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . nl2br($msg) . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
</tbody></table>
</body></html>
', 'text/html');
$mailer->send($message);
return new JsonResponse('true');
}
/**
* * @Route("/contact", name="app_contact")
*/
public function contact(CategorieRepository $categorieRepository, TypeRepository $typeRepository, AnnonceRepository $annonceRepository): Response
{
return $this->render('home/contact.html.twig', [
'types' => $typeRepository->findAll(),
'categories' => $categorieRepository->findAll(),
'annonces' => $annonceRepository->findAll()
]);
}
/**
* @Route("/sendmsg", name="sendmsg")
*/
public function sendmsg(Request $request, \Swift_Mailer $mailer, AnnonceRepository $annonceRepository): Response
{
$email = $request->get('email');
$objet =$request->get('subject');
$nom = $request->get('name');
$msg = $request->get('message');
$message = (new \Swift_Message($objet))
->setFrom($email)
->setTo('innoyadev@gmail.com')
->setBody('
<html><body>
<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>
<tr><td height="30" colspan="2" align=
"left" valign="middle"><span style="font-family:Arial;font-size:16px;font-weight:600;color:#006699"> Détails d\'émail - Depuis le Site Web</span>
</td></tr>
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Nom & Prénom : </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . $nom . '</span></td></tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Email : </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px">' . $email . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Objet: </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . nl2br($objet) . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
<tr>
<td width="10%" valign="top">
<span style="font-family:Arial;font-size:14px;line-height:22px">Message: </span>
</td>
<td width="50%" valign="top">
<span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' . nl2br($msg) . '</span>
</td>
</tr>
<hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
</tbody></table>
</body></html>
', 'text/html');
$mailer->send($message);
return new JsonResponse('true');
}
}