src/Controller/Website/LayoutController.php line 77

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Website;
  3. use App\Repository\PropertyRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use App\Manager\TypeManager;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use App\Service\DocumentManagerService;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class LayoutController extends AbstractController
  12. {
  13.     public function __construct(TypeManager $typeManagerDocumentManagerService $documentManagerParameterBagInterface $params)
  14.     {
  15.       $this->typeManager $typeManager;
  16.       $this->documentManager $documentManager;
  17.       $this->params $params;
  18.     }
  19.     public function selectType()
  20.     {
  21.       return $this->render('elements/home_cover/select_type.html.twig', [
  22.           'categories'=> $this->typeManager->mapData(),
  23.         ]);
  24.     }
  25.     public function documentHead($params)
  26.     {
  27.       $useWds $this->getUseWds();
  28.       $params['useWds'] = $useWds;
  29.       $params['extractCss'] = !$useWds || $_ENV['EXTRACT_CSS'] === 'true';
  30.       return $this->render('search_properties/elements/document_head.html.twig'$params);
  31.     }
  32.     private function getUseWds()
  33.     {
  34.       return $_ENV['USE_WEBPACK_DEV_SERVER'] === 'true';
  35.     }
  36.     public function bodyEnd()
  37.     {
  38.       return $this->render('search_properties/elements/body_end.html.twig', [
  39.         'useWds' => $this->getUseWds(),
  40.         'googleCaptchaKey' => $_ENV['GOOGLE_CAPTCHA_KEY'],
  41.         'googleApisKey' => $_ENV['GOOGLE_APIS_KEY'],
  42.       ]);
  43.     }
  44.     public function popupMenu()
  45.     {
  46.       return $this->render('search_properties/elements/header_hub.html.twig', [
  47.       ]);
  48.     }
  49.     public function justMenu()
  50.     {
  51.       return $this->render('pages/just_menu.html.twig');
  52.     }
  53.     public function carouselBuy(PropertyRepository $pr)
  54.     {
  55.       return $this->render('elements2024/swiper_slider.html.twig', [
  56.         'slides' => $pr->findFeatured(102),
  57.         'detailPath' => 'buy_detail',
  58.       ]);
  59.     }
  60.     public function hasCarouselBuy(PropertyRepository $pr)
  61.     {
  62.       return new JsonResponse($pr->findFeatured(102) ? true :false);
  63.     }
  64.     public function carouselRent(PropertyRepository $pr)
  65.     {
  66.       return $this->render('elements2024/swiper_slider.html.twig', [
  67.         'slides' => $pr->findFeatured(10),
  68.         'detailPath' => 'rent_detail',
  69.       ]);
  70.     }
  71.     public function hasCarouselRent(PropertyRepository $pr)
  72.     {
  73.       return new JsonResponse($pr->findFeatured(10) ? true :false);
  74.     }
  75.     public function searchContactCoordinates(string $location) :JsonResponse
  76.     {
  77.       $Items $this->documentManager->getAgences($location);
  78.       if(!$Items || sizeof($Items) <= )
  79.       {
  80.           return new JsonResponse([]);
  81.       }
  82.       $Items $Items->current();
  83.       $lat $Items->getStructure()->getProperty('lat')->getValue();
  84.       $lng $Items->getStructure()->getProperty('lng')->getValue();
  85.       return new JsonResponse([["lat"=>(float)$lat"lng"=>(float)$lng]]);
  86.     }
  87.     public function newUser(Request $request)
  88.     {
  89.       $statusCode 500;
  90.       $message "Error";
  91.       if ($request->getMethod() == "POST" && $request->get('email')) {
  92.         $email $request->get('email');
  93.         $listId $this->params->get('app.list_id');
  94.         $apiKey $this->params->get('app.api_key');
  95.         $dataCenter substr($apiKeystrpos($apiKey'-') + 1);
  96.         $url 'https://' $dataCenter '.api.mailchimp.com/3.0/lists/' $listId '/members';
  97.         $json json_encode([
  98.           'email_address' => $email,
  99.           'status'        => 'pending',
  100.         ]);
  101.         $ch curl_init($url);
  102.         curl_setopt($chCURLOPT_USERPWD'user:' $apiKey);
  103.         curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  104.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  105.         curl_setopt($chCURLOPT_TIMEOUT10);
  106.         curl_setopt($chCURLOPT_POST1);
  107.         curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  108.         curl_setopt($chCURLOPT_POSTFIELDS$json);
  109.         $result curl_exec($ch);
  110.         $result json_decode($resulttrue);
  111.         $statusCode curl_getinfo($chCURLINFO_HTTP_CODE);
  112.         if ($statusCode == 200) {
  113.           $message 'You have successfully subscribed to CodexWorld.';
  114.         } else {
  115.           $statusCode $result['status'];
  116.           $message =$result['title'] ;
  117.         }
  118.         curl_close($ch);
  119.       }
  120.       $response = new Response(json_encode(
  121.         [
  122.           'status' => $statusCode,
  123.           'message' =>$message
  124.         ])
  125.       );
  126.       $response->headers->set('Content-Type''application/json');
  127.       return $response;
  128.     }
  129. }