src/Controller/HomeController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Annonce;
  4. use App\Entity\AnnonceSearch;
  5. use App\Entity\Type;
  6. use App\Form\AnnonceSearchType;
  7. use App\Repository\AnnonceRepository;
  8. use App\Repository\CategorieRepository;
  9. use App\Repository\TypeRepository;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class HomeController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/")
  19.      * * @Route("/home", name="app_home")
  20.      */
  21.     public function index(CategorieRepository $categorieRepositoryTypeRepository $typeRepositoryAnnonceRepository $annonceRepository): Response
  22.     {
  23.         return $this->render('home/index.html.twig', [
  24.             'types' => $typeRepository->findAll(),
  25.             'categories' => $categorieRepository->findAll(),
  26.             'annonces' => $annonceRepository->findAll()
  27.         ]);
  28.     }
  29.     /**
  30.      * * @Route("/liste", name="app_liste")
  31.      */
  32.     public function liste(Request $requestCategorieRepository $categorieRepositoryTypeRepository $typeRepositoryAnnonceRepository $annonceRepository): Response
  33.     {
  34.         $search = new AnnonceSearch();
  35.         $form=$this->createForm(AnnonceSearchType::class, $search);
  36.         $form->handleRequest($request);
  37.         $annonces $annonceRepository->findAllVisibleQuery($search)->getResult();
  38.         return $this->render('home/listeannonce.html.twig', [
  39.             'types' => $typeRepository->findAll(),
  40.             'categories' => $categorieRepository->findAll(),
  41.             'annonces' => $annonces,
  42.             'form' =>$form->createView()
  43.         ]);
  44.     }
  45.     /**
  46.      * * @Route("/annonce/{id}", name="details_annonce")
  47.      */
  48.     public function detailsannonce(CategorieRepository $categorieRepositoryTypeRepository $typeRepositoryAnnonce $annonce): Response
  49.     {
  50.         if ($annonce->getGeneral() != null) {
  51.             $general implode(' 'array_column(json_decode($annonce->getGeneral()), 'value'));
  52.             $generals explode(" "$general);
  53.         } else {
  54.             $generals = [];
  55.         }
  56.         if ($annonce->getEspext()) {
  57.             $espext implode(' 'array_column(json_decode($annonce->getEspext()), 'value'));
  58.             $espexts explode(" "$espext);
  59.         } else {
  60.             $espexts = [];
  61.         }
  62.         if ($annonce->getParking() != null) {
  63.             $parking implode(' 'array_column(json_decode($annonce->getParking()), 'value'));
  64.             $parkings explode(" "$parking);
  65.         } else {
  66.             $parkings = [];
  67.         }
  68.         if ($annonce->getChauffage() != null) {
  69.             $chauffage implode(' 'array_column(json_decode($annonce->getChauffage()), 'value'));
  70.             $chauffages explode(" "$chauffage);
  71.         } else {
  72.             $chauffages = [];
  73.         }
  74.         if ($annonce->getCuisine() != null) {
  75.             $cuisine implode(' 'array_column(json_decode($annonce->getCuisine()), 'value'));
  76.             $cuisines explode(" "$cuisine);
  77.         } else {
  78.             $cuisines = [];
  79.         }
  80.         if ($annonce->getClimatisation() != null) {
  81.             $climatisation implode(' 'array_column(json_decode($annonce->getClimatisation()), 'value'));
  82.             $climatisations explode(" "$climatisation);
  83.         } else {
  84.             $climatisations = [];
  85.         }
  86.         return $this->render('home/detailsannonce.html.twig', [
  87.             'types' => $typeRepository->findAll(),
  88.             'categories' => $categorieRepository->findAll(),
  89.             'annonce' => $annonce,
  90.             'generals' => $generals,
  91.             'espexts' => $espexts,
  92.             'parkings' => $parkings,
  93.             'chauffages' => $chauffages,
  94.             'cuisines' => $cuisines,
  95.             'climatisations' => $climatisations,
  96.         ]);
  97.     }
  98.     /**
  99.      * * @Route("/liste/type/{id}/{categorie}", name="app_liste_type")
  100.      */
  101.     public function listetype(Request $requestCategorieRepository $categorieRepositoryType $typeTypeRepository $typeRepositoryAnnonceRepository $annonceRepository): Response
  102.     {
  103.         $categorie $categorieRepository->findOneBy(['nom' => $request->get('categorie')]);
  104.         return $this->render('home/listeannoncetype.html.twig', [
  105.             'types' => $typeRepository->findAll(),
  106.             'categories' => $categorieRepository->findAll(),
  107.             'annonces' => $annonceRepository->findBy(['type' => $type'categorie' => $categorie])
  108.         ]);
  109.     }
  110.     /**
  111.      * @Route("/sendmessage", name="sendmessage")
  112.      */
  113.     public function sendmessage(Request $request, \Swift_Mailer $mailerAnnonceRepository $annonceRepository): Response
  114.     {
  115.         $annonce $annonceRepository->findOneBy(['id' => $request->get('idannonce')]);
  116.         $tel $annonce->getPublierpar()->getTel();
  117.         $email $annonce->getPublierpar()->getEmail();
  118.         $nom $annonce->getPublierpar()->getNom();
  119.         $msg $request->get('message');
  120.         $message = (new \Swift_Message($annonce->getTitre()))
  121.             ->setFrom($email)
  122.             ->setTo('innoyadev@gmail.com')
  123.             ->setBody('
  124. <html><body>
  125.   
  126. <table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>
  127.   <tr><td height="30" colspan="2" align=
  128. "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>
  129. </td></tr>
  130. <tr>
  131. <td width="10%" valign="top">
  132.  <span style="font-family:Arial;font-size:14px;line-height:22px">Nom & Prénom : </span>
  133.  </td>
  134.  <td width="50%" valign="top">
  135.                          <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' $nom '</span></td></tr>
  136. <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  137. <tr>
  138.                        <td width="10%" valign="top">
  139.                            <span style="font-family:Arial;font-size:14px;line-height:22px">Email : </span>
  140.                        </td>
  141.                        <td width="50%" valign="top">
  142.                          <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px">' $email '</span>
  143.                        </td>
  144.                      </tr>
  145.                      
  146.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  147.                             <tr>
  148.                              <td width="10%" valign="top">
  149.                                <span style="font-family:Arial;font-size:14px;line-height:22px">Téléphone: </span>
  150.                              </td>
  151.                              <td width="50%" valign="top">
  152.                                <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' nl2br($tel) . '</span>
  153.                              </td>
  154.                            </tr> 
  155.                           
  156.                            
  157.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee"> 
  158.                             <tr>
  159.                              <td width="10%" valign="top">
  160.                                <span style="font-family:Arial;font-size:14px;line-height:22px">Message: </span>
  161.                              </td>
  162.                              <td width="50%" valign="top">
  163.                                <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' nl2br($msg) . '</span>
  164.                              </td>
  165.                            </tr>    
  166.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  167.                            </tbody></table>
  168. </body></html>
  169. ''text/html');
  170.         $mailer->send($message);
  171.         return new JsonResponse('true');
  172.     }
  173.     /**
  174.      * * @Route("/contact", name="app_contact")
  175.      */
  176.     public function contact(CategorieRepository $categorieRepositoryTypeRepository $typeRepositoryAnnonceRepository $annonceRepository): Response
  177.     {
  178.         return $this->render('home/contact.html.twig', [
  179.             'types' => $typeRepository->findAll(),
  180.             'categories' => $categorieRepository->findAll(),
  181.             'annonces' => $annonceRepository->findAll()
  182.         ]);
  183.     }
  184.     /**
  185.      * @Route("/sendmsg", name="sendmsg")
  186.      */
  187.     public function sendmsg(Request $request, \Swift_Mailer $mailerAnnonceRepository $annonceRepository): Response
  188.     {
  189.         $email $request->get('email');
  190.         $objet =$request->get('subject');
  191.         $nom $request->get('name');
  192.         $msg $request->get('message');
  193.         $message = (new \Swift_Message($objet))
  194.             ->setFrom($email)
  195.             ->setTo('innoyadev@gmail.com')
  196.             ->setBody('
  197. <html><body>
  198.   
  199. <table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>
  200.   <tr><td height="30" colspan="2" align=
  201. "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>
  202. </td></tr>
  203. <tr>
  204. <td width="10%" valign="top">
  205.  <span style="font-family:Arial;font-size:14px;line-height:22px">Nom & Prénom : </span>
  206.  </td>
  207.  <td width="50%" valign="top">
  208.                          <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' $nom '</span></td></tr>
  209. <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  210. <tr>
  211.                        <td width="10%" valign="top">
  212.                            <span style="font-family:Arial;font-size:14px;line-height:22px">Email : </span>
  213.                        </td>
  214.                        <td width="50%" valign="top">
  215.                          <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px">' $email '</span>
  216.                        </td>
  217.                      </tr>
  218.                      
  219.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  220.                             <tr>
  221.                              <td width="10%" valign="top">
  222.                                <span style="font-family:Arial;font-size:14px;line-height:22px">Objet: </span>
  223.                              </td>
  224.                              <td width="50%" valign="top">
  225.                                <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' nl2br($objet) . '</span>
  226.                              </td>
  227.                            </tr> 
  228.                           
  229.                            
  230.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee"> 
  231.                             <tr>
  232.                              <td width="10%" valign="top">
  233.                                <span style="font-family:Arial;font-size:14px;line-height:22px">Message: </span>
  234.                              </td>
  235.                              <td width="50%" valign="top">
  236.                                <span style="font-family:Arial;font-size:14px;font-weight:600;line-height:22px"> ' nl2br($msg) . '</span>
  237.                              </td>
  238.                            </tr>    
  239.                            <hr style="margin-top:10px;margin-bottom:10px;border:0;border-top:1px solid #eee">
  240.                            </tbody></table>
  241. </body></html>
  242. ''text/html');
  243.         $mailer->send($message);
  244.         return new JsonResponse('true');
  245.     }
  246. }