<?php declare(strict_types=1);
namespace App\Realty\Controller;
use App\Base\Controller\BaseController;
use App\Leads\Form\ApartmentRecallType;
use App\Leads\Form\LayoutRecallType;
use App\Realty\Entity\Apartment;
use App\Realty\Entity\FloorModel;
use App\Realty\Entity\Layout;
use App\Realty\Repository\ApartmentRepository;
use App\Realty\Repository\LayoutRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use function Doctrine\ORM\QueryBuilder;
class LayoutController extends BaseController
{
#[Route(path: '/realty/layout_modal/{id}', name: 'realty:layout_modal')]
public function layoutModal(
Request $request,
Layout $layout
): Response {
$form = $this->createForm(LayoutRecallType::class);
$form->get('link')->setData($request->getUri());
return $this->render('pages/modal/realty/_layout-modal.html.twig', [
'layout' => $layout,
'idType' => 'layout',
'form' => $form->createView(),
]);
}
#[Route(path: '/realty/apartment_modal/{id}', name: 'realty:apartment_modal')]
public function apartmentModal(
Request $request,
Apartment $apartment
): Response {
$form = $this->createForm(ApartmentRecallType::class);
$form->get('link')->setData($request->getUri());
return $this->render('pages/modal/realty/_apartment-modal.html.twig', [
'apartment' => $apartment,
'idType' => 'apartment',
'form' => $form->createView(),
]);
}
#[Route(path: '/realty/outer_modal/{outerKey}', name: 'realty:outer_modal')]
public function outerModal(
Request $request,
Apartment $apartment
): Response {
return $this->apartmentModal($request, $apartment);
}
#[Route(path: '/realty/floor_modal/{id}', name: 'realty:floor_modal')]
public function floorModal(
FloorModel $floor,
): Response {
return $this->render('_parts/genplan/_floor.html.twig', [
'floor' => $floor,
]);
}
#[Route(path: '/realty/floor_genplan/{id}', name: 'realty:floor_genplan')]
public function floorGenplan(
FloorModel $floor,
): Response {
return $this->render('_parts/genplan/_floor-genplan.html.twig', [
'floor' => $floor,
]);
}
#[Route(path: '/share/layout/{id}', name: 'realty:share_layout')]
public function shareLayout(
Request $request,
int $id,
LayoutRepository $layoutRepository
): Response {
$qb = $layoutRepository->createQueryBuilder('layout');
$layout = $qb
->join('layout.apartments', 'apartments')
->where("layout.id = {$id}")
->andWhere('apartments.hidden = false')
->getQuery()
->getResult();
if (!$layout) {
return $this->json(['error' => "layout with {$id} could not found"], 500);
}
return $this->json([
'success' => true
]);
}
#[Route(path: '/share/apartment/{id}', name: 'realty:share_apartment')]
public function shareApartment(
Request $request,
int $id,
ApartmentRepository $apartmentRepository
): Response {
$apartment = $apartmentRepository->findOneBy(['id' => $id, 'hidden' => false]);
if (!$apartment) {
return $this->json(['error' => "apartment with {$id} could not found"], 500);
}
return $this->json([
'success' => true
]);
}
#[Route(path: '/share/outer/{outerId}', name: 'realty:share_outer')]
public function shareOuter(
Request $request,
int $outerId,
ApartmentRepository $apartmentRepository
): Response {
$apartment = $apartmentRepository->findOneBy(['outerKey' => $outerId, 'hidden' => false]);
if (!$apartment) {
return $this->json(['error' => "apartment with outer {$outerId} could not found"], 500);
}
return $this->json([
'success' => true
]);
}
}