mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixed #5067 - account for only one name in generateFormattedNameFromFullName
This commit is contained in:
parent
a85b38850c
commit
cbd8409611
|
@ -330,19 +330,29 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
|
||||||
|
|
||||||
public static function generateFormattedNameFromFullName($format = 'filastname', $users_name)
|
public static function generateFormattedNameFromFullName($format = 'filastname', $users_name)
|
||||||
{
|
{
|
||||||
list($first_name, $last_name) = explode(" ", $users_name, 2);
|
|
||||||
|
|
||||||
// Assume filastname by default
|
// If there was only one name given
|
||||||
$username = str_slug(substr($first_name, 0, 1).$last_name);
|
if (strpos($users_name, ' ') === false) {
|
||||||
|
$first_name = $users_name;
|
||||||
if ($format=='firstname.lastname') {
|
$last_name = '';
|
||||||
$username = str_slug($first_name).'.'.str_slug($last_name);
|
$username = $users_name;
|
||||||
|
|
||||||
} elseif ($format=='firstname_lastname') {
|
} else {
|
||||||
$username = str_slug($first_name).'_'.str_slug($last_name);
|
|
||||||
|
|
||||||
} elseif ($format=='firstname') {
|
list($first_name, $last_name) = explode(" ", $users_name, 2);
|
||||||
$username = str_slug($first_name);
|
|
||||||
|
// Assume filastname by default
|
||||||
|
$username = str_slug(substr($first_name, 0, 1).$last_name);
|
||||||
|
|
||||||
|
if ($format=='firstname.lastname') {
|
||||||
|
$username = str_slug($first_name).'.'.str_slug($last_name);
|
||||||
|
|
||||||
|
} elseif ($format=='firstname_lastname') {
|
||||||
|
$username = str_slug($first_name).'_'.str_slug($last_name);
|
||||||
|
|
||||||
|
} elseif ($format=='firstname') {
|
||||||
|
$username = str_slug($first_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user['first_name'] = $first_name;
|
$user['first_name'] = $first_name;
|
||||||
|
|
|
@ -71,5 +71,13 @@ class UserTest extends BaseTest
|
||||||
$this->assertEquals($expected_username, $user['username']);
|
$this->assertEquals($expected_username, $user['username']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSingleName()
|
||||||
|
{
|
||||||
|
$fullname = "Natalia";
|
||||||
|
$expected_username = 'natalia';
|
||||||
|
$user = User::generateFormattedNameFromFullName('firstname_lastname', $fullname);
|
||||||
|
$this->assertEquals($expected_username, $user['username']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue