Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a name order with the last name outside of brackets #6286

Merged
merged 4 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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