setLocale() public méthode

Sets the locale.
public setLocale ( string $locale )
$locale string
Exemple #1
0
 /**
  * Lists all Scheda entities.
  *
  * @Route("//{page}/{lang}", name="scheda", options={"expose": true}, defaults={"page" = 0, "lang" = "it"})
  * @Method("GET")
  * @Template()
  * 
  */
 public function indexAction(Request $request, $page, $lang)
 {
     $data = null;
     $esito = null;
     # $session = new Session();
     $session = $request->getSession();
     $session->start();
     if ($lang == "en") {
         $request->setLocale("en_EN");
         $session->set("lang", "en");
     } else {
         $request->setLocale("it_IT");
         $session->set("lang", "it");
     }
     if ($session->has("esito")) {
         $esito = $session->getFlashBag()->get("esito", array());
     }
     $form = $this->form_ricerca_rif();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
     }
     $entities = $this->getDoctrine()->getRepository("CasaFront2Bundle:Scheda")->scheda($data, $page);
     $entities2 = $this->getDoctrine()->getRepository("CasaFront2Bundle:Scheda")->scheda_pag($data);
     return array('form_ric' => $form->createView(), 'entities' => $entities, 'pag' => $entities2, 'esito' => $esito, 'page' => $page);
 }
 /**
  * Event handler that renders custom pages in case of a NotFoundHttpException (404)
  * or a AccessDeniedHttpException (403).
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ('dev' == $this->kernel->getEnvironment()) {
         return;
     }
     $exception = $event->getException();
     $this->request->setLocale($this->defaultLocale);
     $this->request->setDefaultLocale($this->defaultLocale);
     if ($exception instanceof NotFoundHttpException) {
         $section = $this->getExceptionSection(404, '404 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
         $response->setStatusCode(404);
         $event->setResponse($response);
     } elseif ($exception instanceof AccessDeniedHttpException) {
         $section = $this->getExceptionSection(403, '403 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
         $response->setStatusCode(403);
         $event->setResponse($response);
     }
 }
 public function language($language = null)
 {
     $session = $this->container->get('session');
     if ($language == null) {
         if (!$session->get('_locale')) {
             $session->set('_locale', 'en');
         }
         $language = $session->get('_locale');
     }
     if ($language) {
         $this->request->setLocale($language);
     }
     return '';
 }
 /**
  * @Route("/{slugs}", name="orbitale_cms_page", requirements={"slugs": "([a-zA-Z0-9_-]+\/?)*"}, defaults={"slugs": ""})
  *
  * @param Request     $request
  * @param string      $slugs
  * @param string|null $_locale
  *
  * @return Response
  */
 public function indexAction(Request $request, $slugs = '', $_locale = null)
 {
     if (preg_match('~/$~', $slugs)) {
         return $this->redirect($this->generateUrl('orbitale_cms_page', array('slugs' => rtrim($slugs, '/'))));
     }
     $this->request = $request;
     $this->request->setLocale($_locale ?: $this->request->getLocale());
     $slugsArray = preg_split('~/~', $slugs, -1, PREG_SPLIT_NO_EMPTY);
     $pages = $this->getPages($slugsArray);
     $currentPage = $this->getCurrentPage($pages, $slugsArray);
     if ($currentPage->isHomepage() && strlen($slugs)) {
         return $this->redirect($this->generateUrl('orbitale_cms_page', array('slugs' => '', '_locale' => $this->request->getLocale())));
     }
     return $currentPage instanceof Response ? $currentPage : $this->render('OrbitaleCmsBundle:Front:index.html.twig', array('pages' => $pages, 'page' => $currentPage));
 }
 /**
  * Index of the app
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $locale = $request->get('_locale');
     $request->setLocale($locale);
     $request->getSession()->set('_locale', $locale);
     $session = $request->getSession();
     $securityContext = $this->container->get('security.context');
     if ($securityContext->isGranted('ROLE_ADMIN')) {
         return $this->redirectToRoute('admin_homepage');
     } elseif ($securityContext->isGranted('ROLE_USER')) {
         return $this->redirectToRoute('user_homepage');
     } else {
         $authErrorKey = Security::AUTHENTICATION_ERROR;
         $lastUsernameKey = Security::LAST_USERNAME;
         // get the error if any (works with forward and redirect -- see below)
         if ($request->attributes->has($authErrorKey)) {
             $error = $request->attributes->get($authErrorKey);
         } elseif (null !== $session && $session->has($authErrorKey)) {
             $error = $session->get($authErrorKey);
             $session->remove($authErrorKey);
         } else {
             $error = null;
         }
         if (!$error instanceof AuthenticationException) {
             $error = null;
             // The value does not come from the security component.
         }
         // last username entered by the user
         $lastUsername = null === $session ? '' : $session->get($lastUsernameKey);
         $csrfToken = $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue();
         return $this->render('BaseBundle:Default:index.html.twig', array('last_username' => $lastUsername, 'error' => $error, 'csrf_token' => $csrfToken));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(Request $request, RequestAttributes $requestAttributes)
 {
     $portalInformation = $requestAttributes->getAttribute('portalInformation');
     if (!$portalInformation instanceof PortalInformation) {
         return new RequestAttributes();
     }
     $attributes = ['requestUri' => $request->getUri()];
     if (null !== ($localization = $portalInformation->getLocalization())) {
         $request->setLocale($localization->getLocalization());
     }
     $attributes['portalInformation'] = $portalInformation;
     $attributes['getParameter'] = $request->query->all();
     $attributes['postParameter'] = $request->request->all();
     $attributes['matchType'] = $portalInformation->getType();
     $attributes['redirect'] = $portalInformation->getRedirect();
     $attributes['analyticsKey'] = $portalInformation->getAnalyticsKey();
     $attributes['portalUrl'] = $portalInformation->getUrl();
     $attributes['webspace'] = $portalInformation->getWebspace();
     $attributes['portal'] = $portalInformation->getPortal();
     if ($portalInformation->getType() === RequestAnalyzerInterface::MATCH_TYPE_REDIRECT) {
         return new RequestAttributes($attributes);
     }
     $attributes['localization'] = $portalInformation->getLocalization();
     $attributes['segment'] = $portalInformation->getSegment();
     list($resourceLocator, $format) = $this->getResourceLocatorFromRequest($portalInformation, $request);
     $attributes['urlExpression'] = $portalInformation->getUrlExpression();
     $attributes['resourceLocator'] = $resourceLocator;
     $attributes['format'] = $format;
     $attributes['resourceLocatorPrefix'] = substr($portalInformation->getUrl(), strlen($request->getHttpHost()));
     if (null !== $format) {
         $request->setRequestFormat($format);
     }
     return new RequestAttributes($attributes);
 }
Exemple #7
0
 public function changeLocaleAction($code, Request $request)
 {
     $request->setLocale($code);
     $this->get('session')->set('_locale', $code);
     $referer = $request->headers->get('referer');
     return $this->redirect(empty($referer) ? "/" : $referer);
 }
 /**
  * Users profile
  *
  * @param Request $request
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function profileAction(Request $request)
 {
     //set language
     $locale = $request->get('_locale');
     $request->setLocale($locale);
     $request->getSession()->set('_locale', $locale);
     //Security control. Check user roles.
     $response = $this->checkUserRole($request);
     if ($response instanceof RedirectResponse) {
         return $response;
     }
     $user = $this->getUser();
     $user_id = $user->getId();
     $gravatar = $this->getGravatar($user->getEmail());
     $em = $this->getDoctrine()->getManager();
     $form = $this->createForm(new UpdateUserType($user));
     $form->handleRequest($request);
     if ($request->isMethod('POST') && $form->isValid()) {
         $data = $form->getData();
         $user->setFullName($data['fullName']);
         $user->setEmail($data['email']);
         $em->flush();
         $this->get('session')->getFlashBag()->add('correct', '');
     }
     //buscar log de usuario
     $logLogic = new Loglogic();
     $logger = $logLogic->getLog($user_id, $em, $this->get('translator'));
     //actualizar password
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->get('fos_user.change_password.form.factory');
     $formPassword = $formFactory->createForm();
     $formPassword->setData($user);
     return $this->render('BaseBundle:User:profile.html.twig', array('userData' => $user, 'form' => $form->createView(), 'logger' => $logger, 'gravatar' => $gravatar, 'formPassword' => $formPassword->createView()));
 }
 /**
  * Tests initializing the framework with a back end request.
  *
  * @runInSeparateProcess
  */
 public function testBackendRequest()
 {
     $request = new Request();
     $request->attributes->set('_route', 'dummy');
     $request->attributes->set('_scope', ContaoCoreBundle::SCOPE_BACKEND);
     $request->attributes->set('_contao_referer_id', 'foobar');
     $request->setLocale('de');
     $container = $this->mockContainerWithContaoScopes();
     $container->get('request_stack')->push($request);
     $framework = $this->mockContaoFramework($container->get('request_stack'), $this->mockRouter('/contao/install'));
     $framework->setContainer($container);
     $framework->initialize();
     $this->assertTrue(defined('TL_MODE'));
     $this->assertTrue(defined('TL_START'));
     $this->assertTrue(defined('TL_ROOT'));
     $this->assertTrue(defined('TL_REFERER_ID'));
     $this->assertTrue(defined('TL_SCRIPT'));
     $this->assertTrue(defined('BE_USER_LOGGED_IN'));
     $this->assertTrue(defined('FE_USER_LOGGED_IN'));
     $this->assertTrue(defined('TL_PATH'));
     $this->assertEquals('BE', TL_MODE);
     $this->assertEquals($this->getRootDir(), TL_ROOT);
     $this->assertEquals('foobar', TL_REFERER_ID);
     $this->assertEquals('contao/install', TL_SCRIPT);
     $this->assertEquals('', TL_PATH);
     $this->assertEquals('de', $GLOBALS['TL_LANGUAGE']);
 }
 /**
  * @Route("/recommendation/post")
  * @Route("/{lang}/recommendation/post")
  * @Method("POST")
  */
 public function postAction(Request $request, $lang = 'ar')
 {
     $translator = $this->container->get('translator');
     $preferencesService = $this->container->get('system_preferences_service');
     $to = $preferencesService->SendRecommendationEmail;
     $defaultFrom = $preferencesService->EmailFromAddress;
     $response = array();
     $parameters = $request->request->all();
     $request->setLocale($lang);
     $form = $this->container->get('form.factory')->create(new SendRecommendationType(), array(), array());
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $date = new \DateTime("now");
             $subject = $translator->trans('plugin.recommendation.email.subject', array('%name%' => $data['person_name']), 'messages');
             $body = '';
             foreach ($data as $name => $value) {
                 if ($name == 'person_name') {
                     $body .= '<b>' . $translator->trans('plugin.recommendation.form.label.person_group_label') . '</b><br>';
                 } elseif ($name == 'recommendee_name') {
                     $body .= '<br><b>' . $translator->trans('plugin.recommendation.form.label.recommendee_group_label') . '</b><br>';
                 }
                 $body .= $translator->trans('plugin.recommendation.form.label.' . $name) . ': ' . $value . '<br>';
             }
             $emailService = $this->container->get('email');
             $emailService->send($subject, $body, $to, $defaultFrom);
             $response['response'] = array('status' => true, 'message' => $translator->trans('plugin.recommendation.msg.success'));
         } else {
             $response['response'] = array('status' => false, 'message' => $translator->trans('plugin.recommendation.msg.invalid'));
         }
         return new JsonResponse($response);
     }
 }
Exemple #11
0
 public function listAction(Request $request, $filter)
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     if ($user != null) {
         $request->setLocale($user);
         $listEvent = null;
         $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->listEvents(null);
         return $this->render('MdyXlagendaBundle:Event:list.html.twig', array('listEvent' => $listEvent, 'filter' => $filter));
     } else {
         // utilisateur anonymous
         if ($request->isXmlHttpRequest()) {
             // il s'agit d'un appel AJAX
             if ($request->getMethod() == "POST") {
                 $filter = array();
                 $filter['lieu'] = $request->request->get('lieu');
                 $filter['rubrique'] = $request->request->get('rubrique');
                 $filter['dateDebut'] = $request->request->get('dateDebut');
                 $filter['dateFin'] = $request->request->get('dateFin');
                 $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->findFilter($filter);
                 return $this->render('MdyXlagendaBundle:Event:visitor.ajax.twig', array('listEvent' => $listEvent));
             } else {
             }
         } else {
             // il s'agit d'un appel "standard"
             $listEvent = $em->getRepository('MdyXlagendaBundle:Event')->myFindAll();
             $listLieu = $em->getRepository('MdyXlagendaBundle:Lieu')->findAll();
             $listRubrique = $em->getRepository('MdyXlagendaBundle:Rubrique')->findAll();
             return $this->render('MdyXlagendaBundle:Event:visitor.html.twig', array('listEvent' => $listEvent, 'listLieu' => $listLieu, 'listRubrique' => $listRubrique, 'filter' => null));
         }
     }
 }
 private function setLocale(Request $request, $locale)
 {
     $request->setLocale($locale);
     if (null !== $this->router) {
         $this->router->getContext()->setParameter('_locale', $request->getLocale());
     }
 }
Exemple #13
0
 public function setUp()
 {
     $request = new Request(['q-a' => 1, 'q-b' => 2], [], ['foo' => 'bar', 'fee' => 'bee', 'fii' => 'bii', 'int' => 9, '_route_params' => ['zee' => 'zar']]);
     $request->setLocale('en');
     $requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')->disableOriginalConstructor()->getMock();
     $requestStack->method('getCurrentRequest')->willReturn($request);
     $this->api = new BlockFilterApi($requestStack);
 }
Exemple #14
0
 /**
  * @param HttpRequest $request
  * @param string $locale
  */
 public function setLocale(HttpRequest $request, $locale)
 {
     setlocale(LC_ALL, $locale);
     $locale = substr($locale, 0, 2);
     $request->setLocale($locale);
     $this->translator->setLocale($locale);
     $this->translatable->setTranslatableLocale($locale);
 }
 public function changeLocalizationAction(Request $request, $_locale)
 {
     try {
         $request->setLocale($_locale);
         return new JsonResponse(array('success' => true));
     } catch (\Exception $ex) {
         return new JsonResponse(array('success' => false, 'message' => $ex->getMessage()));
     }
 }
 function it_sets_request_if_local_request_is_null($localeSettings, Request $request, ParameterBag $parameterBag)
 {
     $parameterBag->get('_locale')->willReturn(false);
     $request->attributes = $parameterBag;
     $localeSettings->getLanguage()->willReturn('fr_FR');
     $localeSettings->getLocale()->willReturn('fr_FR');
     $request->setLocale('fr_FR')->shouldBeCalled();
     $this->setRequest($request);
 }
 /**
  * @param Request $request
  */
 public function setRequest(Request $request = null)
 {
     if (!$request) {
         return;
     }
     if (!$request->attributes->get('_locale')) {
         $request->setLocale($this->localeSettings->getLanguage());
     }
     $this->setPhpDefaultLocale($this->localeSettings->getLocale());
 }
 public function indexAction(Request $request)
 {
     $actions = $this->container->get('templating')->get('actions');
     $html1 = $actions->render($actions->controller('TestBundle:Fragment:inlined', array('options' => array('bar' => new Bar(), 'eleven' => 11))));
     $html2 = $actions->render($actions->controller('TestBundle:Fragment:customformat', array('_format' => 'html')));
     $html3 = $actions->render($actions->controller('TestBundle:Fragment:customlocale', array('_locale' => 'es')));
     $request->setLocale('fr');
     $html4 = $actions->render($actions->controller('TestBundle:Fragment:forwardlocale'));
     return new Response($html1 . '--' . $html2 . '--' . $html3 . '--' . $html4);
 }
Exemple #19
0
 /**
  * @param Request $request
  * @param string $lang
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function switchLanguageAction(Request $request, $lang)
 {
     $request->getSession()->set('_locale', $lang);
     $request->setLocale($lang);
     $referer = $request->headers->get('referer');
     if ($referer == null) {
         $referer = $this->generateUrl('admin_homepage');
     }
     return $this->redirect($referer);
 }
Exemple #20
0
 public function setRequest(Request $request = null)
 {
     if (null === $request) {
         return;
     }
     if ($locale = $request->attributes->get('_locale')) {
         $request->setLocale($locale);
     }
     if (null !== $this->router) {
         $this->router->getContext()->setParameter('_locale', $request->getLocale());
     }
 }
 /**
  * Welcome controller.
  *
  * @Route("/" , name="user_dashboard_index")
  * @Method("GET")
  * @Template()
  */
 public function indexAction(Request $request)
 {
     $locale = $request->attributes->get('_locale', $request->getLocale());
     if ($locale == $request->attributes->get('_locale')) {
         $request->getSession()->set('_locale', $locale);
     } else {
         // if no explicit locale has been set on this request, use one from the session
         $request->setLocale($request->getSession()->get('_locale', $locale));
         //$this->defaultLocale));
     }
     return array('_locale' => $locale, 'admin_pool' => $this->container->get('sonata.admin.pool'));
 }
 /**
  * @Route("/{slug}/{locale}", name="icap_badge_badge_collection_share_view", defaults={"locale"= "fr"})
  * @Template
  */
 public function shareViewAction(Request $request, BadgeCollection $collection, $locale)
 {
     $request->setLocale($locale);
     if (!$collection->isIsShared()) {
         throw $this->createNotFoundException('Collection not shared.');
     }
     if (!$this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $showBanner = false;
     } else {
         $showBanner = $this->getUser() === $collection->getUser();
     }
     return array('collection' => $collection, 'user' => $collection->getUser(), 'showBanner' => $showBanner);
 }
Exemple #23
0
 /**
  * @param Request $request
  */
 public function setRequest(Request $request = null)
 {
     if (!$request) {
         return;
     }
     if ($this->isInstalled) {
         if (!$request->attributes->get('_locale')) {
             $request->setLocale($this->localeSettings->getLanguage());
         }
         $this->setPhpDefaultLocale($this->localeSettings->getLocale());
         $this->translatableListener->setTranslatableLocale($this->localeSettings->getLanguage());
     }
 }
 public function forwardEditAction(Request $request)
 {
     $entityManager = $this->get('doctrine.orm.entity_manager');
     $node = $entityManager->getRepository('AlpixelCMSBundle:Node')->find($request->get('id'));
     // Forward edit action from EN page set locale for admin to EN instead default locale
     $defaultLocale = $this->getParameter('default_locale');
     $request->setLocale($defaultLocale);
     if ($node !== null) {
         $instanceAdmin = $this->admin->getConfigurationPool()->getAdminByClass(get_class($node));
         if ($instanceAdmin !== null) {
             return $this->redirect($instanceAdmin->generateUrl('edit', ['id' => $request->get('id')]));
         }
     }
     $instanceAdmin = $this->admin->getConfigurationPool()->getInstance('alpixel_cms.admin.node');
     return $this->redirect($instanceAdmin->generateUrl('list'));
 }
 private function localeRedirect(Request $request, $loc)
 {
     // Enforce selected locale.
     $request->getSession()->set('_locale', $loc);
     $request->setLocale($loc);
     // TODO: handle missing
     // Get route of parent URL, e.g. 'home'.
     $parentRoute = $request->get('parent_route');
     $parentRouteParams = is_null($request->get('parent_route_params')) ? array() : $request->get('parent_route_params');
     // Generate URL with changed locale (won't pick up changes from the session, have to enforce).
     $url = $this->get('router')->generate($parentRoute, array('_locale' => $loc) + $parentRouteParams);
     // As a result of previous line, URL's that don't have locale in path, will get query ?_locale=...
     // Remove all queries as a solution
     // TODO: intelligently remove _locale, preserving other parameters, but ok for now as we don't use query
     return $this->redirect(parse_url($url, PHP_URL_PATH));
 }
