<?php
namespace App\Controller\Website;
use App\Repository\PropertyRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Manager\TypeManager;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Service\DocumentManagerService;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class LayoutController extends AbstractController
{
public function __construct(TypeManager $typeManager, DocumentManagerService $documentManager, ParameterBagInterface $params)
{
$this->typeManager = $typeManager;
$this->documentManager = $documentManager;
$this->params = $params;
}
public function selectType()
{
return $this->render('elements/home_cover/select_type.html.twig', [
'categories'=> $this->typeManager->mapData(),
]);
}
public function documentHead($params)
{
$useWds = $this->getUseWds();
$params['useWds'] = $useWds;
$params['extractCss'] = !$useWds || $_ENV['EXTRACT_CSS'] === 'true';
return $this->render('search_properties/elements/document_head.html.twig', $params);
}
private function getUseWds()
{
return $_ENV['USE_WEBPACK_DEV_SERVER'] === 'true';
}
public function bodyEnd()
{
return $this->render('search_properties/elements/body_end.html.twig', [
'useWds' => $this->getUseWds(),
'googleCaptchaKey' => $_ENV['GOOGLE_CAPTCHA_KEY'],
'googleApisKey' => $_ENV['GOOGLE_APIS_KEY'],
]);
}
public function popupMenu()
{
return $this->render('search_properties/elements/header_hub.html.twig', [
]);
}
public function justMenu()
{
return $this->render('pages/just_menu.html.twig');
}
public function carouselBuy(PropertyRepository $pr)
{
return $this->render('elements2024/swiper_slider.html.twig', [
'slides' => $pr->findFeatured(10, 2),
'detailPath' => 'buy_detail',
]);
}
public function hasCarouselBuy(PropertyRepository $pr)
{
return new JsonResponse($pr->findFeatured(10, 2) ? true :false);
}
public function carouselRent(PropertyRepository $pr)
{
return $this->render('elements2024/swiper_slider.html.twig', [
'slides' => $pr->findFeatured(10),
'detailPath' => 'rent_detail',
]);
}
public function hasCarouselRent(PropertyRepository $pr)
{
return new JsonResponse($pr->findFeatured(10) ? true :false);
}
public function searchContactCoordinates(string $location) :JsonResponse
{
$Items = $this->documentManager->getAgences($location);
if(!$Items || sizeof($Items) <= 0 )
{
return new JsonResponse([]);
}
$Items = $Items->current();
$lat = $Items->getStructure()->getProperty('lat')->getValue();
$lng = $Items->getStructure()->getProperty('lng')->getValue();
return new JsonResponse([["lat"=>(float)$lat, "lng"=>(float)$lng]]);
}
public function newUser(Request $request)
{
$statusCode = 500;
$message = "Error";
if ($request->getMethod() == "POST" && $request->get('email')) {
$email = $request->get('email');
$listId = $this->params->get('app.list_id');
$apiKey = $this->params->get('app.api_key');
$dataCenter = substr($apiKey, strpos($apiKey, '-') + 1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members';
$json = json_encode([
'email_address' => $email,
'status' => 'pending',
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$result = json_decode($result, true);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
$message = 'You have successfully subscribed to CodexWorld.';
} else {
$statusCode = $result['status'];
$message =$result['title'] ;
}
curl_close($ch);
}
$response = new Response(json_encode(
[
'status' => $statusCode,
'message' =>$message
])
);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}