src/AppBundle/Controller/BienController.php line 91

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. # use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use AppBundle\Includes\Database;
  10. use AppBundle\Includes\Settings;
  11. use AppBundle\Includes\Helper;
  12. use AppBundle\Includes\Tracker;
  13. use AppBundle\Includes\Users;
  14. use AppBundle\Includes\Functions;
  15. use AppBundle\Includes\Constants;
  16. //http://bizenco2/entreprises-commerces/provence-alpes-azur/13-bouches-du-rhone/commerce-a-vendre/vente-bouches-du-rhone-provence-alpes-azur----66-1324.html
  17. //http://bizenco2/entreprises-commerces/provence-alpes-azur/13-bouches-du-rhone/commerce-a-vendre/
  18. class BienController extends AbstractController
  19. {
  20.     //entreprises-commerces/basse-normandie/14-calvados/bar-tabac/vente-bar-licence-iv-petite-restauration-geo_situtation--1-3412.html
  21.     /**
  22.      * @Route("/{type}/{region}/{departement}/{commerce_type}/{title}--{geo_situation}--{id}.html",
  23.      * requirements={"type": "entreprises-commerces|murs-locaux-terrains", "title": "[a-zA-Z0-9\-]+", "geo_situation": "[a-zA-Z0-9\-]*"},
  24.      * defaults={"departement": "departement", "commerce_type": "commerce-type"},
  25.      * name="bien_display_old", methods={"GET", "POST"})
  26.      */
  27.     public function displayOldAction(Request $request$type$region$departement$commerce_type$title$geo_situation$id)
  28.     {
  29.         $helper = new Helper($this->get('router'));
  30.         $input = Array('id' => $id);
  31.         $bien $helper->db_select($input'id');
  32.         if (empty($bien)) {
  33.             $session $request->getSession();
  34.             # Bien not found
  35.             $error_obj Functions::alert_obj('Référence invalide!''Ce bien n’est pas présent dans notre base de donnée'0);
  36.             # Get commerce text and department text
  37.             $com_id Functions::com_type2id($commerce_type);
  38.             $dep_id Functions::departement2id("$departement");
  39.             $com_str "";
  40.             if ($com_id) {
  41.                 $com_str Functions::id2com_type($com_idfalse);
  42.             }
  43.             $departement_str "";
  44.             if ($dep_id) {
  45.                 $dep_strs Functions::id2departement($dep_idfalsefalse);
  46.                 $departement_str "{$dep_strs[0]}";
  47.             }
  48.             if ($type == 'murs-locaux-terrains') {
  49.                 $type 'tout';
  50.             } else {
  51.                 $type 'vente';
  52.             }
  53.             $session->set('error'$error_obj);
  54.             if ($com_str && $com_str) {
  55.                 $session->set('redirect_page'"/$type/$commerce_type/$departement/");
  56.                 $session->set('redirect_text'"$com_str à vendre en $departement_str");
  57.             } else {
  58.                 $session->set('redirect_text'"");
  59.             }
  60.             # Cause an better 404 error with more info using session variables
  61.             # Use the throw, or else it really causes a blank 404 error
  62.             throw $this->createNotFoundException('Ce bien n’est pas présent dans notre base de donnée');
  63.         }
  64.         $bien $bien[0]; # We have only one bien
  65.         $params $helper->bien_url_params($bien);
  66.         return $this->redirect($this->get('router')->generate('bien_display'$params), 301);
  67.     }
  68.     //entreprises-commerces/basse-normandie/14-calvados/bar-tabac/vente-bar-licence-iv-petite-restauration-geo_situtation--1-3412.html
  69.     /**
  70.      * @Route("/{type}/{commerce_type}/{departement}/{title}--{geo_situation}--{id}.html",
  71.      * requirements={"type": "vente|vente-immobilier|location|opportunites-investisseurs", "title": "[a-zA-Z0-9\-]+", "geo_situation": "[a-zA-Z0-9\-]*"},
  72.      * defaults={"departement": "departement", "commerce_type": "commerce-type"},
  73.      * name="bien_display", methods={"GET", "POST"})
  74.      */
  75.     public function displayAction(Request $request$type$departement$commerce_type$title$geo_situation$id)
  76.     {
  77.         $helper = new Helper($this->get('router'));
  78.         $user $this->get('app.users');
  79.         $tracker = new Tracker();
  80.           $input = Array('id' => $id);
  81.         $bien $helper->db_select($input'id');
  82.         $session $request->getSession();
  83.         if (empty($bien)) {
  84.             # Bien not found
  85.             $error_obj Functions::alert_obj('Référence invalide!''Ce bien n’est pas présent dans notre base de donnée'0);
  86.             # Get commerce text and department text
  87.             $com_id Functions::com_type2id($commerce_type);
  88.             $dep_id Functions::departement2id("$departement");
  89.             $com_str "";
  90.             if ($com_id) {
  91.                 $com_str Functions::id2com_type($com_idfalse);
  92.             }
  93.             $departement_str "";
  94.             if ($dep_id) {
  95.                 $dep_strs Functions::id2departement($dep_idfalsefalse);
  96.                 $departement_str "{$dep_strs[0]}";
  97.             }
  98.             $session->set('error'$error_obj);
  99.             if ($com_str && $departement_str) {
  100.                 $session->set('redirect_page'"/$type/$commerce_type/$departement/");
  101.                 $session->set('redirect_text'"$com_str à vendre en $departement_str");
  102.             }
  103.             # Cause an better 404 error with more info using session variables
  104.             # Use the throw, or else it really causes a blank 404 error
  105.             throw $this->createNotFoundException('Ce bien n’est pas présent dans notre base de donnée');
  106.         }
  107.         $bien $bien[0]; # We have only one bien
  108.         if ($geo_situation == 'n-a') {
  109.             # url contains geo_situation, which could be empty. Correct and redirect
  110.             $geo_situation '';
  111.             #print_r($bien);
  112.             $params $helper->bien_url_params($bien);
  113.             return $this->redirect($this->get('router')->generate('bien_display'$params), 301);
  114.         }
  115.         
  116.         $params $helper->bien_url_params($bien);
  117.         if ($params['departement']         != $departement     ||
  118.             $params['commerce_type']     != $commerce_type     ||
  119.             $params['title']             != $title            ||
  120.             $params['geo_situation']     != $geo_situation)
  121.         {
  122.             # Instead of doing an error, redirect to correct page!
  123.             #$error_obj = Functions::alert_obj('Paramètres de l’URL non valides!', 'Une erreur est intervenue lors de la construction de l’URL', 0);
  124.             #$session->set('error', $error_obj);
  125.             #return $this->redirect('/', 301);
  126.             $params $helper->bien_url_params($bien);
  127.             return $this->redirect($this->get('router')->generate('bien_display'$params), 301);
  128.         }
  129.         # $bien variable is used later, but I need title set
  130.         $bien['title']                    = $helper->bien_title($bien);
  131.         $bien_refined['title']              = $helper->bien_title($bien);
  132.         $bien_refined['id']                 = $id;
  133.         $bien_refined['biz_id']           = $bien['biz_id'];
  134.         $bien_refined['reference']        = $bien['reference'];
  135.         $bien_refined['date']             = $bien['date'];
  136.         $bien_refined['type']               = $bien['type'];
  137.         $bien_refined['type_transaction'] = $bien['type_transaction'];
  138.         $bien_refined['forme_juridique']  = $bien['forme_juridique'];
  139.         $bien_refined['licence']          = $bien['licence'];
  140.         $bien_refined['rent_price']       = Functions::euro_num($bien['rent_price']);
  141.         $bien_refined['designation']      = $bien['designation'];
  142.         $bien_refined['geo_situation']    = $bien['geo_situation'];
  143.         $bien_refined['departement']       = $bien['departement'];
  144.         $bien_refined['commerce_type']       = $bien['commerce_type'];
  145.         $bien_refined['ca_ht']            = Functions::euro_num($bien['price_ht']);
  146.         $bien_refined['profit']           = Functions::euro_num($bien['profit']);
  147.         $bien_refined['salaire_dirigeant']= Functions::euro_num($bien['salaire_dirigeant']);
  148.         $bien_refined['price']            = Functions::euro_num($bien['price']);
  149.         $bien_refined['price_com']        = Functions::euro_num($bien['price_com']);
  150.         $bien_refined['price_fonds']      = Functions::euro_num($bien['price_fonds']);
  151.         $bien_refined['price_murs']       = Functions::euro_num($bien['price_murs']);
  152.         $bien_refined['description']      = Functions::str_filter(strip_tags($bien['description']));
  153.         $bien_refined['conditions']       = $bien['conditions'];
  154.         $bien_refined['picture1']         = $bien['picture1'];
  155.         $bien_refined['stationnement']    = $bien['stationnement'];
  156.         $bien_refined['appartement']      = $bien['appartement'];
  157.         $bien_refined['superficie']       = $bien['superficie'];
  158.         $bien_refined['achat_marchandise'] = Functions::euro_num($bien['achat_marchandise']);
  159.         if ($bien['logement'] == 1)
  160.             $bien_refined['logement'] = 'Oui';
  161.         else
  162.             $bien_refined['logement'] = 'Non';
  163.         $bien_refined['motif_cession']    = $bien['motif_cession'];
  164.         $bien_refined['detail_bail']      = $bien['detail_bail'] ? $bien['detail_bail'] : 'N/A';
  165.         $bien_refined['locaux']           = $bien['locaux'];
  166.         $bien_refined['materiel']         = $bien['materiel'];
  167.         $bien_refined['horaire_ouverture']= $bien['horaire_ouverture'];
  168.         $bien_refined['fermeture_hebdo']  = $bien['fermeture_hebdo'];
  169.         $bien_refined['fermeture_an']     = $bien['fermeture_an'];
  170.         $bien_refined['salaire']          = Functions::euro_num($bien['salaire']);
  171.         $bien_refined['ebe']              = Functions::euro_num($bien['ebe']);
  172.         # Calculate Loyer Annuel HT et HC / m2
  173.         $bien_refined['ht_m2']               = Functions::euro_num('');
  174.         $bien_refined['found_communes']   = $bien['found_communes'];
  175.         $bien_refined['url']              = $request->getUri();
  176.         $bien_refined['region_ld']        = Functions::id2region($bien['departement']);
  177.         $bien_refined['departement_ld']   = Functions::id2departement($bien['departement'], False)[0];
  178.         $bien_refined['commerce_type_ld'] = Functions::id2com_type($bien['commerce_type'], False);
  179.         # Mail nego stuff
  180.         if (!empty($bien_refined['superficie']) && $bien_refined['superficie'] != 0)
  181.             $bien_refined['ht_m2'] = Functions::euro_num(intval($bien['rent_price']) * 12 intval($bien['superficie']));
  182.                         
  183.         foreach ($bien_refined as $key => $value) {
  184.             if ($value == '') {
  185.                 if ($key == 'picture1') {  # In case of empty image, place a filler at least
  186.                     $bien_refined["$key"] = '/images/bizenco_b.png';
  187.                 } else {
  188.                     $bien_refined["$key"] = 'N/A';
  189.                 }
  190.             } else {
  191.                 $bien_refined["$key"] = Functions::str_filter($value);
  192.             }
  193.         }
  194.         # Comparer section
  195.         if (in_array($bien_refined['id'], $helper->cookie['comparer']))
  196.             $in_comparer True;
  197.         else
  198.             $in_comparer False;
  199.         # most likely will use agent data already in bien (specific agent), else use agent defaults!
  200.         $ag_keys = Array(
  201.             'tele_portable' => 'portable_nego',
  202.             'tele_fixe' => 'tel_nego',
  203.             'prenom' => 'prenom_nego',
  204.             'nom' => 'nom_nego',
  205.             'email' => 'mail_nego'
  206.         );
  207.         $agents_info $user->get_agents_list($bien['site_id']);
  208.         # Handle problematic agents with their images:
  209.         if (in_array($agents_info['id'], Constants::$block_images_agents)) {
  210.             $replace_img = !empty($agents_info['logo']) ? $agents_info['logo'] : '/images/agents/default.png';
  211.             $bien_refined $helper->replace_image($bien_refined$replace_img);
  212.         }
  213.         foreach ($ag_keys as $key => $value) {
  214.             if (isset($bien[$value]) && $bien[$value] != '') {
  215.                 $agents_info[$key] = $bien[$value];
  216.             }
  217.         }
  218.         # In some formats, they only have NOM for agence
  219.         if (!empty($bien['nom_nego']) && empty($bien['prenom_nego'])) {
  220.             $agents_info['prenom'] = '';
  221.         }
  222.         # Also add agent email to bien_refined, used later
  223.         $bien_refined['email'] = $agents_info['email'];
  224.         # Add bien to the visited list
  225.         $helper->history_add($id$bien);
  226.         # print_r($helper->breadcrumb($bien_refined)); exit();
  227.         # Limit page description & remove html tags
  228.         $page_description "{$bien_refined['description']}";
  229.         $page_description Functions::str_filter($page_description);
  230.         $page_description substr($page_description050);
  231.         $output = array(
  232.             'page_title'    => Functions::str_filter("{$bien_refined['title']} - $id"),
  233.             'page_description' => $page_description,
  234.             'social_title'    => Functions::str_filter("{$bien_refined['title']}"),
  235.             'social_image'    => $bien_refined['picture1'],
  236.             'social_description' => $bien_refined['description'],
  237.             'breadcrumb'    => $helper->breadcrumb($bien_refined),
  238.             'page'          => 'display',
  239.             'loggedin'      => $user->loggedin(),
  240.             'bien'            => $bien_refined,
  241.             'history'        => $helper->history_get(),
  242.             'in_comparer'    => $in_comparer,
  243.             'agent_info'    => $agents_info,
  244.             );
  245.         # Handle user interest in Bien
  246.         if (isset($_POST) && !empty($_POST)) {
  247.             // TODO: check bien_interest function that handles the email
  248.             $output['error'] = $user->bien_interest($_POST$bien_refined);
  249.         }
  250.         $session $request->getSession();
  251.         # If logged in, can prepare some info to sent mail fast
  252.         if ($session->get('email') && !$session->get('user_info')) {
  253.             $session_userinfo = Array();
  254.             $user_info $user->ret_user_info($session->get('email') );
  255.             $session_userinfo['name'] = "{$user_info['nom']} {$user_info['prenom']}";
  256.             $session_userinfo['email'] = $session->get('email');
  257.             $session_userinfo['subject'] = "Demande d’information sur la réf. {$bien_refined['reference']}";
  258.             $session_userinfo['telephone'] = "";
  259.             $session_userinfo['message'] = "";
  260.             $session->set('user_info'$session_userinfo);
  261.         }
  262.         
  263.         # Auto-fill some info
  264.         if ($session->get('user_info'))
  265.             $output['user_info'] = $session->get('user_info');
  266.         
  267.         # Pick between print or normal mode
  268.         if (isset($_GET['mode']) && $_GET['mode'] == 'print') {
  269.             return $this->render('display/bien_printable.html.twig'$output);
  270.         } else {
  271.             $lsrcInput $session->get('last_search');
  272.             if (is_array($lsrcInput)) {
  273.                 # print_r($lsrcInput);
  274.                 $results $helper->db_select($lsrcInput'similar');
  275.                 $srcRes $helper->refine_results($results);
  276.                 # Handle similar pages
  277.                 $prev null;
  278.                 if (is_array($srcRes) && !empty($srcRes)) {
  279.                     # Find current ID
  280.                     foreach ($srcRes as $key => $res) {
  281.                         if ($bien_refined['biz_id'] == $res['biz_id']) {
  282.                             $numIt 5;
  283.                             if ($numIt count($srcRes)) $numIt count($srcRes);
  284.                             # Emulate circular relation for array
  285.                             $slice array_slice($srcRes$key+1$numIt);
  286.                             if ($numIt count($slice)) {
  287.                                 $slice2 array_slice($srcRes0$numIt count($slice));
  288.                                 $slice array_merge($slice$slice2);
  289.                             }
  290.                             $output['last_search_results'] = $slice;
  291.                             # Next item for nagivate prev, next
  292.                             if (count($slice)) {
  293.                                 $output['next_search'] = $slice[0]['url'];
  294.                             } else {
  295.                                 $output['next_search'] = Array();
  296.                             }
  297.                             $output['prev_search'] = $prev;
  298.                             break;
  299.                         }
  300.                         $prev $res['url'];
  301.                     }
  302.                 }
  303.             }
  304.             # Do those things only in normal mode
  305.             # Add bien to the visited list
  306.             $helper->history_add($id$bien_refined);
  307.             # Latest Entries Display
  308.             $tracker->add_bien($bien_refined);
  309.             return $this->render('display/bien.html.twig'$output);
  310.         }
  311.     }
  312. }