<?php
namespace Troika\RealEstateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class FilterPresetController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
private function _model($name)
{
return $this
->container
->get($name . '.model');
}
public function CustomFilterAction($alias)
{
$em = $this->getDoctrine()->getEntityManager();
$filter = $em->getRepository('TroikaMainBundle:FilterPreset')->findOneBy(['alias' => $alias]);
if ($filter) {
$lots = $this->_model('lot')->getEmptyPage();
if ($filter->getTypeLot() && !$filter->getExclusive()) {
switch ($filter->getTypeLot()->getId()) {
case 1:
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(1, 1),
'subways' => $this->_model('subway')->getAll2(),
'districts' => $this->_model('district')->getAll2(),
'types' => $this->_model('type_house')->getByType(1),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('TroikaRealEstateBundle:EstateList:city.html.twig', $data);
break;
case 4:
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(4, 1),
'countries' => $this->_model('country')->getAll(),
'countryCities' => $this->_model('country_city')->getAll(),
'types' => $this->_model('type_house')->getByType(4),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('TroikaRealEstateBundle:EstateList:foreign.html.twig', $data);
break;
case 2:
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(2, 2),
'highways' => $this->_model('highway')->getAll(),
'settlements' => $this->_model('settlement')->getAll(),
'types' => $this->_model('type_house')->getByType(2),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('TroikaRealEstateBundle:EstateList:suburban.html.twig', $data);
break;
case 3:
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(3, 2),
'subways' => $this->_model('subway')->getAll2(),
'districts' => $this->_model('district')->getAll2(),
'types' => $this->_model('type_house')->getByType(3),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('TroikaRealEstateBundle:EstateList:commercial.html.twig', $data);
break;
}
} elseif ($filter->getExclusive()) {
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(3, 2),
'subways' => $this->_model('subway')->getAll2(),
'districts' => $this->_model('district')->getAll2(),
'types' => $this->_model('type_house')->getByType(3),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('@TroikaRealEstate/EstateList/special.html.twig', $data);
}
} else {
throw new NotFoundHttpException();
}
}
public function SuburbanCustomFilterAction($alias)
{
exit;
$em = $this->getDoctrine()->getEntityManager();
$filter = $em->getRepository('TroikaMainBundle:FilterPreset')->findOneBy(['alias' => $alias]);
if ($filter) {
$lots = $this->_model('lot')->getEmptyPage();
if ($filter->getTypeLot() && !$filter->getExclusive()) {
switch ($filter->getTypeLot()->getId()) {
case 2:
$data = [
'lots' => $lots,
'lotsAddresses' => $this->_model('lot')->getLotAddresses(2, 2),
'highways' => $this->_model('highway')->getAll(),
'settlements' => $this->_model('settlement')->getAll(),
'types' => $this->_model('type_house')->getByType(2),
'stages' => $this->_model('stage_house')->getAll(),
'filterpreset' => $filter->getAttributes(),
];
return $this->render('TroikaRealEstateBundle:EstateList:suburban.html.twig', $data);
break;
default:
throw new NotFoundHttpException();
break;
}
}
} else {
throw new NotFoundHttpException();
}
}
}