Exemple #26
0
 /**
  * @param Request $request
  */
 public function setRequest(Request $request = null)
 {
     if (!$request) {
         return;
     }
     if ($this->getIsInstalled()) {
         if (!$request->attributes->get('_locale')) {
             $request->setLocale($this->getLocaleSettings()->getLanguage());
             if (null !== $this->getRouter()) {
                 $this->getRouter()->getContext()->setParameter('_locale', $this->getLocaleSettings()->getLanguage());
             }
         }
         $this->setPhpDefaultLocale($this->getLocaleSettings()->getLocale());
         $this->getTranslatableListener()->setTranslatableLocale($this->getLocaleSettings()->getLanguage());
     }
 }
 public function indexAction(Request $request)
 {
     /****Check language session*******/
     $session = $request->getSession();
     $user = $session->get('user');
     if (!empty($user)) {
         $lan = $session->get('language');
         $request->setLocale($lan);
         $type = $request->request->get('type');
         $em = $this->container->get('doctrine')->getManager();
         $typeid = 0;
         if ($type == 'Destination') {
             $destination = $em->createQuery("SELECT d FROM MytripAdminBundle:Destination d WHERE d.status='Active' AND d.url='" . $request->request->get('destination') . "'")->getArrayResult();
             $typeid = $destination[0]['destinationId'];
         } elseif ($type == 'Hostal') {
             $destination = $em->createQuery("SELECT d FROM MytripAdminBundle:Destination d WHERE d.status='Active' AND d.url='" . $request->request->get('destination') . "'")->getArrayResult();
             $hostal = $em->createQuery("SELECT d FROM MytripAdminBundle:Hostal d WHERE d.status='Active' AND d.destination='" . $destination[0]['destinationId'] . "' AND d.url='" . $request->request->get('hostal') . "'")->getArrayResult();
             $typeid = $hostal[0]['hostalId'];
         }
         if ($typeid > 0) {
             $reviews = new \Mytrip\AdminBundle\Entity\Review();
             $reviews->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($user['userId']));
             $reviews->setTypeId($typeid);
             $reviews->setReviewType($request->request->get('type'));
             $reviews->setRating($request->request->get('rate'));
             $reviews->setReview($request->request->get('review'));
             $reviews->setLan($lan);
             $reviews->setStatus('Active');
             $reviews->setCreatedDate(new \DateTime());
             $em->persist($reviews);
             $em->flush();
             $check = array('suc' => '1', 'msg' => $this->get('translator')->trans('Thanks for your interest on us'));
         } else {
             $check = array('suc' => '0', 'msg' => $this->get('translator')->trans('Sorry, Please try again'));
         }
     } else {
         $session->set('destination', $request->request->get('destination'));
         $session->set('hostal', $request->request->get('hostal'));
         $session->set('type', $request->request->get('type'));
         $session->set('rate', $request->request->get('rate'));
         $session->set('review', $request->request->get('review'));
         $session->set('created_date', new \DateTime());
         $this->get('session')->getFlashBag()->add('loginerror', $this->get('translator')->trans('Please Login'));
         $check = array('suc' => '2', 'msg' => $this->get('translator')->trans('Please Login'));
     }
     return new Response(json_encode($check));
 }
 public function infoAction(Request $request)
 {
     $jsonp = $request->query->get('jsonp');
     $locale = $request->query->get('_locale');
     if (isset($locale)) {
         $request->setLocale($locale);
     }
     $locale = $request->getLocale();
     $decklist_id = $request->query->get('decklist_id');
     $content = null;
     /* @var $user \Netrunnerdb\UserBundle\Entity\User */
     $user = $this->getUser();
     if ($user) {
         $user_id = $user->getId();
         $public_profile_url = $this->get('router')->generate('user_profile_view', array('_locale' => $this->getRequest()->getLocale(), 'user_id' => $user_id, 'user_name' => urlencode($user->getUsername())));
         $content = array('public_profile_url' => $public_profile_url, 'id' => $user_id, 'name' => $user->getUsername(), 'faction' => $user->getFaction(), 'locale' => $locale);
         if (isset($decklist_id)) {
             /* @var $em \Doctrine\ORM\EntityManager */
             $em = $this->get('doctrine')->getManager();
             /* @var $decklist \Netrunnerdb\BuilderBundle\Entity\Decklist */
             $decklist = $em->getRepository('NetrunnerdbBuilderBundle:Decklist')->find($decklist_id);
             if ($decklist) {
                 $decklist_id = $decklist->getId();
                 $dbh = $this->get('doctrine')->getConnection();
                 $content['is_liked'] = (bool) $dbh->executeQuery("SELECT\n        \t\t\t\tcount(*)\n        \t\t\t\tfrom decklist d\n        \t\t\t\tjoin vote v on v.decklist_id=d.id\n        \t\t\t\twhere v.user_id=?\n        \t\t\t\tand d.id=?", array($user_id, $decklist_id))->fetch(\PDO::FETCH_NUM)[0];
                 $content['is_favorite'] = (bool) $dbh->executeQuery("SELECT\n        \t\t\t\tcount(*)\n        \t\t\t\tfrom decklist d\n        \t\t\t\tjoin favorite f on f.decklist_id=d.id\n        \t\t\t\twhere f.user_id=?\n        \t\t\t\tand d.id=?", array($user_id, $decklist_id))->fetch(\PDO::FETCH_NUM)[0];
                 $content['is_author'] = $user_id == $decklist->getUser()->getId();
                 $content['can_delete'] = $decklist->getNbcomments() == 0 && $decklist->getNbfavorites() == 0 && $decklist->getNbvotes() == 0;
             }
         }
     }
     $content = json_encode($content);
     $response = new Response();
     $response->setPrivate();
     if (isset($jsonp)) {
         $content = "{$jsonp}({$content})";
         $response->headers->set('Content-Type', 'application/javascript');
     } else {
         $response->headers->set('Content-Type', 'application/json');
     }
     $response->setContent($content);
     return $response;
 }
 /**
  * Returns TRUE whether the given site matches the given request
  *
  * @param SiteInterface $site    A site instance
  * @param Request       $request A request instance
  *
  * @return string|boolean FALSE whether the site does not match
  */
 protected function matchRequest(SiteInterface $site, Request $request)
 {
     $results = array();
     // we read the value from the attribute to handle fragment support
     $requestPathInfo = $request->get('pathInfo', $request->getPathInfo());
     foreach ($site->getLanguageVersions() as $lv) {
         if (preg_match(sprintf('@^(%s)(/.*|$)@', $lv->getRelativePath()), $requestPathInfo, $results)) {
             $site->setHost($lv->getHost());
             $site->setLocale($lv->getLocale());
             $site->setRelativePath($lv->getRelativePath());
             $site->setTitle($lv->getTitle());
             $site->setMetaDescription($lv->getMetaDescription());
             $site->setMetaKeywords($lv->getMetaKeywords());
             $this->site = $site;
             $request->setLocale($lv->getLocale());
             $request->attributes->set('_locale', $lv->getLocale());
             return $results[2];
         }
     }
     return false;
 }
 public function indexAction(Request $request)
 {
     $locale = $request->getLocale();
     // $newLocal = $request->get('loc');
     $newLocal = $request->get('lang');
     // dump($newLocal);
     if (!$newLocal) {
         return new JsonResponse(['change' => false]);
     }
     if (!in_array($newLocal, ['en', 'ru'])) {
         return new JsonResponse(['change' => false]);
     }
     if ($locale == $newLocal) {
         return new JsonResponse(['change' => false]);
     }
     $session = $request->getSession();
     $request->setLocale($newLocal);
     // $request->setLocale('en');
     // dump($request->getLocale());
     $session->set('_locale', $newLocal);
     return new JsonResponse(['change' => true]);
 }