<?php
namespace Site\FrontendBundle\Controller;
use Site\FrontendBundle\Services\MemberService;
use Site\SharedBundle\Entity\Company;
use Site\SharedBundle\Entity\Language;
use Site\SharedBundle\Entity\User;
use Site\SharedBundle\Services\AuctionService;
use Site\SharedBundle\Services\CarService;
use Site\SharedBundle\Utils\VarUtils;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Site\SharedBundle\Entity\Menu;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Date;
class HomeController extends FrontendController {
public function indexAction() {
$welcomeText = null;
$seoMetadata = $this->siteService->getSeoMetadata();
if ($seoMetadata) {
$this->siteService->setPageTitle($seoMetadata['seo_title']);
$this->siteService->setPageDescription($seoMetadata['seo_description']);
$this->siteService->setPageKeyWords($seoMetadata['seo_keywords']);
}
if ($this->restrictWithFines()) {
return $this->redirectToFines();
}
$detectMobileBrowser = $this->detectMobileBrowser();
$template = 'FrontendBundle:Home:index.html.twig';
if ($detectMobileBrowser === 'isMobileBrowser'){
$template = 'FrontendBundle:Home/Mobile:index.html.twig';
}
return $this->render($template, ['main_page' => true, 'detectMobileBrowser' => $detectMobileBrowser]);
}
public function testAction() {
die();
}
public function headerAction() {
$menu = [];
/**
* @var $carService CarService
*/
$carService = $this->get('car_service');
/**
* @var $auctionService AuctionService
*/
$auctionService = $this->get('auction_service');
/**
* @var $memberService MemberService
*/
$memberService = $this->get('member_service');
$auctionFilter = ['not_ended' => 1];
$carFilter = ['with_auction' => 1, 'for_sale' => 1];
$auctionFilter['show_hidden'] = 0;
$auctionFilter['showHiddenFromAnonymous'] = 1;
$carFilter['show_hidden'] = 0;
$auctionFilter['user_location'] = $this->get('location.decoder')->getAddressDetails($_SERVER['REMOTE_ADDR']);
if ($memberService->hasUserSession()) {
$auctionFilter['show_hidden'] = $memberService->isTrusted();
$carFilter['show_hidden'] = $auctionFilter['show_hidden'];
$currentUserData = $memberService->getUserSession();
$auctionFilter['user_context'] = $currentUserData;
$carFilter['user_context'] = $currentUserData;
}
$carCount = $carService->getItemCount($carFilter, "");
$auctionCount = $auctionService->getAuctionCount($auctionFilter);
$pageRep = $this->getDoctrine()->getRepository('SharedBundle:Page');
$contactText = $pageRep->findOneBy(['active' => 1, 'menu_id' => Menu::CONTACT_US_BLOCK, 'language_id' => $this->getLangId()]);
$tmp = $this->getDoctrine()->getRepository('SharedBundle:Language')->findAll();
$langs = [];
foreach ($tmp as $item) {
$langs[] = ['name' => $item->getName(), 'short_name' => $item->getShortName(), 'id' => $item->getId(), 'active' => $item->getId() == $this->getLangId()];
}
$auctionsActive = $_SERVER['REQUEST_URI'] == $this->generateUrl('auction_list');
$carsActive = $_SERVER['REQUEST_URI'] == $this->generateUrl('homepage');
$showLogoLink = $_SERVER['REQUEST_URI'] != $this->generateUrl('homepage');
$currentUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$detectMobileBrowser = $this->detectMobileBrowser();
$template = 'FrontendBundle:Home:header.html.twig';
$params = ['menu' => $menu, 'contactText' => $contactText, 'carCount' => $carCount, 'auctionCount' => $auctionCount, 'langs' => $langs, 'auctionsActive' => $auctionsActive, 'carsActive' => $carsActive, 'currentUrl' => $currentUrl, 'showLogoLink' => $showLogoLink, 'detectMobileBrowser' => $detectMobileBrowser];
if ($detectMobileBrowser === 'isMobileBrowser'){
$session = $memberService->getUserSession();
$userId = $session['id'];
$params['accountData'] = $session;
$template = 'FrontendBundle:Home/Mobile:headerMobile.html.twig';
}
return $this->render($template, $params);
}
public function footerAction() {
$menu = [];
$pagesRepo = $this->getDoctrine()->getRepository('SharedBundle:Page');
$pages = $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::BOTTOM_MENU, 'active' => 1],
['sort' => 'asc']);
$seoPages = $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::SEO_MENU, 'active' => 1],
['sort' => 'asc']);
$carService = $this->get('car_service');
$auctionService = $this->get('auction_service');
$memberService = $this->get('member_service');
$auctionFilter = ['not_ended' => 1];
$carFilter = ['with_auction' => 1, 'for_sale' => 1];
$auctionFilter['show_hidden'] = 0;
$carFilter['show_hidden'] = 0;
$auctionFilter['user_location'] = $this->get('location.decoder')->getAddressDetails($_SERVER['REMOTE_ADDR']);
if ($memberService->hasUserSession()) {
$auctionFilter['show_hidden'] = $memberService->isTrusted();
$carFilter['show_hidden'] = $auctionFilter['show_hidden'];
$currentUserData = $memberService->getUserSession();
$auctionFilter['user_context'] = $currentUserData;
$carFilter['user_context'] = $currentUserData;
}
$params = ['startTime' => time() + 1];
$params['carCount'] = $carService->getItemCount($carFilter, "");
$params['auctionCount'] = $auctionService->getAuctionCount($auctionFilter);
foreach ($pages as $page) {
$menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0, 'show_count' => false];
}
$seoMenu = [];
foreach ($seoPages as $page) {
$seoMenu[] = ['name' => $page->getName(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0, 'show_count' => false];
}
foreach ($menu as $key => $menuItem) {
if ($key == 0) {
if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
$menu[$key]['active'] = 1;
}
} else {
if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
$menu[$key]['active'] = 1;
}
}
}
$params['has_small_footer'] = empty($seoMenu);
$seoMenu = VarUtils::splitArray($seoMenu, 3);
$params['menu'] = $menu;
$params['seoMenu'] = $seoMenu;
$showPrintFooter = false;
if (strpos($_SERVER["REQUEST_URI"], 'auctions/car') !== false) {
$showPrintFooter = true;
}
if ($showPrintFooter) {
$companyLt = $this->getDoctrine()->getRepository('SharedBundle:Company')->find(Company::CAROUTLET_UAB);
// $companyDe = $this->getDoctrine()->getRepository('SharedBundle:Company')->find(Company::CAROUTLET_GMBH);
$contactsLt = $this->getDoctrine()->getRepository('SharedBundle:CompanyContact')->findBy(['company_id' => Company::CAROUTLET_UAB]);
// $contactsDe = $this->getDoctrine()->getRepository('SharedBundle:CompanyContact')->findBy(array('company_id' => Company::CAROUTLET_GMBH));
$tmp = $contactsLt;
$contacts = [];
foreach ($tmp as $item) {
$contacts[$item->getType()] = $item;
}
$params['company'] = $companyLt;
$params['contacts'] = $contacts;
}
$params['showPrintFooter'] = $showPrintFooter;
$params['detectMobileBrowser'] = $this->detectMobileBrowser();
$memberService = $this->get('member_service');
$params['user'] = $memberService->getUserSession();
return $this->render('FrontendBundle:Home:footer.html.twig', $params);
}
public function promoAction() {
$params = [];
$params['detectMobileBrowser'] = $this->detectMobileBrowser();
$template = 'FrontendBundle:Home:promo.html.twig';
if ($params['detectMobileBrowser'] === 'isMobileBrowser'){
$template = 'FrontendBundle:Home/Mobile:promo.html.twig';
$rulesPageName = 'error';
$criteria = [
'tag' => 'terms',
'language_id' => $this->getLangId(),
'menu_id'=> 11
];
$page = $this->getDoctrine()->getRepository('SharedBundle:Page')->findOneBy($criteria);
if ($page) {
$rulesPageName = $page->getSafeName();
}
$params['rulesPageName'] = $rulesPageName;
}
return $this->render($template, $params);
}
public function topMenuAction() {
$formedMenu = $this->formMenuList();
$blockHtml = $this->render('FrontendBundle:Home:topMenu.html.twig', ['menu' => $formedMenu]);
return $blockHtml;
}
public function mobileMenuAction() {
$formedMenu = $this->formMenuMobileList();
$blockHtml = $this->render('FrontendBundle:Home/Mobile:mobileMenu.html.twig', ['menu' => $formedMenu]);
return $blockHtml;
}
private function formMenuList() {
$menu = [];
$pagesRepo = $this->getDoctrine()->getRepository('SharedBundle:Page');
$pages = $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::TOP, 'active' => 1],
['sort' => 'asc']);
foreach ($pages as $page) {
$menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0, 'show_count' => false];
}
foreach ($menu as $key => $menuItem) {
if ($key == 0) {
if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
$menu[$key]['active'] = 1;
}
} else {
if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
$menu[$key]['active'] = 1;
}
}
}
return $menu;
}
private function formMenuMobileList() {
$menu = [];
$pagesRepo = $this->getDoctrine()->getRepository('SharedBundle:Page');
$pages = $pagesRepo->findBy(['language_id' => $this->getLangId(), 'menu_id' => \Site\SharedBundle\Entity\Menu::MOBILE, 'active' => 1],
['sort' => 'asc']);
foreach ($pages as $page) {
$menu[] = ['name' => $page->getName(), 'ico' => $page->getMenuCssClass(), 'url' => $this->generateUrl('page_view', ['name' => $page->getSafeName()]), 'active' => 0, 'show_count' => false];
}
foreach ($menu as $key => $menuItem) {
if ($key == 0) {
if ($_SERVER["REQUEST_URI"] == $menuItem['url']) {
$menu[$key]['active'] = 1;
}
} else {
if (strpos($_SERVER["REQUEST_URI"], $menuItem['url']) === 0) {
$menu[$key]['active'] = 1;
}
}
}
return $menu;
}
public function breadcrumbsAction() {
$breadcrumbs = $this->siteService->getBreadcrumbs();
/* if (!empty($breadcrumbs)) {
$homeItem = array('name' => $this->__('Home'), 'url' => '/');
$breadcrumbs = array_merge(array($homeItem), $breadcrumbs);
}
*/
$auction = $this->getRequest()->get('auction');
$params = ['breadcrumbs' => $breadcrumbs];
if (!empty($auction) && is_numeric($auction)) {
$params['auction'] = $auction;
}
$params['detectMobileBrowser'] = $this->detectMobileBrowser();
$template = 'FrontendBundle:Home:_breadcrumbs.html.twig';
if ($params['detectMobileBrowser'] === 'isMobileBrowser'){
$template = 'FrontendBundle:Home/Mobile:_breadcrumbs.html.twig';
}
return $this->render($template, $params);
}
public function scAction($sk) {
$lib_dir = dirname($this->get('kernel')->getContainer()->getParameter('kernel.cache_dir'), 3) . "/vendor/secureimage/";
require_once($lib_dir . 'securimage.php');
$img = new \securimage();
$img->session_var = $sk;
if (!empty($_SESSION[$img->session_var])) {
$img->code = $_SESSION[$img->session_var];
}
$img->show();
die();
}
public function notificationsAction() {
$params = [];
// check some default notifications
$memberService = $this->get('member_service');
$mute = false;
$errorNotifications = [];
$infoNotifications = [];
$flash = [];
if (strpos($_SERVER['REQUEST_URI'], 'register') !== false) {
$mute = true;
}
if (!$mute) {
// Show cookie message
if (empty($_COOKIE['accept_cookies'])) {
$this->siteService->addInfoNotification($this->__('CookieAcceptanceText'), true, 'accept_cookies');
}
if ($memberService->hasUserSession()) {
$currentUserData = $memberService->getUserSession();
// Show messages from user_notifications
$language_interface_id = $this->getLangId();
/** @var Language $language */
$language = $this->getDoctrine()->getRepository('SharedBundle:Language')->find($language_interface_id);
$em = $this->getDoctrine()->getManager();
/** @var User $user */
$user = $em->getRepository('SharedBundle:User')->find($currentUserData['id']);
$userNotifications = $em->getRepository('SharedBundle:UserNotification')->getForUser($user, $language);
foreach ($userNotifications as $userNotification) {
if ($userNotification['important']) {
$this->siteService->addErrorNotification($userNotification['message']);
} else {
$this->siteService->addInfoNotification($userNotification['message']);
}
}
// Show logistic messages
if (!empty($currentUserData['show_waiting_for_email_confirmation'])) {
$this->siteService->addInfoNotification($this->__('RegistrationSuccessText7Format', ['%email%' => $currentUserData['email']]));
}
if (!empty($currentUserData['show_fines'])) {
$this->siteService->addErrorNotification($this->__('NotificationFines'));
} elseif (!empty($currentUserData['show_waiting_for_passport'])) {
$this->siteService->addInfoNotification($this->__('NotificationWaitingForPassport'));
} elseif (!empty($currentUserData['show_waiting_for_company_documents'])) {
$this->siteService->addInfoNotification($this->__('NotificationWaitingForCompanyDocuments'));
} elseif (!empty($currentUserData['show_waiting_for_documents_check'])) {
$this->siteService->addInfoNotification($this->__('NotificationWaitingForDocumentsCheck'));
}
if (empty($currentUserData['show_fines'])) {
if (!empty($currentUserData['show_waiting_for_online_confirmation'])) {
$this->siteService->addInfoNotification($this->__('NotificationConfirmOnlineCars'));
}
}
if ($memberService->isUserUntrustedNotPaid()) {
$this->siteService->addErrorNotification($this->__('YouCantByCarBecauseNotPaydForLastConfirm'), false, 'untrusted_not_paid_msg');
}
}
$session = $this->get('session');
$mutedNotifications = $session->get('mutedNotifications');
if (empty($mutedNotifications)) {
$mutedNotifications = [];
}
$errorNotifications = $this->siteService->getErrorNotifications();
foreach ($errorNotifications as $key => $item) {
if (in_array($item['hash'], $mutedNotifications)) {
unset($errorNotifications[$key]);
}
}
$infoNotifications = $this->siteService->getInfoNotifications();
foreach ($infoNotifications as $key => $item) {
if (in_array($item['hash'], $mutedNotifications)) {
unset($infoNotifications[$key]);
}
}
$flash = $this->siteService->getFlash();
}
$params['error'] = $errorNotifications;
$params['info'] = $infoNotifications;
$params['flash'] = $flash;
return $this->render('FrontendBundle:Home:_notifications.html.twig', $params);
}
public function notificationMuteAction($hash) {
$session = $this->get('session');
$mutedNotifications = $session->get('mutedNotifications');
if (empty($mutedNotifications)) {
$mutedNotifications = [];
}
$mutedNotifications[] = $hash;
$session->set('mutedNotifications', $mutedNotifications);
return $this->renderJson(['success' => 1]);
}
public function acceptCookiesAction() {
setcookie('accept_cookies', '1', ['expires' => time() + 3600 * 24 * 365 * 10, 'path' => '/']);
return $this->renderJson(['success' => 1]);
}
/*
public function addMailForSubscriptionAction(){
$result = array();
$email_address = $this->getRequest()->get('email');
$user_name = $this->getRequest()->get('user_name');
$email_unsubscribe = $this->getRequest()->get('email_unsubscribe');
$user = $this->get('user_service');
if (!empty($email_unsubscribe)){
if ($user->unsubscribeEmail($email_unsubscribe)) {
$result['result'] = 'successful';
}else{
$result['result'] = 'fail';
}
} else {
if ($user->addEmailToDatabase($email_address,$user_name)) {
$result['result'] = 'successful';
}else{
$result['result'] = 'fail';
}
}
return $this->renderJson($result);
}*/
}