Skip to content

Commit

Permalink
Merge branch '4.x' into 5916-fix-2fa-redirect-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
efturtle authored Nov 5, 2023
2 parents b4b6dd7 + 0a9112e commit 2c645bf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,21 @@ public function getNameAttribute()
$completeName = $completeName.' '.$this->middle_name;
}
break;
case 'nickname_bracketed_firstname_lastname':
$completeName = $this->first_name;

if (! is_null($this->middle_name)) {
$completeName = $completeName.' '.$this->middle_name;
}

if (! is_null($this->nickname)) {
$completeName = $this->nickname.' ('.$completeName.')';
}

if (! is_null($this->last_name)) {
$completeName = $completeName.' '.$this->last_name;
}
break;
case 'nickname':
if (! is_null($this->nickname)) {
$completeName = $this->nickname;
Expand Down Expand Up @@ -909,6 +924,10 @@ public function getIncompleteName()
$incompleteName = '';
$incompleteName = $this->first_name;

if ($this->nameOrder == 'nickname_bracketed_firstname_lastname' && ! is_null($this->nickname)) {
$incompleteName = $this->nickname;
}

if (! is_null($this->last_name)) {
$incompleteName .= ' '.mb_substr($this->last_name, 0, 1);
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasLocalePreferen
'lastname_nickname_firstname',
'nickname_firstname_lastname',
'nickname_lastname_firstname',
'nickname_bracketed_firstname_lastname',
'nickname',
];

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'name_order_lastname_nickname_firstname' => '<Last name> (<Nickname>) <First name> – Doe (Rambo) John',
'name_order_nickname_firstname_lastname' => '<Nickname> (<First name> <Last name>) – Rambo (John Doe)',
'name_order_nickname_lastname_firstname' => '<Nickname> (<Last name> <First name>) – Rambo (Doe John)',
'name_order_nickname_bracketed_firstname_lastname' => '<Nickname> (<First name>) <Last name> - Rambo (John) Doe',
'name_order_nickname' => '<Nickname> – Rambo',
'currency' => 'Currency',
'name' => 'Your name: :name',
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/Models/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,39 @@ public function name_attribute_returns_name_in_the_right_order()
$contact->name
);

$contact = new Contact;
$contact->first_name = 'Peter';
$contact->middle_name = 'H';
$contact->last_name = 'Gregory';
$contact->nickname = 'Rambo';
$contact->nameOrder('nickname_bracketed_firstname_lastname');
$this->assertEquals(
'Rambo (Peter H) Gregory',
$contact->name
);

$contact = new Contact;
$contact->first_name = 'Peter';
$contact->middle_name = 'H';
$contact->last_name = null;
$contact->nickname = 'Rambo';
$contact->nameOrder('nickname_bracketed_firstname_lastname');
$this->assertEquals(
'Rambo (Peter H)',
$contact->name
);

$contact = new Contact;
$contact->first_name = 'Peter';
$contact->middle_name = null;
$contact->last_name = 'Gregory';
$contact->nickname = 'Rambo';
$contact->nameOrder('nickname_bracketed_firstname_lastname');
$this->assertEquals(
'Rambo (Peter) Gregory',
$contact->name
);

$contact = new Contact;
$contact->first_name = 'Peter';
$contact->middle_name = 'H';
Expand Down

0 comments on commit 2c645bf

Please sign in to comment.