src/AppBundle/Controller/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Cache\Adapter\ApcuAdapter;
  7. use Symfony\Contracts\Cache\ItemInterface;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use AppBundle\Includes\Helper;
  10. use AppBundle\Includes\Tracker;
  11. use AppBundle\Includes\Functions;
  12. use AppBundle\Includes\Constants;
  13. class DefaultController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/{uri}", name="dbslashesfix",
  17.      * requirements={"uri": "^/+(.+)"},
  18.      * methods={"GET"})
  19.      */
  20.     public function dbslashesfixAction(Request $request$uri)
  21.     {
  22.         $uri preg_replace('~/{2,}~''/'$uri);
  23.         return $this->redirect($uri301);
  24.     }
  25.     /**
  26.      * @Route("/test/home", name="homepage_old", methods={"GET"})
  27.      */
  28.     public function defaultOldAction(Request $request)
  29.     {
  30.         $session $request->getSession();
  31.         $helper = new Helper($this->get('router'));
  32.         $user $this->get('app.users');
  33.         $tracker = new Tracker();
  34.         # Using of APCU cache highly updates speed
  35.         $cache = new ApcuAdapter($namespace='bizenco',$defaultLifetime=0,$version=null);
  36.         $popular_searches_entre $cache->get('popular_searches_entre', function (ItemInterface $item) use ($tracker) {
  37.             $item->expiresAfter(7200);
  38.             $value $tracker->get_popular_searches($this->get('router'), 112);
  39.             return $value;
  40.         });
  41.         $popular_searches_murs $cache->get('popular_searches_murs', function (ItemInterface $item) use ($tracker) {
  42.             $item->expiresAfter(7200);
  43.             $value $tracker->get_popular_searches($this->get('router'), 212);
  44.             return $value;
  45.         });
  46.         $tracker->get_popular_searches($this->get('router'), 210);
  47.         $recently_joined $cache->get('recently_joined', function (ItemInterface $item) use ($helper) {
  48.             $item->expiresAfter(86400);
  49.             $value $helper->recently_joined();
  50.             return $value;
  51.         });
  52.         $latest_views $cache->get('latest_views', function (ItemInterface $item) use ($tracker) {
  53.             $item->expiresAfter(3600);
  54.             $value $tracker->get_latest_biens();
  55.             return $value;
  56.         });
  57.         # print_R($helper->html_region_list('entreprises-commerces', '', '', true)); exit();
  58.         $output = array(
  59.             'page_title'    => 'Vente Commerce, local commercial à louer, immobilier d’entreprise - Bizenco',
  60.             'page'          => 'homepage',
  61.             'loggedin'      => $user->loggedin(),
  62.             'search_comm_entre' => $helper->html_comm_list('entreprises-commerces'''''true),
  63.             'search_region_entre' => $helper->html_region_list('entreprises-commerces'''''true),
  64.             'search_comm_murs' => $helper->html_comm_list('murs-locaux-terrains'''''true),
  65.             'search_region_murs' => $helper->html_region_list('murs-locaux-terrains'''''true),
  66.             'popular_searches_entre' => $popular_searches_entre,
  67.             'popular_searches_murs' => $popular_searches_murs,
  68.             'recently_joined' => $recently_joined,
  69.             'latest_views' => $latest_views,
  70.             );
  71.         # Check for errors to display
  72.         if ($session->get('error')) {
  73.             $output['error'] = $session->get('error');
  74.             $session->set('error'null);
  75.         }
  76.         if ($session->get('last_search')) {
  77.             $output['last_search'] = $session->get('last_search');
  78.         }
  79.         return $this->render('default/index.html.twig'$output);
  80.     }
  81.     /**
  82.      * @Route("/", name="homepage", methods={"GET"})
  83.      */
  84.     public function defaultAction(Request $request)
  85.     {
  86.         $session $request->getSession();
  87.         $helper = new Helper($this->get('router'));
  88.         $user $this->get('app.users');
  89.         $tracker = new Tracker();
  90.         # Using of APCU cache highly updates speed
  91.         $cache = new ApcuAdapter($namespace='bizenco',$defaultLifetime=0,$version=null);
  92.         $popular_searches_entre $cache->get('popular_searches_entre', function (ItemInterface $item) use ($tracker) {
  93.             $item->expiresAfter(7200);
  94.             $value $tracker->get_popular_searches($this->get('router'), 112);
  95.             return $value;
  96.         });
  97.         $popular_searches_murs $cache->get('popular_searches_murs', function (ItemInterface $item) use ($tracker) {
  98.             $item->expiresAfter(7200);
  99.             $value $tracker->get_popular_searches($this->get('router'), 212);
  100.             return $value;
  101.         });
  102.         $tracker->get_popular_searches($this->get('router'), 210);
  103.         $recently_joined $cache->get('recently_joined', function (ItemInterface $item) use ($helper) {
  104.             $item->expiresAfter(86400);
  105.             $value $helper->recently_joined();
  106.             return $value;
  107.         });
  108.         $latest_views $cache->get('latest_views', function (ItemInterface $item) use ($tracker) {
  109.             $item->expiresAfter(3600);
  110.             $value $tracker->get_latest_biens();
  111.             return $value;
  112.         });
  113.         #print_R($helper->html_region_list2('entreprises-commerces', '', '', true)); exit();
  114.         #print_R($helper->html_region_list2('entreprises-commerces', '', '', false)); exit();
  115.         $output = array(
  116.             'page_title'    => 'Vente Commerce, local commercial à louer, immobilier d’entreprise - Bizenco',
  117.             'page'          => 'homepage',
  118.             'loggedin'      => $user->loggedin(),
  119.             'search_comm_entre' => $helper->html_comm_list('entreprises-commerces'''''true),
  120.             'search_comm_murs' => $helper->html_comm_list('murs-locaux-terrains'''''true),
  121.             'search_region_murs' => $helper->html_region_list2('murs-locaux-terrains'''''true),
  122.             'search_region_entre' => $helper->html_region_list2('entreprises-commerces'''''true),
  123.             'search_region_entre_ville' => $helper->html_region_list_ville('entreprises-commerces'''''''true),
  124.             'search_region_murs_ville' => $helper->html_region_list_ville('murs-locaux-terrains''''''',true),
  125.             'popular_searches_entre' => $popular_searches_entre,
  126.             'popular_searches_murs' => $popular_searches_murs,
  127.             'recently_joined' => $recently_joined,
  128.             'latest_views' => $latest_views,
  129.             'form_active' => 2
  130.         );
  131.         # Check for errors to display
  132.         if ($session->get('error')) {
  133.             $output['error'] = $session->get('error');
  134.             $session->set('error'null);
  135.         }
  136.         if ($session->get('last_search')) {
  137.             $output['last_search'] = $session->get('last_search');
  138.         }
  139.         return $this->render('default/index2.html.twig'$output);
  140.     }
  141.     /**
  142.      * @Route("/", name="search_redirects", methods={"POST"})
  143.      */
  144.     public function redirectAction(Request $request)
  145.     {
  146.         $session $request->getSession();
  147.         $params $request->request->all();
  148.         # Error detection
  149.         $error FALSE;
  150.         # Actaully allow blank search
  151.         #if ((empty($params['type']) &&
  152.         #        ($params['type'] != 'entreprises-commerces' || $params['type'] != 'murs-locaux-terrains')) ||
  153.         #        (empty($params['commerce_type']) && empty($params['departement']) && empty($params['region'])))
  154.         #        {
  155.         #            $error = TRUE;
  156.         #       }
  157.         if ($error) {
  158.             $error_obj Functions::alert_obj("Votre recherche n’a pas abouti!"'Veuillez réessayer'0);
  159.             $session->set('error'$error_obj);
  160.             return $this->redirect('/'301);
  161.         } else {
  162.             if (empty($params['departement'])) {
  163.                 $params['departement'] = null;
  164.                 # $params['departement'] = Constants::generic_departement;
  165.                 # $params['region'] = Constants::generic_region;
  166.             } elseif (empty($params['departement']) && !empty($params['region'])) {
  167.                 # $params['region'] = Functions::url_friendly($params['region']);
  168.                 $params['departement'] = Constants::generic_departement;
  169.             } else {
  170.                 #departement contains midi-pyrenees/aveyron, split and recreate
  171.                 # TODO: edit in case of ville?
  172.                 list($params['region'], $params['departement']) = explode('/'$params['departement']);
  173.                 $dep_id Functions::departement2id($params['departement'] . '-' $params['region']);
  174.                 $params['departement'] = $dep_id '-' $params['departement'];
  175.             }
  176.             if (empty($params['commerce_type']) || $params['commerce_type'] == '') {
  177.                 if ($params['departement']) {
  178.                     $params['commerce_type'] = Constants::generic_commerce_type;
  179.                 } else {
  180.                     $params['commerce_type'] = null;
  181.                 }
  182.             }
  183.             # Covert type to new form
  184.             if (!empty($params['type']) && $params['type'] == 'entreprises-commerces') {
  185.                 $params['type'] = 'vente';
  186.             } elseif (!empty($params['type']) && $params['type'] == 'murs-locaux-terrains') {
  187.                 if (!empty($params['transaction']) && $params['transaction'] == 'vente') {
  188.                     $params['type'] = 'vente-immobilier';
  189.                 } elseif (!empty($params['transaction']) && $params['transaction'] == 'location') {
  190.                     $params['type'] = 'location';
  191.                 } elseif (!empty($params['transaction']) && $params['transaction'] == 'cession-de-droit-au-bail') {
  192.                     $params['type'] = 'opportunites-investisseurs';
  193.                 } else {
  194.                     $params['type'] = 'tout';
  195.                 }
  196.             }
  197.             # Remove default values from query, to have better URLS
  198.             $twig $this->container->get('twig');
  199.             $globals $twig->getGlobals();
  200.             $max_slider $globals['max_slider'];
  201.             $price_arr = [];
  202.             if ($params['type'] == 'vente') {
  203.                 if (!empty($params['price_f'])) {
  204.                     $price_arr $params['price_f'];
  205.                 }
  206.             } else {
  207.                 if (!empty($params['price_m'])) {
  208.                     $price_arr $params['price_m'];
  209.                 }
  210.             }
  211.             $surface_arr = [];
  212.             if (!empty($params['surface_m'])) {
  213.                 $surface_arr $params['surface_m'];
  214.             }
  215.             // Clean up extra parameters:
  216.             unset($params['price_f']);
  217.             unset($params['price_m']);
  218.             unset($params['surface_m']);
  219.             # return Math.round((100 * (Math.pow(1.0471285480508996, num)-1))/10) * 10;
  220.             if (!empty($price_arr)) {
  221.                 $prices explode(';'$price_arr);
  222.                 if (isset($prices[0])) {
  223.                     $params['price-low'] = round(100 * (pow(1.0471285480508996intval($prices[0]))-1)/10) * 10 1000;
  224.                 }
  225.                 if (isset($prices[1])) {
  226.                     $params['price-high'] = round(100 * (pow(1.0471285480508996intval($prices[1]))-1)/10) * 10 1000;
  227.                 }
  228.             }
  229.             if (!empty($surface_arr)) {
  230.                 $surface explode(';'$surface_arr);
  231.                 if (isset($surface[0])) {
  232.                     $params['surface-min'] = round(100 * (pow(1.0471285480508996intval($surface[0]))-1)/10)  * 10;
  233.                 }
  234.                 if (isset($surface[1])) {
  235.                     $params['surface-max'] = round(100 * (pow(1.0471285480508996intval($surface[1]))-1)/10)  * 10;
  236.                 }
  237.             }
  238.             if (isset($params['price-low']) && $params['price-low'] == 0) unset($params['price-low']);
  239.             if (isset($params['price-high']) && $params['price-high'] == 9900000) unset($params['price-high']);
  240.             if (isset($params['surface-min']) && $params['surface-min'] == 0) unset($params['surface-min']);
  241.             if (isset($params['surface-max']) && ($params['surface-max'] == 9900 || $params['surface-max'] == '')) unset($params['surface-max']);
  242.             unset($params['region']);
  243.             unset($params['transaction']);
  244.             # Remove ville, if it is blanks
  245.             if (isset($params['ville']) && $params['ville'] == '') unset($params['ville']);
  246.             return $this->redirect($this->get('router')->generate(
  247.                     'search_results',
  248.                     $params), 301);
  249.         }
  250.      }
  251. }