src/Controller/LanguageController.php
public function changeLanguageAction()
    {
        $langId = $this->params()->fromQuery('langId', null);
        $locale = '';
        $success = true;
        $errors = array();
        if (empty($langId) || !is_numeric($langId) || $langId <= 0)
            $success = false;

        $melisLangTable = $this->serviceLocator->get('MelisCore\Model\Tables\MelisLangTable');
        $melisUserTable = $this->serviceLocator->get('MelisCore\Model\Tables\MelisUserTable');
        $melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');

        $datasLang = $melisLangTable->getEntryById($langId);

        // If the language was found and then exists
        if (!empty($datasLang))
        {
            $datasLang = $datasLang->current();
            
            // Update session locale for melis BO
            $container = new Container('meliscore');
            if($container) {
                $container['melis-lang-id'] = $langId;
                if(isset($datasLang->lang_locale)){
                    $container['melis-lang-locale'] = $datasLang->lang_locale;
                    $container['melis-login-lang-locale'] = $datasLang->lang_locale;
                }
            }
            
            // If user is connected
            if ($melisCoreAuth->hasIdentity())
            {
                // Get user id from session auth
                $userAuthDatas =  $melisCoreAuth->getStorage()->read();
                $userId = $userAuthDatas->usr_id;

                // Update auth user session
                $userAuthDatas->usr_lang_id = $langId;

                // Update user table
                $datasUser = $melisUserTable->save(array('usr_lang_id' => $langId), $userId);
                
                $flashMsgSrv = $this->getServiceLocator()->get('MelisCoreFlashMessenger');
                $flashMsgSrv->clearFlashMessage();
                $this->getEventManager()->trigger('meliscore_get_recent_user_logs', $this, array());
            }
        }
        else
        {
            $success = false;
            $errors[] = 'Language not found';
        }

        $jsonModel = new JsonModel();
        $jsonModel->setVariables(array(
            'success' => $success,
            'errors' => $errors,
        ));

        return $jsonModel;
    }
public function changeLanguageAction()
    {
        $langId = $this->params()->fromQuery('langId', null);
        $locale = '';
        $success = true;
        $errors = array();
        if (empty($langId) || !is_numeric($langId) || $langId <= 0)
            $success = false;

        $melisLangTable = $this->serviceLocator->get('MelisCore\Model\Tables\MelisLangTable');
        $melisUserTable = $this->serviceLocator->get('MelisCore\Model\Tables\MelisUserTable');
        $melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');

        $datasLang = $melisLangTable->getEntryById($langId);

        // If the language was found and then exists
        if (!empty($datasLang))
        {
            $datasLang = $datasLang->current();
            
            // Update session locale for melis BO
            $container = new Container('meliscore');
            if($container) {
                $container['melis-lang-id'] = $langId;
                if(isset($datasLang->lang_locale)){
                    $container['melis-lang-locale'] = $datasLang->lang_locale;
                    $container['melis-login-lang-locale'] = $datasLang->lang_locale;
                }
            }
            
            // If user is connected
            if ($melisCoreAuth->hasIdentity())
            {
                // Get user id from session auth
                $userAuthDatas =  $melisCoreAuth->getStorage()->read();
                $userId = $userAuthDatas->usr_id;

                // Update auth user session
                $userAuthDatas->usr_lang_id = $langId;

                // Update user table
                $datasUser = $melisUserTable->save(array('usr_lang_id' => $langId), $userId);
                
                $flashMsgSrv = $this->getServiceLocator()->get('MelisCoreFlashMessenger');
                $flashMsgSrv->clearFlashMessage();
                $this->getEventManager()->trigger('meliscore_get_recent_user_logs', $this, array());
            }
        }
        else
        {
            $success = false;
            $errors[] = 'Language not found';
        }

        $jsonModel = new JsonModel();
        $jsonModel->setVariables(array(
            'success' => $success,
            'errors' => $errors,
        ));

        return $jsonModel;
    }
public function changeLanguageAction ( ) { $ langId = $ this -> params ( ) -> fromQuery ( 'langId' , null ) ; $ locale = '' ; $ success = true ; $ errors = array ( ) ; if ( empty ( $ langId ) || ! is_numeric ( $ langId ) || $ langId <= 0 ) $ success = false ; $ melisLangTable = $ this -> serviceLocator -> get ( 'MelisCore\Model\Tables\MelisLangTable' ) ; $ melisUserTable = $ this -> serviceLocator -> get ( 'MelisCore\Model\Tables\MelisUserTable' ) ; $ melisCoreAuth = $ this -> serviceLocator -> get ( 'MelisCoreAuth' ) ; $ datasLang = $ melisLangTable -> getEntryById ( $ langId ) ; // If the language was found and then exists if ( ! empty ( $ datasLang ) ) { $ datasLang = $ datasLang -> current ( ) ; // Update session locale for melis BO $ container = new Container ( 'meliscore' ) ; if ( $ container ) { $ container [ 'melis-lang-id' ] = $ langId ; if ( isset ( $ datasLang -> lang_locale ) ) { $ container [ 'melis-lang-locale' ] = $ datasLang -> lang_locale ; $ container [ 'melis-login-lang-locale' ] = $ datasLang -> lang_locale ; } } // If user is connected if ( $ melisCoreAuth -> hasIdentity ( ) ) { // Get user id from session auth $ userAuthDatas = $ melisCoreAuth -> getStorage ( ) -> read ( ) ; $ userId = $ userAuthDatas -> usr_id ; // Update auth user session $ userAuthDatas -> usr_lang_id = $ langId ; // Update user table $ datasUser = $ melisUserTable -> save ( array ( 'usr_lang_id' => $ langId ) , $ userId ) ; $ flashMsgSrv = $ this -> getServiceLocator ( ) -> get ( 'MelisCoreFlashMessenger' ) ; $ flashMsgSrv -> clearFlashMessage ( ) ; $ this -> getEventManager ( ) -> trigger ( 'meliscore_get_recent_user_logs' , $ this , array ( ) ) ; } } else { $ success = false ; $ errors [ ] = 'Language not found' ; } $ jsonModel = new JsonModel ( ) ; $ jsonModel -> setVariables ( array ( 'success' => $ success , 'errors' => $ errors , ) ) ; return $ jsonModel ; }
Change the language

@return \Zend\View\Model\JsonModel
Change the language