src/Troika/RealEstateBundle/Controller/ComplexController.php line 71

Open in your IDE?
  1. <?php
  2. namespace Troika\RealEstateBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  5. class ComplexController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
  6. {
  7.     public function filterAction(\Symfony\Component\HttpFoundation\Request $request)
  8.     {
  9.         $r $request;
  10.         $query $this
  11.           ->getDoctrine()
  12.           ->getRepository('TroikaMainBundle:ComplexPage')
  13.           ->createQueryBuilder('c')
  14.           ->andWhere('c.isVisible = 1')
  15.           ->orderBy('c.id''desc');;
  16.         if ($district $r->get('district')) {
  17.             $query
  18.               ->andWhere('c.area2 IN (:district)')
  19.               ->setParameter('district'$district);
  20.         }
  21.         if ($subway $r->get('subway')) {
  22.             $query
  23.               ->andWhere('c.subway2 IN (:subway)')
  24.               ->setParameter('subway'$subway);
  25.         }
  26.         if ($type $r->get('type')) {
  27.             $query
  28.               ->andWhere('c.typeComplex IN (:type)')
  29.               ->setParameter('type'$type);
  30.         }
  31.         if ($stage $r->get('stage')) {
  32.             $query
  33.               ->andWhere('c.stageComplex IN (:stage)')
  34.               ->setParameter('stage'$stage);
  35.         }
  36.         if ($text $r->get('text')) {
  37.             $text str_replace("%""\%"$text);
  38.             $query
  39.               ->andWhere($query->expr()->like('c.name'':text'))
  40.               ->setParameter('text'$text '%');
  41.         }
  42.         $page $r->get('page') ?: 1;
  43.         $complexesCount = clone $query;
  44.         $complexesCount $complexesCount->select('count(c)')->getQuery()->getResult()[0][1];
  45.         $complexes $query->setMaxResults(10)->setFirstResult(($r->get('page') - 1) * 10)->getQuery()->getResult();
  46.         return $this->render(
  47.           'TroikaRealEstateBundle:Complex:item.item.html.twig',
  48.           ['complexes' => $complexes'complexesCount' => $complexesCount]
  49.         );
  50.     }
  51.     public function itemAction($name)
  52.     {
  53.         $complex $this->getDoctrine()->getRepository('TroikaMainBundle:ComplexPage')->findByUrl($name);
  54.         // $blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
  55.         if (empty($complex)) {
  56.             throw new NotFoundHttpException();
  57.         }
  58.         $page $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
  59.         return $this->render('TroikaRealEstateBundle:Complex:item.html.twig', ['complex' => $complex[0],'page'=>$page]);
  60.     }
  61.     public function listAction(\Symfony\Component\HttpFoundation\Request $request)
  62.     {
  63.         $seo $this->getDoctrine()->getRepository('TroikaMainBundle:Novostroy')->find(1);
  64.         if (empty($seo)) {
  65.             $seo $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
  66.               ->findOneBy(['route'=>$request->getRequestUri()],['id'=>'desc']);
  67.         }
  68.         $blog $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
  69.         $r $request;
  70.         $complexes $this->get('lot.model')->getComplexesList($r);
  71.         $complexesAll $this->getDoctrine()->getRepository('TroikaMainBundle:ComplexPage')->findBy([], ['name' => 'ASC']);
  72.         $districtsAll $this->getDoctrine()->getRepository('TroikaMainBundle:Area2')->findAll();
  73.         $subwaysAll $this->getDoctrine()->getRepository('TroikaMainBundle:Subway2')->findAll();
  74.         $districts = [];
  75.         $subways = [];
  76.         $cs = [];
  77.         $districtIds = [];
  78.         $subwayIds = [];
  79.         $types $this->getDoctrine()->getRepository('TroikaMainBundle:TypeComplex')->findAll();
  80.         $stages $this->getDoctrine()->getRepository('TroikaMainBundle:StageComplex')->findAll();
  81.         foreach ($complexesAll as $complex) {
  82.             if ($complex->getIsVisible()) {
  83.                 $cs[] = $complex->getName();
  84.             }
  85.             if (!in_array($complex->getArea2()->getId(), $districtIdstrue)) {
  86.                 $districtIds[] = $complex->getArea2()->getId();
  87.             }
  88.             if (!in_array($complex->getSubway2()->getId(), $subwayIdstrue)) {
  89.                 $subwayIds[] = $complex->getSubway2()->getId();
  90.             }
  91.         }
  92.         foreach ($districtIds as $id) {
  93.             foreach ($districtsAll as $district) {
  94.                 if ($id == $district->getId()) {
  95.                     $districts[] = $district;
  96.                 }
  97.             }
  98.         }
  99.         foreach ($subwayIds as $id) {
  100.             foreach ($subwaysAll as $subway) {
  101.                 if ($id == $subway->getId()) {
  102.                     $subways[] = $subway;
  103.                 }
  104.             }
  105.         }
  106.         
  107.         $page $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
  108.         return $this->render(
  109.           'TroikaRealEstateBundle:Complex:list.html.twig',
  110.           [
  111.             'districts' => $districts,
  112.             'subways' => $subways,
  113.             'types' => $types,
  114.             'stages' => $stages,
  115.             'complexes' => $complexes,
  116.             'f_text' => $r->get('text'),
  117.             'f_district' => $r->get('district'),
  118.             'f_stage' => $r->get('stage'),
  119.             'f_type' => $r->get('type'),
  120.             'f_subway' => $r->get('subway'),
  121.             'cs' => $cs,
  122.             'f_c' => $r->get('text'),
  123.             'w_c' => $r->get('with_filter'),
  124.             'seo' => $seo,
  125.             'page'=>$page
  126.           ]
  127.         );
  128.     }
  129. }