src/Troika/RealEstateBundle/Controller/ListController.php line 626

Open in your IDE?
  1. <?php
  2. namespace Troika\RealEstateBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Troika\MainBundle\Command\GenerateShitFiltersCommand;
  6. class ListController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
  7. {
  8.     private function action($repa_name$type_lot$page$add_fields$twig$is_rent$request$seo null)
  9.     {
  10.         $repository $this->getDoctrine()->getRepository('TroikaMainBundle:' $repa_name);
  11.         $repa $repository->find(1);
  12.         $route $this->getRouteData($type_lot$request);
  13.         $data = [
  14.           'lots'          => $this->lotList($type_lot$route['type_operation'], $page$request),
  15.           'page'          => $page,
  16.           'lotsAddresses' => $this->model('lot')->getLotAddresses($type_lot$route['type_operation']),
  17.           'custompage'    => empty($_GET) ? 'false' 'true',
  18.           'title'         => $seo $seo->getSeotitle() : $repa->getTitle($is_rent),
  19.           'keywords'      => $seo $seo->getMetaKeywords() : $repa->getKeywords($is_rent),
  20.           'description'   => $seo $seo->getSeodesc() : $repa->getDescription($is_rent),
  21.           'h1'            => $seo $seo->getH1() : $repa->getH1($is_rent),
  22.           'seoFirst'      => $seo $seo->getSeotext1() : $repa->getSeoLabelFirst(),
  23.           'seoSecond'     => $seo $seo->getSeotext2() : $repa->getSeoLabelSecond(),
  24.           'seoFirstRent'  => $seo $seo->getSeotext1() : $repa->getSeoLabelRentFirst(),
  25.           'seoSecondRent' => $seo $seo->getSeotext2() : $repa->getSeoLabelRentSecond(),
  26.         ];
  27.         $translit = new GenerateShitFiltersCommand();
  28.         $translits = [];
  29.         foreach ($add_fields as $key => $item) {
  30.             switch ($item['logic']) {
  31.                 case 'rent':
  32.                     $adds $route['type_operation'] === 1
  33.                       $this->model($item['model'])->getInUseSale($type_lot)
  34.                       : $this->model($item['model'])->getInUseRent($type_lot);
  35.                     break;
  36.                 case 'by_type':
  37.                     $adds $this->model($item['model'])->getByType($type_lot);
  38.                     break;
  39.                 case 'all':
  40.                     $adds $this->model($item['model'])->getAll();
  41.                     break;
  42.                 default:
  43.                     $adds = [];
  44.                     break;
  45.             }
  46.             foreach ($adds as $add) {
  47.                 if (!array_key_exists($item['model'], $translits)) {
  48.                     $translits[$item['model']] = [];
  49.                 }
  50.                 if (!is_array($add)) {
  51.                     $add = [
  52.                       'id'   => $add->getId(),
  53.                       'name' => $add->getName(),
  54.                     ];
  55.                 }
  56.                 if ($add['id'] && $add['name']) {
  57.                     $tr_model array_key_exists('preset'$item) ? $item['preset'] : $item['model'];
  58.                     $tr_key $translit->toAscii($translit->str2url($add['name']));
  59.                     $translits[$tr_model][$tr_key] = $add['id'];
  60.                 }
  61.             }
  62.             $data[$key] = $adds;
  63.         }
  64.         $this->parseQuery($type_lot$route$data$translits);
  65.         return $this->render('TroikaRealEstateBundle:EstateList:' $twig '.html.twig'$data);
  66.     }
  67.     private function getRouteData($type_lot$request null)
  68.     {
  69.         $rt = [
  70.           => [
  71.             'route' => 'elit_kvartiry',
  72.             'title' => 'Городская недвижимость',
  73.           ],
  74.           [
  75.             'route' => 'zagorodnaya_nedvizhimost',
  76.             'title' => 'Загородная недвижимость',
  77.           ],
  78.           [
  79.             'route' => 'commercial_nedvigimost',
  80.             'title' => 'Коммерческая недвижимость',
  81.           ],
  82.           [
  83.             'route' => 'zarubezhnaya_nedvizhimost',
  84.             'title' => 'Зарубежная недвижимость',
  85.           ],
  86.           [
  87.             'route' => 'special_offers',
  88.             'title' => 'Эксклюзивная недвижимость',
  89.           ],
  90.         ];
  91.         $request $this->container->get('request_stack')->getCurrentRequest();
  92.         //$query = $request->getQueryString();
  93.         $query $request->get('query');
  94.         $q_len mb_strlen($query);
  95.         $rent '_arenda';
  96.         $r_len mb_strlen($rent);
  97.         if (mb_substr($querymax($q_len $r_len0), min($r_len$q_len)) === $rent) {
  98.             $query str_replace($rent''$query);
  99.             $type_operation 2;
  100.         } else {
  101.             $type_operation 1;
  102.         }
  103.         return [
  104.           'route'          => $rt[$type_lot]['route'],
  105.           'title'          => $rt[$type_lot]['title'],
  106.           'query'          => $query,
  107.           'type_operation' => $type_operation,
  108.         ];
  109.     }
  110.     private function lotList($type$operation$page$request)
  111.     {
  112.         $price_a = [
  113.           [
  114.             [
  115.               [
  116.                 'min' => 0,
  117.                 'max' => 15000,
  118.               ],
  119.               [
  120.                 'min' => 0,
  121.                 'max' => $this->get('troika_main.currency')->getDollars(300001),
  122.               ],
  123.               [
  124.                 'min' => $this->get('troika_main.currency')->getDollars(300001),
  125.                 'max' => $this->get('troika_main.currency')->getDollars(1000001),
  126.               ],
  127.               [
  128.                 'min' => $this->get('troika_main.currency')->getDollars(1000001),
  129.                 'max' => $this->get('troika_main.currency')->getDollars(1_000_0001),
  130.               ],
  131.             ],
  132.             [
  133.               [
  134.                 'min' => 0,
  135.                 'max' => 15000,
  136.               ],
  137.               [
  138.                 'min' => 0,
  139.                 'max' => $this->get('troika_main.currency')->getDollars(3001),
  140.               ],
  141.               [
  142.                 'min' => $this->get('troika_main.currency')->getDollars(3001),
  143.                 'max' => $this->get('troika_main.currency')->getDollars(10001),
  144.               ],
  145.               [
  146.                 'min' => $this->get('troika_main.currency')->getDollars(10001),
  147.                 'max' => $this->get('troika_main.currency')->getDollars(100001),
  148.               ],
  149.             ],
  150.           ],
  151.           [
  152.             [
  153.               [
  154.                 'min' => 0,
  155.                 'max' => 15000,
  156.               ],
  157.               [
  158.                 'min' => 0,
  159.                 'max' => $this->get('troika_main.currency')->getDollars(600001),
  160.               ],
  161.               [
  162.                 'min' => $this->get('troika_main.currency')->getDollars(600001),
  163.                 'max' => $this->get('troika_main.currency')->getDollars(1000001),
  164.               ],
  165.               [
  166.                 'min' => $this->get('troika_main.currency')->getDollars(1000001),
  167.                 'max' => $this->get('troika_main.currency')->getDollars(1_000_0001),
  168.               ],
  169.             ],
  170.             [
  171.               [
  172.                 'min' => 0,
  173.                 'max' => 15000,
  174.               ],
  175.               [
  176.                 'min' => 0,
  177.                 'max' => $this->get('troika_main.currency')->getDollars(6001),
  178.               ],
  179.               [
  180.                 'min' => $this->get('troika_main.currency')->getDollars(6001),
  181.                 'max' => $this->get('troika_main.currency')->getDollars(10001),
  182.               ],
  183.               [
  184.                 'min' => $this->get('troika_main.currency')->getDollars(10001),
  185.                 'max' => $this->get('troika_main.currency')->getDollars(100001),
  186.               ],
  187.             ],
  188.           ],
  189.           [
  190.             [
  191.               [
  192.                 'min' => 0,
  193.                 'max' => 15000,
  194.               ],
  195.               [
  196.                 'min' => 0,
  197.                 'max' => $this->get('troika_main.currency')->getDollars(600001),
  198.               ],
  199.               [
  200.                 'min' => $this->get('troika_main.currency')->getDollars(600001),
  201.                 'max' => $this->get('troika_main.currency')->getDollars(1000001),
  202.               ],
  203.               [
  204.                 'min' => $this->get('troika_main.currency')->getDollars(1000001),
  205.                 'max' => $this->get('troika_main.currency')->getDollars(1_000_0001),
  206.               ],
  207.             ],
  208.             [
  209.               [
  210.                 'min' => 0,
  211.                 'max' => 15000,
  212.               ],
  213.               [
  214.                 'min' => 0,
  215.                 'max' => $this->get('troika_main.currency')->getDollars(5001),
  216.               ],
  217.               [
  218.                 'min' => $this->get('troika_main.currency')->getDollars(5001),
  219.                 'max' => $this->get('troika_main.currency')->getDollars(10001),
  220.               ],
  221.               [
  222.                 'min' => $this->get('troika_main.currency')->getDollars(10001),
  223.                 'max' => $this->get('troika_main.currency')->getDollars(100001),
  224.               ],
  225.             ],
  226.           ],
  227.           [
  228.             [
  229.               [
  230.                 'min' => 0,
  231.                 'max' => 15000,
  232.               ],
  233.               [
  234.                 'min' => 0,
  235.                 'max' => 1000,
  236.               ],
  237.               [
  238.                 'min' => 1000,
  239.                 'max' => 3000,
  240.               ],
  241.               [
  242.                 'min' => 3000,
  243.                 'max' => 300000,
  244.               ],
  245.             ],
  246.             [
  247.               [
  248.                 'min' => 0,
  249.                 'max' => 15000,
  250.               ],
  251.               [
  252.                 'min' => 0,
  253.                 'max' => 50,
  254.               ],
  255.               [
  256.                 'min' => 50,
  257.                 'max' => 100,
  258.               ],
  259.               [
  260.                 'min' => 100,
  261.                 'max' => 10000,
  262.               ],
  263.             ],
  264.           ],
  265.         ];
  266.         $space_a = [
  267.           [
  268.             [
  269.               'min' => 0,
  270.               'max' => 100000,
  271.             ],
  272.             [
  273.               'min' => 0,
  274.               'max' => 100,
  275.             ],
  276.             [
  277.               'min' => 100,
  278.               'max' => 200,
  279.             ],
  280.             [
  281.               'min' => 200,
  282.               'max' => 10000,
  283.             ],
  284.           ],
  285.           [
  286.             [
  287.               'min' => 0,
  288.               'max' => 100000,
  289.             ],
  290.             [
  291.               'min' => 0,
  292.               'max' => 600,
  293.             ],
  294.             [
  295.               'min' => 300,
  296.               'max' => 1000,
  297.             ],
  298.             [
  299.               'min' => 1000,
  300.               'max' => 10000,
  301.             ],
  302.           ],
  303.           [
  304.             [
  305.               'min' => 0,
  306.               'max' => 100000,
  307.             ],
  308.             [
  309.               'min' => 0,
  310.               'max' => 300,
  311.             ],
  312.             [
  313.               'min' => 300,
  314.               'max' => 1000,
  315.             ],
  316.             [
  317.               'min' => 1000,
  318.               'max' => 10000,
  319.             ],
  320.           ],
  321.           [
  322.             [
  323.               'min' => 0,
  324.               'max' => 100000,
  325.             ],
  326.             [
  327.               'min' => 0,
  328.               'max' => 300,
  329.             ],
  330.             [
  331.               'min' => 300,
  332.               'max' => 1000,
  333.             ],
  334.             [
  335.               'min' => 1000,
  336.               'max' => 10000,
  337.             ],
  338.           ],
  339.         ];
  340.         $a $request->get('price') ? (int)$request->get('price') : 0;
  341.         $b $request->get('space') ? (int)$request->get('space') : 0;
  342.         $p $price_a[$type 1][$operation 1][$a];
  343.         $s $space_a[$type 1][$b];
  344.         $repair $request->get('repair');
  345.         $rooms $request->get('rooms');
  346.         return $lots $this
  347.           ->model('lot')
  348.           ->getPageByType(
  349.             [
  350.               'price'     => $p,
  351.               'space'     => $s,
  352.               'repair'    => $repair,
  353.               'rooms'     => $rooms,
  354.               'type'      => $type,
  355.               'sale'      => (bool)$request->get('sale'),
  356.               'operation' => $operation,
  357.               'text'      => $request->get('text'),
  358.               'page'      => $request->get('page') ?: 1,
  359.               'pageSize'  => 10,
  360.             ]
  361.           );
  362.     }
  363.     private function model($name)
  364.     {
  365.         try {
  366.             return $this
  367.               ->container
  368.               ->get($name '.model');
  369.         } catch (\Exception $e) {
  370.             throw $e;
  371.         }
  372.     }
  373.     private function parseQuery($type_lot$route, &$data$translits)
  374.     {
  375.         $preset = [];
  376.         foreach (explode('-'$route['query']) as $q) {
  377.             if (!mb_strlen($q)) {
  378.                 continue;
  379.             }
  380.             foreach ($translits as $key => $translit) {
  381.                 if (!array_key_exists($q$translit)) {
  382.                     continue;
  383.                 }
  384.                 if (!array_key_exists($key$preset)) {
  385.                     $preset[$key] = [];
  386.                 }
  387.                 $preset[$key][] = $translit[$q];
  388.                 break;
  389.             }
  390.         }
  391.         if ($preset) {
  392.             $preset['seotitle'] = $route['title'];
  393.             $preset['seodesc'] = '';
  394.             $preset['name'] = '';
  395.             $preset['typelot'] = $type_lot;
  396.             $preset['typeoperation'] = $route['type_operation'];
  397.             $data['filterpreset'] = $preset;
  398.         }
  399.     }
  400.     public function cityAction(Request $request, \Symfony\Component\HttpFoundation\Request $mainRequest)
  401.     {
  402.         if (
  403.           (!empty($_GET['price']) && $_GET['price'] === '[Array]') ||
  404.           (!empty($_GET['space']) && $_GET['space'] === '[Array]')
  405.         ) {
  406.             $a explode("?"$request->getUri());
  407.             $a $a[0];
  408.             return $this->redirect($a301);
  409.         }
  410.         $request $mainRequest;
  411.         $page $request->get('page') ?: 1;
  412.         $isRent = (strpos($mainRequest->getUri(), "arenda") !== false);
  413.         $currentUrl $mainRequest->getUri();
  414.         $currentUrl array_reverse(explode("/"$currentUrl));
  415.         $currentUrl $currentUrl[0];
  416.         $currentUrl explode("?"$currentUrl);
  417.         $currentUrl $currentUrl[0];
  418.         $seo $this
  419.           ->getDoctrine()
  420.           ->getRepository('TroikaMainBundle:FilterPreset')
  421.           ->findBy(['alias' => $currentUrl]);
  422.         if (empty($seo)) {
  423.             $seo null;
  424.         } else {
  425.             $seo $seo[0];
  426.         }
  427.         if (empty($seo)) {
  428.             $seo $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
  429.               ->findOneBy(['route' => $mainRequest->getRequestUri()], ['id' => 'desc']);
  430.         }
  431.         return $this->action('City'1$page, [
  432.           'subways'   => [
  433.             'model' => 'subway',
  434.             'logic' => 'rent',
  435.           ],
  436.           'districts' => [
  437.             'model' => 'district',
  438.             'logic' => 'rent',
  439.           ],
  440.           'types'     => [
  441.             'model'  => 'type_house',
  442.             'logic'  => 'by_type',
  443.             'preset' => 'type',
  444.           ],
  445.           'stages'    => [
  446.             'model'  => 'stage_house',
  447.             'logic'  => 'all',
  448.             'preset' => 'stage',
  449.           ],
  450.           'complexes' => [
  451.             'model' => 'complex',
  452.             'logic' => 'all',
  453.           ],
  454.           'tags'      => [
  455.             'model' => 'tag',
  456.             'logic' => 'all',
  457.           ],
  458.         ], 'city'$isRent$mainRequest$seo);
  459.     }
  460.     public function citySaleAction()
  461.     {
  462.     }
  463.     public function commercialAction(\Symfony\Component\HttpFoundation\Request $request)
  464.     {
  465.         $page $request->get('page') ?: 1;
  466.         $isRent = (strpos($request->getUri(), "arenda") !== false);
  467.         $currentUrl $request->getUri();
  468.         $currentUrl array_reverse(explode("/"$currentUrl));
  469.         $currentUrl $currentUrl[0];
  470.         $currentUrl explode("?"$currentUrl);
  471.         $currentUrl $currentUrl[0];
  472.         $seo $this
  473.           ->getDoctrine()
  474.           ->getRepository('TroikaMainBundle:FilterPreset')
  475.           ->findBy(['alias' => $currentUrl]);
  476.         if (empty($seo)) {
  477.             $seo null;
  478.         } else {
  479.             $seo $seo[0];
  480.         }
  481.         if (empty($seo)) {
  482.             $seo $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
  483.               ->findOneBy(['route' => $request->getRequestUri()], ['id' => 'desc']);
  484.         }
  485.         return $this->action('Commercial'3$page, [
  486.           'subways'   => [
  487.             'model' => 'subway',
  488.             'logic' => 'rent',
  489.           ],
  490.           'districts' => [
  491.             'model' => 'district',
  492.             'logic' => 'rent',
  493.           ],
  494.           'types'     => [
  495.             'model'  => 'type_house',
  496.             'logic'  => 'by_type',
  497.             'preset' => 'type',
  498.           ],
  499.           'stages'    => [
  500.             'model'  => 'stage_house',
  501.             'logic'  => 'all',
  502.             'preset' => 'stage',
  503.           ],
  504.           'tags'      => [
  505.             'model' => 'tag',
  506.             'logic' => 'all',
  507.           ],
  508.         ], 'commercial'$isRent$request$seo);
  509.     }
  510.     /*
  511.      * bldzhad
  512.     */
  513.     public function errorAction()
  514.     {
  515.         header('HTTP/1.0 404');
  516.         echo "Страница не найдена. <a href='/'>На главную</a>";
  517.     }
  518.     public function foreignAction(\Symfony\Component\HttpFoundation\Request $request)
  519.     {
  520.         $page $request->get('page') ?: 1;
  521.         $isRent = (strpos($request->getUri(), "arenda") !== false);
  522.         $currentUrl $request->getUri();
  523.         $currentUrl array_reverse(explode("/"$currentUrl));
  524.         $currentUrl $currentUrl[0];
  525.         $currentUrl explode("?"$currentUrl);
  526.         $currentUrl $currentUrl[0];
  527.         $seo $this
  528.           ->getDoctrine()
  529.           ->getRepository('TroikaMainBundle:FilterPreset')
  530.           ->findBy(['alias' => $currentUrl]);
  531.         if (empty($seo)) {
  532.             $seo null;
  533.         } else {
  534.             $seo $seo[0];
  535.         }
  536.         if (empty($seo)) {
  537.             $seo $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
  538.               ->findOneBy(['route' => $request->getRequestUri()], ['id' => 'desc']);
  539.         }
  540.         return $this->action('ForeignEstate'4$page, [
  541.           'countries'     => [
  542.             'model' => 'country',
  543.             'logic' => 'rent',
  544.           ],
  545.           'countryCities' => [
  546.             'model' => 'country_city',
  547.             'logic' => 'rent',
  548.           ],
  549.           'types'         => [
  550.             'model'  => 'type_house',
  551.             'logic'  => 'by_type',
  552.             'preset' => 'type',
  553.           ],
  554.           'stages'        => [
  555.             'model'  => 'stage_house',
  556.             'logic'  => 'all',
  557.             'preset' => 'stage',
  558.           ],
  559.           'tags'          => [
  560.             'model' => 'tag',
  561.             'logic' => 'all',
  562.           ],
  563.         ], 'foreign'$isRent$request$seo);
  564.     }
  565.     public function specialAction()
  566.     {
  567.         $data = [
  568.           'lots'          => $this->model('lot')->getSpecial(),
  569.           'lotsAddresses' => $this->model('lot')->getSpecialLotAddresses(),
  570.         ];
  571.         return $this->render('TroikaRealEstateBundle:EstateList:special.html.twig'$data);
  572.     }
  573.     public function suburbanAction(\Symfony\Component\HttpFoundation\Request $request)
  574.     {
  575.         $request $request;
  576.         $page $request->get('page') ?: 1;
  577.         $isRent = (strpos($request->getUri(), "arenda") !== false);
  578.         $currentUrl $request->getUri();
  579.         $currentUrl array_reverse(explode("/"$currentUrl));
  580.         $currentUrl $currentUrl[0];
  581.         $currentUrl explode("?"$currentUrl);
  582.         $currentUrl $currentUrl[0];
  583.         $seo $this
  584.           ->getDoctrine()
  585.           ->getRepository('TroikaMainBundle:FilterPreset')
  586.           ->findBy(['alias' => $currentUrl]);
  587.         if (empty($seo)) {
  588.             $seo null;
  589.         } else {
  590.             $seo $seo[0];
  591.         }
  592.         if (empty($seo)) {
  593.             $seo $this->getDoctrine()->getRepository('TroikaMainBundle:SeoText')
  594.               ->findOneBy(['route' => $request->getRequestUri()], ['id' => 'desc']);
  595.         }
  596.         return $this->action('SubUrban'2$page, [
  597.           'highways'    => [
  598.             'model' => 'highway',
  599.             'logic' => 'rent',
  600.           ],
  601.           'settlements' => [
  602.             'model' => 'settlement',
  603.             'logic' => 'rent',
  604.           ],
  605.           'types'       => [
  606.             'model'  => 'type_house',
  607.             'logic'  => 'by_type',
  608.             'preset' => 'type',
  609.           ],
  610.           'stages'      => [
  611.             'model'  => 'stage_house',
  612.             'logic'  => 'all',
  613.             'preset' => 'stage',
  614.           ],
  615.           'tags'        => [
  616.             'model' => 'tag',
  617.             'logic' => 'all',
  618.           ],
  619.         ], 'suburban'$isRent$request$seo);
  620.     }
  621. }