diff --git a/app/Models/Contact/Contact.php b/app/Models/Contact/Contact.php index a1e1de7d11e..23761ecddce 100644 --- a/app/Models/Contact/Contact.php +++ b/app/Models/Contact/Contact.php @@ -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; @@ -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); } diff --git a/app/Models/User/User.php b/app/Models/User/User.php index c6c95e2c1cc..d614f276eff 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -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', ]; diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 503ccdff15e..214fcd4405a 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -69,6 +69,7 @@ 'name_order_lastname_nickname_firstname' => ' () – Doe (Rambo) John', 'name_order_nickname_firstname_lastname' => ' ( ) – Rambo (John Doe)', 'name_order_nickname_lastname_firstname' => ' ( ) – Rambo (Doe John)', + 'name_order_nickname_bracketed_firstname_lastname' => ' () - Rambo (John) Doe', 'name_order_nickname' => ' – Rambo', 'currency' => 'Currency', 'name' => 'Your name: :name', diff --git a/tests/Unit/Models/ContactTest.php b/tests/Unit/Models/ContactTest.php index 081e5f8ca23..4b274674a7f 100644 --- a/tests/Unit/Models/ContactTest.php +++ b/tests/Unit/Models/ContactTest.php @@ -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';