<?php
namespace Troika\RealEstateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ComplexController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function filterAction(\Symfony\Component\HttpFoundation\Request $request)
{
$r = $request;
$query = $this
->getDoctrine()
->getRepository('TroikaMainBundle:ComplexPage')
->createQueryBuilder('c')
->andWhere('c.isVisible = 1')
->orderBy('c.id', 'desc');;
if ($district = $r->get('district')) {
$query
->andWhere('c.area2 IN (:district)')
->setParameter('district', $district);
}
if ($subway = $r->get('subway')) {
$query
->andWhere('c.subway2 IN (:subway)')
->setParameter('subway', $subway);
}
if ($type = $r->get('type')) {
$query
->andWhere('c.typeComplex IN (:type)')
->setParameter('type', $type);
}
if ($stage = $r->get('stage')) {
$query
->andWhere('c.stageComplex IN (:stage)')
->setParameter('stage', $stage);
}
if ($text = $r->get('text')) {
$text = str_replace("%", "\%", $text);
$query
->andWhere($query->expr()->like('c.name', ':text'))
->setParameter('text', $text . '%');
}
$page = $r->get('page') ?: 1;
$complexesCount = clone $query;
$complexesCount = $complexesCount->select('count(c)')->getQuery()->getResult()[0][1];
$complexes = $query->setMaxResults(10)->setFirstResult(($r->get('page') - 1) * 10)->getQuery()->getResult();
return $this->render(
'TroikaRealEstateBundle:Complex:item.item.html.twig',
['complexes' => $complexes, 'complexesCount' => $complexesCount]
);
}
public function itemAction($name)
{
$complex = $this->getDoctrine()->getRepository('TroikaMainBundle:ComplexPage')->findByUrl($name);
// $blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
if (empty($complex)) {
throw new NotFoundHttpException();
}
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:Complex:item.html.twig', ['complex' => $complex[0],'page'=>$page]);
}
public function listAction(\Symfony\Component\HttpFoundation\Request $request)
{
$seo = $this->getDoctrine()->getRepository('TroikaMainBundle:Novostroy')->find(1);
if (empty($seo)) {
$seo = $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
->findOneBy(['route'=>$request->getRequestUri()],['id'=>'desc']);
}
$blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
$r = $request;
$complexes = $this->get('lot.model')->getComplexesList($r);
$complexesAll = $this->getDoctrine()->getRepository('TroikaMainBundle:ComplexPage')->findBy([], ['name' => 'ASC']);
$districtsAll = $this->getDoctrine()->getRepository('TroikaMainBundle:Area2')->findAll();
$subwaysAll = $this->getDoctrine()->getRepository('TroikaMainBundle:Subway2')->findAll();
$districts = [];
$subways = [];
$cs = [];
$districtIds = [];
$subwayIds = [];
$types = $this->getDoctrine()->getRepository('TroikaMainBundle:TypeComplex')->findAll();
$stages = $this->getDoctrine()->getRepository('TroikaMainBundle:StageComplex')->findAll();
foreach ($complexesAll as $complex) {
if ($complex->getIsVisible()) {
$cs[] = $complex->getName();
}
if (!in_array($complex->getArea2()->getId(), $districtIds, true)) {
$districtIds[] = $complex->getArea2()->getId();
}
if (!in_array($complex->getSubway2()->getId(), $subwayIds, true)) {
$subwayIds[] = $complex->getSubway2()->getId();
}
}
foreach ($districtIds as $id) {
foreach ($districtsAll as $district) {
if ($id == $district->getId()) {
$districts[] = $district;
}
}
}
foreach ($subwayIds as $id) {
foreach ($subwaysAll as $subway) {
if ($id == $subway->getId()) {
$subways[] = $subway;
}
}
}
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render(
'TroikaRealEstateBundle:Complex:list.html.twig',
[
'districts' => $districts,
'subways' => $subways,
'types' => $types,
'stages' => $stages,
'complexes' => $complexes,
'f_text' => $r->get('text'),
'f_district' => $r->get('district'),
'f_stage' => $r->get('stage'),
'f_type' => $r->get('type'),
'f_subway' => $r->get('subway'),
'cs' => $cs,
'f_c' => $r->get('text'),
'w_c' => $r->get('with_filter'),
'seo' => $seo,
'page'=>$page
]
);
}
}