Fix UserRights::GetUserInitials() for login starting with a lower case letter

This commit is contained in:
Molkobain
2021-03-11 16:04:45 +01:00
parent c1564fdcc6
commit 3380b8896a
2 changed files with 68 additions and 10 deletions

View File

@@ -1274,14 +1274,17 @@ class UserRights
if (is_null($oUser))
{
$sInitials = '';
$aLoginParts = explode(' ', $sLogin);
foreach($aLoginParts as $sLoginPart)
{
// - Capitalize the first letter no matter what
$sReworkedLogin = ucfirst($sLogin);
// - Replace dashes with spaces to interpret all parts of the login
$sReworkedLogin = str_replace('-', ' ', $sReworkedLogin);
// - Explode login to check parts individually
$aLoginParts = explode(' ', $sReworkedLogin);
foreach ($aLoginParts as $sLoginPart) {
// Keep only upper case first letters
// eg. "My first name My last name" => "MM"
// eg. "Carrie Anne Moss" => "CAM"
if(preg_match('/^\p{Lu}/u', $sLoginPart) > 0)
{
if (preg_match('/^\p{Lu}/u', $sLoginPart) > 0) {
$sInitials .= mb_substr($sLoginPart, 0, 1);
}
}