src/Services/Languages.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use App\Repository\LanguagesRepository;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. class Languages
  6. {
  7.     public function getLanguages()
  8.     {
  9.         $languages $this->languagesRepository->findBy([
  10.             'isActive' => true
  11.         ]);
  12.         if($languages){
  13.             return $languages;
  14.         }
  15.         else{
  16.             return null;
  17.         }
  18.     }
  19.     public function LanguageSelected()
  20.     {
  21.         $session $this->requestStack->getCurrentRequest()->getSession();
  22.         if( $session->get('selected_language')) {
  23.             $language $session->get('selected_language');
  24.             return $this->languagesRepository->findOneBy(['language' => $language]);
  25.         }
  26.         else{
  27.             $default_language $this->languagesRepository->findOneBy(['language' => 'English']);
  28.             if($default_language){
  29.                 return $default_language;
  30.             }
  31.             else{
  32.                 return null;
  33.             }
  34.         }
  35.     }
  36.     public function getSelectedLanguageCode()
  37.     {
  38.         $session $this->requestStack->getCurrentRequest()->getSession();
  39.         if( $session->get('selected_language')) {
  40.             $language $session->get('selected_language');
  41.             if ($language == 'English') {
  42.                 return '';
  43.             } elseif ($language == 'French') {
  44.                 return 'FR';
  45.             } elseif ($language == 'German') {
  46.                 return 'DE';
  47.             }
  48.         }
  49.         return '';
  50.     }
  51. public function getLanguagesByRankingOrder()
  52. {
  53.     return $this->languagesRepository->getLanguagesByRankingOrder();
  54. }
  55.     public function __construct(LanguagesRepository $languagesRepositoryRequestStack $requestStack)
  56.     {
  57.         $this->languagesRepository $languagesRepository;
  58.         $this->requestStack $requestStack;
  59.     }
  60. }