mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
Localization: user profile ++ language
SVN:trunk[356]
This commit is contained in:
@@ -336,6 +336,12 @@ class UserRightsMatrix extends UserRightsAddOnAPI
|
||||
return $oLogin->Get('userid');
|
||||
}
|
||||
|
||||
// this module does not handle localization
|
||||
public function GetUserLanguage($sUserName)
|
||||
{
|
||||
return 'EN US';
|
||||
}
|
||||
|
||||
public function GetContactId($sUserName)
|
||||
{
|
||||
// this module has no link with the business data
|
||||
|
||||
@@ -47,6 +47,11 @@ class UserRightsNull extends UserRightsAddOnAPI
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function GetUserLanguage($sUserName)
|
||||
{
|
||||
return 'EN US';
|
||||
}
|
||||
|
||||
public function GetContactId($sUserName)
|
||||
{
|
||||
// this module has no link with the business data
|
||||
|
||||
@@ -68,6 +68,8 @@ class URP_Users extends UserRightsBaseClass
|
||||
MetaModel::Init_AddAttribute(new AttributeString("login", array("allowed_values"=>null, "sql"=>"login", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
|
||||
MetaModel::Init_AddAttribute(new AttributePassword("password", array("allowed_values"=>null, "sql"=>"pwd", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
|
||||
|
||||
MetaModel::Init_AddAttribute(new AttributeEnum("language", array("allowed_values"=>new ValueSetEnum('EN US,FR FR'), "sql"=>"language", "default_value"=>"EN US", "is_null_allowed"=>false, "depends_on"=>array())));
|
||||
|
||||
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("profiles", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"userid", "ext_key_to_remote"=>"profileid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
|
||||
|
||||
//MetaModel::Init_InheritFilters();
|
||||
@@ -76,7 +78,7 @@ class URP_Users extends UserRightsBaseClass
|
||||
MetaModel::Init_AddFilterFromAttribute("password");
|
||||
|
||||
// Display lists
|
||||
MetaModel::Init_SetZListItems('details', array('userid', 'first_name', 'email', 'login')); // Attributes to be displayed for the complete details
|
||||
MetaModel::Init_SetZListItems('details', array('userid', 'first_name', 'email', 'login', 'language')); // Attributes to be displayed for the complete details
|
||||
MetaModel::Init_SetZListItems('list', array('first_name', 'last_name', 'login')); // Attributes to be displayed for a list
|
||||
// Search criteria
|
||||
MetaModel::Init_SetZListItems('standard_search', array('login', 'userid')); // Criteria of the std search form
|
||||
@@ -942,6 +944,18 @@ exit;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetUserLanguage($sUserName)
|
||||
{
|
||||
if (array_key_exists($sUserName, $this->m_aLogin2UserId))
|
||||
{
|
||||
// This happens really when the list of users is being loaded into the cache!!!
|
||||
$iUserId = $this->m_aLogin2UserId[$sUserName];
|
||||
$oUser = $this->m_aUsers[$iUserId];
|
||||
return $oUser->Get('language');
|
||||
}
|
||||
return 'EN US';
|
||||
}
|
||||
|
||||
public function GetContactId($sUserName)
|
||||
{
|
||||
if (array_key_exists($sUserName, $this->m_aLogin2UserId))
|
||||
|
||||
@@ -47,13 +47,23 @@ define('DICT_ERR_EXCEPTION', 2); // when a string is missing, throw an exception
|
||||
class Dict
|
||||
{
|
||||
protected static $m_iErrorMode = DICT_ERR_STRING;
|
||||
protected static $m_sDefaultLanguage = 'EN US';
|
||||
protected static $m_sCurrentLanguage = 'EN US';
|
||||
|
||||
protected static $m_aLanguages = array(); // array( code => array( 'description' => '...', 'localized_description' => '...') ...)
|
||||
protected static $m_aData = array();
|
||||
|
||||
|
||||
public static function SetLanguage($sLanguageCode)
|
||||
public static function SetDefaultLanguage($sLanguageCode)
|
||||
{
|
||||
if (!array_key_exists($sLanguageCode, self::$m_aLanguages))
|
||||
{
|
||||
throw new DictExceptionUnknownLanguage($sLanguageCode);
|
||||
}
|
||||
self::$m_sDefaultLanguage = $sLanguageCode;
|
||||
}
|
||||
|
||||
public static function SetUserLanguage($sLanguageCode)
|
||||
{
|
||||
if (!array_key_exists($sLanguageCode, self::$m_aLanguages))
|
||||
{
|
||||
@@ -78,29 +88,41 @@ class Dict
|
||||
|
||||
public static function S($sStringCode, $sDefault = null)
|
||||
{
|
||||
// Attempt to find the string in the user language
|
||||
//
|
||||
$aCurrentDictionary = self::$m_aData[self::$m_sCurrentLanguage];
|
||||
if (!array_key_exists($sStringCode, $aCurrentDictionary))
|
||||
if (array_key_exists($sStringCode, $aCurrentDictionary))
|
||||
{
|
||||
switch (self::$m_iErrorMode)
|
||||
{
|
||||
case DICT_ERR_STRING:
|
||||
if (is_null($sDefault))
|
||||
{
|
||||
return $sStringCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $sDefault;
|
||||
}
|
||||
break;
|
||||
|
||||
case DICT_ERR_EXCEPTION:
|
||||
default:
|
||||
throw new DictExceptionMissingString(self::$m_sCurrentLanguage, $sStringCode);
|
||||
break;
|
||||
}
|
||||
return $aCurrentDictionary[$sStringCode];
|
||||
}
|
||||
return $aCurrentDictionary[$sStringCode];
|
||||
// Attempt to find the string in the default language
|
||||
//
|
||||
$aDefaultDictionary = self::$m_aData[self::$m_sDefaultLanguage];
|
||||
if (array_key_exists($sStringCode, $aDefaultDictionary))
|
||||
{
|
||||
return $aDefaultDictionary[$sStringCode];
|
||||
}
|
||||
// Could not find the string...
|
||||
//
|
||||
switch (self::$m_iErrorMode)
|
||||
{
|
||||
case DICT_ERR_STRING:
|
||||
if (is_null($sDefault))
|
||||
{
|
||||
return $sStringCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $sDefault;
|
||||
}
|
||||
break;
|
||||
|
||||
case DICT_ERR_EXCEPTION:
|
||||
default:
|
||||
throw new DictExceptionMissingString(self::$m_sCurrentLanguage, $sStringCode);
|
||||
break;
|
||||
}
|
||||
return 'bug!';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ abstract class MetaModel
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::GetDescription($sClass);
|
||||
return self::GetClassDescription($sClass);
|
||||
}
|
||||
}
|
||||
final static public function IsAutoIncrementKey($sClass)
|
||||
@@ -2799,7 +2799,7 @@ abstract class MetaModel
|
||||
self::Plugin($sConfigFile, 'dictionaries', $sToInclude);
|
||||
}
|
||||
// Set the language... after the dictionaries have been loaded!
|
||||
Dict::SetLanguage($oConfig->GetDefaultLanguage());
|
||||
Dict::SetDefaultLanguage($oConfig->GetDefaultLanguage());
|
||||
|
||||
$sServer = $oConfig->GetDBHost();
|
||||
$sUser = $oConfig->GetDBUser();
|
||||
|
||||
@@ -49,6 +49,7 @@ abstract class UserRightsAddOnAPI
|
||||
|
||||
abstract public function Init(); // loads data (possible optimizations)
|
||||
abstract public function CheckCredentials($sLogin, $sPassword); // returns the id of the user or false
|
||||
abstract public function GetUserLanguage($sLogin); // returns the language code (e.g "EN US")
|
||||
abstract public function GetUserId($sLogin); // returns the id of the user or false
|
||||
abstract public function GetContactId($sLogin); // returns the id of the "business" user or false
|
||||
abstract public function GetFilter($sLogin, $sClass); // returns a filter object
|
||||
@@ -78,6 +79,7 @@ class UserRights
|
||||
protected static $m_sRealUser;
|
||||
protected static $m_iUserId;
|
||||
protected static $m_iRealUserId;
|
||||
protected static $m_sUserLanguage;
|
||||
|
||||
public static function SelectModule($sModuleName)
|
||||
{
|
||||
@@ -97,6 +99,7 @@ class UserRights
|
||||
self::$m_sRealUser = '';
|
||||
self::$m_iUserId = 0;
|
||||
self::$m_iRealUserId = 0;
|
||||
self::$m_sUserLanguage = 'EN US';
|
||||
}
|
||||
|
||||
public static function GetModuleInstance()
|
||||
@@ -125,11 +128,13 @@ class UserRights
|
||||
public static function Login($sName, $sPassword)
|
||||
{
|
||||
self::$m_iUserId = self::$m_oAddOn->CheckCredentials($sName, $sPassword);
|
||||
if ( self::$m_iUserId !== false )
|
||||
if (self::$m_iUserId !== false)
|
||||
{
|
||||
self::$m_sUser = $sName;
|
||||
self::$m_iRealUserId = self::$m_iUserId;
|
||||
self::$m_sRealUser = $sName;
|
||||
self::$m_sUserLanguage = self::$m_oAddOn->GetUserLanguage($sName);
|
||||
Dict::SetUserLanguage(self::GetUserLanguage());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -143,9 +148,11 @@ class UserRights
|
||||
if (!self::CheckLogin()) return false;
|
||||
|
||||
self::$m_iRealUserId = self::$m_oAddOn->CheckCredentials($sName, $sPassword);
|
||||
if ( self::$m_iRealUserId !== false)
|
||||
if (self::$m_iRealUserId !== false)
|
||||
{
|
||||
self::$m_sUser = $sName;
|
||||
self::$m_sUserLanguage = self::$m_oAddOn->GetUserLanguage($sName);
|
||||
Dict::SetUserLanguage(self::GetUserLanguage());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -159,6 +166,11 @@ class UserRights
|
||||
return self::$m_sUser;
|
||||
}
|
||||
|
||||
public static function GetUserLanguage()
|
||||
{
|
||||
return self::$m_sUserLanguage;
|
||||
}
|
||||
|
||||
public static function GetUserId($sName = '')
|
||||
{
|
||||
if (empty($sName))
|
||||
|
||||
@@ -109,6 +109,12 @@ Dict::Add('EN US', 'English', 'English', array(
|
||||
'Class:URP_Users/Attribute:login+' => 'user identification string',
|
||||
'Class:URP_Users/Attribute:password' => 'Password',
|
||||
'Class:URP_Users/Attribute:password+' => 'user authentication string',
|
||||
'Class:URP_Users/Attribute:language' => 'Language',
|
||||
'Class:URP_Users/Attribute:language+' => 'user language',
|
||||
'Class:URP_Users/Attribute:language/Value:EN US' => 'English',
|
||||
'Class:URP_Users/Attribute:language/Value:EN US+' => 'English U.S.',
|
||||
'Class:URP_Users/Attribute:language/Value:FR FR' => 'French',
|
||||
'Class:URP_Users/Attribute:language/Value:FR FR+' => 'FR FR',
|
||||
'Class:URP_Users/Attribute:profiles' => 'Profiles',
|
||||
'Class:URP_Users/Attribute:profiles+' => 'roles, granting rights for that person',
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user