Check if user is log
This commit is contained in:
parent
a5e453835b
commit
d2d043f7c1
@ -1,37 +1,53 @@
|
||||
<?php
|
||||
class Application_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract
|
||||
class Application_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$registry = Zend_Registry::getInstance();
|
||||
$session = new Zend_Session_Namespace('Zend_Auth');
|
||||
$translate = $registry->get('Zend_Translate');
|
||||
$currLocale = $translate->getLocale();
|
||||
|
||||
Zend_Registry::get('firebug')->info('Plugin Language');
|
||||
$user = new Scores_Utilisateur();
|
||||
|
||||
$lang = $request->getParam('lang', '');
|
||||
|
||||
switch ($lang) {
|
||||
case "fr":
|
||||
$langLocale = 'fr';
|
||||
break;
|
||||
case "en":
|
||||
$langLocale = 'en';
|
||||
break;
|
||||
default:
|
||||
$langLocale = $session->lang !='' ? $session->lang : $user->getLang();
|
||||
if ( $user->isLog() ) {
|
||||
$lang = $request->getParam('lang', '');
|
||||
|
||||
switch ($lang) {
|
||||
case "fr":
|
||||
$langLocale = 'fr';
|
||||
break;
|
||||
case "en":
|
||||
$langLocale = 'en';
|
||||
break;
|
||||
default:
|
||||
$langLocale = $session->lang !='' ? $session->lang : $user->getLang();
|
||||
}
|
||||
} else {
|
||||
$langLocale = 'fr';
|
||||
}
|
||||
|
||||
|
||||
$newLocale = new Zend_Locale();
|
||||
$newLocale->setLocale($langLocale);
|
||||
$registry->set('Zend_Locale', $newLocale);
|
||||
|
||||
|
||||
$session->lang = $langLocale;
|
||||
|
||||
$translate->setLocale($langLocale);
|
||||
|
||||
$this->setSessionLang($langLocale);
|
||||
|
||||
$registry->set('Zend_Translate', $translate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save new lang value into session
|
||||
* @param string $lang
|
||||
*/
|
||||
protected function setSessionLang($lang)
|
||||
{
|
||||
$authStorage = Zend_Auth::getInstance()->getStorage();
|
||||
$authData = $authStorage->read();
|
||||
if($authData)
|
||||
{
|
||||
$authData->lang = $lang;
|
||||
$authStorage->write($authData);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user