src/Site/FrontendBundle/Controller/HomeController.php line 132

Open in your IDE?
  1. <?php
  2. namespace Site\FrontendBundle\Controller;
  3. use Site\FrontendBundle\Services\MemberService;
  4. use Site\SharedBundle\Entity\Company;
  5. use Site\SharedBundle\Entity\Language;
  6. use Site\SharedBundle\Entity\User;
  7. use Site\SharedBundle\Services\AuctionService;
  8. use Site\SharedBundle\Services\CarService;
  9. use Site\SharedBundle\Utils\VarUtils;
  10. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  11. use Site\SharedBundle\Entity\Menu;
  12. use Symfony\Component\Config\Definition\Exception\Exception;
  13. use Symfony\Component\HttpKernel\Exception\FlattenException;
  14. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Validator\Constraints\Date;
  18. class HomeController extends FrontendController {
  19.     
  20.     public function indexAction() {
  21.         
  22.         $welcomeText null;
  23.         $seoMetadata $this->siteService->getSeoMetadata();
  24.         if ($seoMetadata) {
  25.             $this->siteService->setPageTitle($seoMetadata['seo_title']);
  26.             $this->siteService->setPageDescription($seoMetadata['seo_description']);
  27.             $this->siteService->setPageKeyWords($seoMetadata['seo_keywords']);
  28.         }
  29.         if ($this->restrictWithFines()) {
  30.             return $this->redirectToFines();
  31.         }
  32.         $detectMobileBrowser $this->detectMobileBrowser();
  33.         $template 'FrontendBundle:Home:index.html.twig';
  34.         
  35.         if ($detectMobileBrowser === 'isMobileBrowser'){
  36.             $template 'FrontendBundle:Home/Mobile:index.html.twig';
  37.         }
  38.         return $this->render($template, ['main_page' => true'detectMobileBrowser' => $detectMobileBrowser]);
  39.     }
  40.     
  41.     public function testAction() {
  42.                     
  43.         die();
  44.     }
  45.     public function headerAction() {
  46.         
  47.         $menu = [];
  48.         /**
  49.          * @var $carService CarService
  50.          */
  51.         $carService $this->get('car_service');
  52.         /**
  53.          * @var $auctionService AuctionService
  54.          */
  55.         $auctionService $this->get('auction_service');
  56.         /**
  57.          * @var $memberService MemberService
  58.          */
  59.         $memberService $this->get('member_service');
  60.         $auctionFilter = ['not_ended' => 1];
  61.         $carFilter = ['with_auction' => 1'for_sale' => 1];
  62.         $auctionFilter['show_hidden'] = 0;
  63.         $auctionFilter['showHiddenFromAnonymous'] = 1;
  64.         $carFilter['show_hidden'] = 0;
  65.         $auctionFilter['user_location'] = $this->get('location.decoder')->getAddressDetails($_SERVER['REMOTE_ADDR']);
  66.         if ($memberService->hasUserSession()) {
  67.             $auctionFilter['show_hidden'] = $memberService->isTrusted();
  68.             $carFilter['show_hidden'] = $auctionFilter['show_hidden'];
  69.             $currentUserData $memberService->getUserSession();
  70.             $auctionFilter['user_context'] = $currentUserData;
  71.             $carFilter['user_context'] = $currentUserData;
  72.         }
  73.         $carCount $carService->getItemCount($carFilter"");
  74.         $auctionCount $auctionService->getAuctionCount($auctionFilter);
  75.         $pageRep $this->getDoctrine()->getRepository('SharedBundle:Page');
  76.         $contactText $pageRep->findOneBy(['active' => 1'menu_id' => Menu::CONTACT_US_BLOCK'language_id' => $this->getLangId()]);
  77.         $tmp $this->getDoctrine()->getRepository('SharedBundle:Language')->findAll();
  78.         $langs = [];
  79.         foreach ($tmp as $item) {
  80.             $langs[] = ['name' => $item->getName(), 'short_name' => $item->getShortName(), 'id' => $item->getId(), 'active' => $item->getId() == $this->getLangId()];
  81.         }
  82.         $auctionsActive $_SERVER['REQUEST_URI'] == $this->generateUrl('auction_list');
  83.         $carsActive $_SERVER['REQUEST_URI'] == $this->generateUrl('homepage');
  84.         $showLogoLink =  $_SERVER['REQUEST_URI'] != $this->generateUrl('homepage');
  85.         $currentUrl $_SERVER['REQUEST_SCHEME'] . '://' $_SERVER['SERVER_NAME'] .  $_SERVER['REQUEST_URI'];
  86.         $detectMobileBrowser $this->detectMobileBrowser();
  87.         $template 'FrontendBundle:Home:header.html.twig';
  88.        
  89.         $params = ['menu' => $menu'contactText' => $contactText'carCount' => $carCount'auctionCount' => $auctionCount'langs' => $langs'auctionsActive' => $auctionsActive'carsActive' => $carsActive'currentUrl' => $currentUrl'showLogoLink' => $showLogoLink'detectMobileBrowser' => $detectMobileBrowser];
  90.         
  91.         if ($detectMobileBrowser === 'isMobileBrowser'){
  92.             $session $memberService->getUserSession();
  93.             $userId $session['id'];
  94.             $params['accountData'] = $session;
  95.             $template 'FrontendBundle:Home/Mobile:headerMobile.html.twig';
  96.         } 
  97.         return $this->render($template$params);
  98.     }
  99.     public function footerAction() {
  100.                     
  101.         $menu = [];
  102.         $pagesRepo $this->getDoctrine()->getRepository('SharedBundle:Page');
  103.         $pages $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::BOTTOM_MENU'active' => 1],
  104.                                     ['sort' => 'asc']);
  105.         $seoPages $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::SEO_MENU'active' => 1],
  106.             ['sort' => 'asc']);
  107.         $carService $this->get('car_service');
  108.         $auctionService $this->get('auction_service');
  109.         $memberService $this->get('member_service');
  110.         $auctionFilter = ['not_ended' => 1];
  111.         $carFilter = ['with_auction' => 1'for_sale' => 1];
  112.         $auctionFilter['show_hidden'] = 0;
  113.         $carFilter['show_hidden'] = 0;
  114.         $auctionFilter['user_location'] = $this->get('location.decoder')->getAddressDetails($_SERVER['REMOTE_ADDR']);
  115.         if ($memberService->hasUserSession()) {
  116.             $auctionFilter['show_hidden'] = $memberService->isTrusted();
  117.             $carFilter['show_hidden'] = $auctionFilter['show_hidden'];
  118.             $currentUserData $memberService->getUserSession();
  119.             $auctionFilter['user_context'] = $currentUserData;
  120.             $carFilter['user_context'] = $currentUserData;
  121.         }
  122.         $params = ['startTime' => time() + 1];
  123.         $params['carCount'] = $carService->getItemCount($carFilter"");
  124.         $params['auctionCount'] = $auctionService->getAuctionCount($auctionFilter);
  125.         foreach ($pages as $page) {
  126.             $menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0'show_count' => false];
  127.         }
  128.         $seoMenu = [];
  129.         foreach ($seoPages as $page) {
  130.             $seoMenu[] = ['name' => $page->getName(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0'show_count' => false];
  131.         }
  132.         
  133.         foreach ($menu as $key => $menuItem) {
  134.             if ($key == 0) {
  135.                 if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
  136.                     $menu[$key]['active'] = 1;
  137.                 }
  138.             } else {
  139.                 if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
  140.                     $menu[$key]['active'] = 1;
  141.                 }
  142.             }    
  143.         }
  144.         $params['has_small_footer'] = empty($seoMenu);
  145.         $seoMenu VarUtils::splitArray($seoMenu3);
  146.         $params['menu'] = $menu;
  147.         $params['seoMenu'] = $seoMenu;
  148.         $showPrintFooter false;
  149.         if (strpos($_SERVER["REQUEST_URI"], 'auctions/car') !== false) {
  150.             $showPrintFooter true;
  151.         }
  152.         if ($showPrintFooter) {
  153.             $companyLt $this->getDoctrine()->getRepository('SharedBundle:Company')->find(Company::CAROUTLET_UAB);
  154.            // $companyDe = $this->getDoctrine()->getRepository('SharedBundle:Company')->find(Company::CAROUTLET_GMBH);
  155.             $contactsLt $this->getDoctrine()->getRepository('SharedBundle:CompanyContact')->findBy(['company_id' => Company::CAROUTLET_UAB]);
  156.          //   $contactsDe = $this->getDoctrine()->getRepository('SharedBundle:CompanyContact')->findBy(array('company_id' => Company::CAROUTLET_GMBH));
  157.             $tmp $contactsLt;
  158.             $contacts = [];
  159.             foreach ($tmp as $item) {
  160.                 $contacts[$item->getType()] = $item;
  161.             }
  162.             $params['company'] = $companyLt;
  163.             $params['contacts'] = $contacts;
  164.         }
  165.         $params['showPrintFooter'] = $showPrintFooter;
  166.         $params['detectMobileBrowser'] = $this->detectMobileBrowser();
  167.         $memberService $this->get('member_service');
  168.         $params['user'] = $memberService->getUserSession();
  169.         return $this->render('FrontendBundle:Home:footer.html.twig'$params);
  170.     }
  171.     public function promoAction() {
  172.         $params = [];
  173.         $params['detectMobileBrowser'] = $this->detectMobileBrowser();
  174.         $template 'FrontendBundle:Home:promo.html.twig';
  175.         
  176.         if ($params['detectMobileBrowser'] === 'isMobileBrowser'){
  177.             $template 'FrontendBundle:Home/Mobile:promo.html.twig';
  178.             $rulesPageName 'error';
  179.             $criteria = [
  180.                 'tag' => 'terms'
  181.                 'language_id' => $this->getLangId(),
  182.                 'menu_id'=> 11
  183.             ];
  184.             
  185.             $page $this->getDoctrine()->getRepository('SharedBundle:Page')->findOneBy($criteria);
  186.             
  187.             if ($page) {
  188.                 $rulesPageName $page->getSafeName();
  189.             }
  190.             $params['rulesPageName'] = $rulesPageName;
  191.         }
  192.         return $this->render($template$params);
  193.     }
  194.     public function topMenuAction() {
  195.         $formedMenu $this->formMenuList();
  196.         $blockHtml $this->render('FrontendBundle:Home:topMenu.html.twig', ['menu' => $formedMenu]);
  197.         return $blockHtml;
  198.     }
  199.     public function mobileMenuAction() {
  200.         $formedMenu $this->formMenuMobileList();
  201.         $blockHtml $this->render('FrontendBundle:Home/Mobile:mobileMenu.html.twig', ['menu' => $formedMenu]);
  202.         return $blockHtml;
  203.     }
  204.     private function formMenuList() {
  205.         $menu = [];
  206.         $pagesRepo $this->getDoctrine()->getRepository('SharedBundle:Page');
  207.         $pages $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::TOP'active' => 1],
  208.                                     ['sort' => 'asc']);
  209.         foreach ($pages as $page) {
  210.             $menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0'show_count' => false];
  211.         }
  212.         foreach ($menu as $key => $menuItem) {
  213.             if ($key == 0) {
  214.                 if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
  215.                     $menu[$key]['active'] = 1;
  216.                 }
  217.             } else {
  218.                 if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
  219.                     $menu[$key]['active'] = 1;
  220.                 }
  221.             }
  222.         }
  223.         return $menu;
  224.     }
  225.     private function formMenuMobileList() {
  226.         $menu = [];
  227.         $pagesRepo $this->getDoctrine()->getRepository('SharedBundle:Page');
  228.         $pages $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::MOBILE'active' => 1],
  229.                                     ['sort' => 'asc']);
  230.         foreach ($pages as $page) {
  231.             $menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0'show_count' => false];
  232.         }
  233.         foreach ($menu as $key => $menuItem) {
  234.             if ($key == 0) {
  235.                 if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
  236.                     $menu[$key]['active'] = 1;
  237.                 }
  238.             } else {
  239.                 if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
  240.                     $menu[$key]['active'] = 1;
  241.                 }
  242.             }
  243.         }
  244.         return $menu;
  245.     }
  246.     
  247.     public function breadcrumbsAction() {
  248.                 
  249.         $breadcrumbs $this->siteService->getBreadcrumbs();
  250.         
  251.         
  252.     /*    if (!empty($breadcrumbs)) {
  253.             $homeItem = array('name' => $this->__('Home'), 'url' => '/');
  254.             $breadcrumbs = array_merge(array($homeItem), $breadcrumbs);
  255.         }
  256.     */
  257.         $auction $this->getRequest()->get('auction');
  258.         $params = ['breadcrumbs' => $breadcrumbs];
  259.         if (!empty($auction) && is_numeric($auction)) {
  260.             $params['auction'] = $auction;
  261.         }
  262.         $params['detectMobileBrowser'] = $this->detectMobileBrowser();
  263.         $template 'FrontendBundle:Home:_breadcrumbs.html.twig';
  264.         if ($params['detectMobileBrowser'] === 'isMobileBrowser'){
  265.             $template 'FrontendBundle:Home/Mobile:_breadcrumbs.html.twig';
  266.         }
  267.         
  268.         return $this->render($template$params);
  269.     }
  270.     public function scAction($sk) {
  271.         $lib_dir dirname($this->get('kernel')->getContainer()->getParameter('kernel.cache_dir'), 3) . "/vendor/secureimage/";
  272.         
  273.         require_once($lib_dir 'securimage.php');
  274.             
  275.         $img = new \securimage();
  276.         $img->session_var $sk;
  277.         
  278.         if (!empty($_SESSION[$img->session_var])) {
  279.             $img->code $_SESSION[$img->session_var];
  280.         }
  281.         
  282.         $img->show();
  283.         die();
  284.     }
  285.     public function notificationsAction() {
  286.         $params = [];
  287.         // check some default notifications
  288.         $memberService $this->get('member_service');
  289.         $mute false;
  290.         $errorNotifications = [];
  291.         $infoNotifications = [];
  292.         $flash = [];
  293.         if (strpos($_SERVER['REQUEST_URI'], 'register') !== false) {
  294.             $mute true;
  295.         }
  296.         if (!$mute) {
  297.             // Show cookie message
  298.             if (empty($_COOKIE['accept_cookies'])) {
  299.                 $this->siteService->addInfoNotification($this->__('CookieAcceptanceText'), true'accept_cookies');
  300.             }
  301.             if ($memberService->hasUserSession()) {
  302.                 $currentUserData $memberService->getUserSession();
  303.                 // Show messages from user_notifications
  304.                 $language_interface_id $this->getLangId();
  305.                 /** @var Language $language */
  306.                 $language $this->getDoctrine()->getRepository('SharedBundle:Language')->find($language_interface_id);
  307.                 $em $this->getDoctrine()->getManager();
  308.                 /** @var User $user */
  309.                 $user $em->getRepository('SharedBundle:User')->find($currentUserData['id']);
  310.                 $userNotifications $em->getRepository('SharedBundle:UserNotification')->getForUser($user$language);
  311.                 foreach ($userNotifications as $userNotification) {
  312.                             if ($userNotification['important']) {
  313.                                 $this->siteService->addErrorNotification($userNotification['message']);
  314.                             } else {
  315.                                 $this->siteService->addInfoNotification($userNotification['message']);
  316.                             }
  317.                 }
  318.                 // Show logistic messages
  319.                 if (!empty($currentUserData['show_waiting_for_email_confirmation'])) {
  320.                     $this->siteService->addInfoNotification($this->__('RegistrationSuccessText7Format', ['%email%' => $currentUserData['email']]));
  321.                 }
  322.                 if (!empty($currentUserData['show_fines'])) {
  323.                     $this->siteService->addErrorNotification($this->__('NotificationFines'));
  324.                 } elseif (!empty($currentUserData['show_waiting_for_passport'])) {
  325.                     $this->siteService->addInfoNotification($this->__('NotificationWaitingForPassport'));
  326.                 } elseif (!empty($currentUserData['show_waiting_for_company_documents'])) {
  327.                     $this->siteService->addInfoNotification($this->__('NotificationWaitingForCompanyDocuments'));
  328.                 } elseif (!empty($currentUserData['show_waiting_for_documents_check'])) {
  329.                     $this->siteService->addInfoNotification($this->__('NotificationWaitingForDocumentsCheck'));
  330.                 }
  331.                 if (empty($currentUserData['show_fines'])) {
  332.                     if (!empty($currentUserData['show_waiting_for_online_confirmation'])) {
  333.                         $this->siteService->addInfoNotification($this->__('NotificationConfirmOnlineCars'));
  334.                     }
  335.                 }
  336.                 if ($memberService->isUserUntrustedNotPaid()) {
  337.                     $this->siteService->addErrorNotification($this->__('YouCantByCarBecauseNotPaydForLastConfirm'), false'untrusted_not_paid_msg');
  338.                 }
  339.             }
  340.             $session $this->get('session');
  341.             $mutedNotifications $session->get('mutedNotifications');
  342.             if (empty($mutedNotifications)) {
  343.                 $mutedNotifications = [];
  344.             }
  345.             $errorNotifications $this->siteService->getErrorNotifications();
  346.             foreach ($errorNotifications as $key => $item) {
  347.                 if (in_array($item['hash'], $mutedNotifications)) {
  348.                     unset($errorNotifications[$key]);
  349.                 }
  350.             }
  351.             $infoNotifications $this->siteService->getInfoNotifications();
  352.             foreach ($infoNotifications as $key => $item) {
  353.                 if (in_array($item['hash'], $mutedNotifications)) {
  354.                     unset($infoNotifications[$key]);
  355.                 }
  356.             }
  357.             $flash $this->siteService->getFlash();
  358.         }
  359.         $params['error'] = $errorNotifications;
  360.         $params['info'] = $infoNotifications;
  361.         $params['flash'] = $flash;
  362.         return $this->render('FrontendBundle:Home:_notifications.html.twig'$params);
  363.     }
  364.     public function notificationMuteAction($hash) {
  365.         $session $this->get('session');
  366.         $mutedNotifications $session->get('mutedNotifications');
  367.         if (empty($mutedNotifications)) {
  368.             $mutedNotifications = [];
  369.         }
  370.         $mutedNotifications[] = $hash;
  371.         $session->set('mutedNotifications'$mutedNotifications);
  372.         return $this->renderJson(['success' => 1]);
  373.     }
  374.     public function acceptCookiesAction() {
  375.         setcookie('accept_cookies''1', ['expires' => time() + 3600 24 365 10'path' => '/']);
  376.         return $this->renderJson(['success' => 1]);
  377.     }
  378. /*
  379.     public function  addMailForSubscriptionAction(){
  380.         $result = array();
  381.         $email_address = $this->getRequest()->get('email');
  382.         $user_name = $this->getRequest()->get('user_name');
  383.         $email_unsubscribe = $this->getRequest()->get('email_unsubscribe');
  384.         $user = $this->get('user_service');
  385.         if (!empty($email_unsubscribe)){
  386.             if ($user->unsubscribeEmail($email_unsubscribe)) {
  387.                 $result['result'] = 'successful';
  388.             }else{
  389.                 $result['result'] = 'fail';
  390.             }
  391.         } else {
  392.             if ($user->addEmailToDatabase($email_address,$user_name)) {
  393.                 $result['result'] = 'successful';
  394.             }else{
  395.                 $result['result'] = 'fail';
  396.             }
  397.         }
  398.         return $this->renderJson($result);
  399.     }*/
  400. }