diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 497ab7cea6..7a7aa45b6e 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -590,6 +590,7 @@ class SettingsController extends Controller $setting->date_display_format = $request->input('date_display_format'); $setting->time_display_format = $request->input('time_display_format'); $setting->digit_separator = $request->input('digit_separator'); + $setting->name_display_format = $request->input('name_display_format'); if ($setting->save()) { return redirect()->route('settings.index') diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 76c0288073..45de50fa7d 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -24,7 +24,7 @@ class UsersTransformer $array = [ 'id' => (int) $user->id, 'avatar' => e($user->present()->gravatar), - 'name' => e($user->first_name).' '.e($user->last_name), + 'name' => e($user->getFullNameAttribute()), 'first_name' => e($user->first_name), 'last_name' => e($user->last_name), 'username' => e($user->username), diff --git a/app/Models/User.php b/app/Models/User.php index 98a3ec346b..0d49b977c4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -247,21 +247,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo */ public function getFullNameAttribute() { - return $this->first_name.' '.$this->last_name; - } + $setting = Setting::getSettings(); - /** - * Returns the complete name attribute with username - * - * @todo refactor this so it's less repetitive and dumb - * - * @author A. Gianotto - * @since [v2.0] - * @return string - */ - public function getCompleteNameAttribute() - { - return $this->last_name.', '.$this->first_name.' ('.$this->username.')'; + if ($setting->name_display_format=='last_first') { + return ($this->last_name) ? $this->last_name.' '.$this->first_name : $this->first_name; + } + return $this->last_name ? $this->first_name.' '.$this->last_name : $this->first_name; } diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 080a2d10e9..f70ddf8af6 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -433,7 +433,7 @@ class UserPresenter extends Presenter */ public function nameUrl() { - return (string) link_to_route('users.show', $this->fullName(), $this->id); + return (string) link_to_route('users.show', $this->getFullNameAttribute(), $this->id); } /** diff --git a/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php b/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php new file mode 100644 index 0000000000..7a0afc5456 --- /dev/null +++ b/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php @@ -0,0 +1,32 @@ +string('name_display_format', 10)->after('alert_threshold')->nullable()->default('first_last'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('name_display_format'); + }); + } +} diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 9a78092179..3fa8092891 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -120,6 +120,9 @@ return [ 'firstname_lastname_underscore_format' => 'First Name Last Name (jane_smith@example.com)', 'lastnamefirstinitial_format' => 'Last Name First Initial (smithj@example.com)', 'firstintial_dot_lastname_format' => 'First Initial Last Name (j.smith@example.com)', + 'firstname_lastname_display' => 'First Name Last Name (Jane Smith)', + 'lastname_firstname_display' => 'Last Name First Name (Smith Jane)', + 'name_display_format' => 'Name Display Format', 'first' => 'First', 'firstnamelastname' => 'First Name Last Name (janesmith@example.com)', 'lastname_firstinitial' => 'Last Name First Initial (smith_j@example.com)', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 43dc2cc2e0..c5c7824edc 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -11,7 +11,7 @@ Form::macro('locales', function ($name = 'locale', $selected = null, $class = nu $idclause = (!is_null($id)) ? $id : ''; - $select = ''; $select .= ''; // Pull the autoglossonym array from the localizations translation file @@ -109,6 +109,23 @@ Form::macro('digit_separator', function ($name = 'digit_separator', $selected = return $select; }); + +Form::macro('name_display_format', function ($name = 'name_display_format', $selected = null, $class = null) { + $formats = [ + 'first_last' => trans('general.firstname_lastname_display'), + 'last_first' => trans('general.lastname_firstname_display'), + ]; + + $select = ''; + + return $select; +}); + /** * Barcode macro * Generates the dropdown menu of available 1D barcodes diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php index 2c3158c88f..a42c91e7a1 100755 --- a/resources/views/account/profile.blade.php +++ b/resources/views/account/profile.blade.php @@ -46,7 +46,7 @@
-
+
@if (!config('app.lock_passwords')) {!! Form::locales('locale', old('locale', $user->locale), 'select2') !!} diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index b77bddcf0d..10b09602ab 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -{{ trans('general.hello_name', array('name' => $user->present()->fullName())) }} +{{ trans('general.hello_name', array('name' => $user->present()->getFullNameAttribute())) }} @parent @stop diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 13a65bf28b..a9f547f4f5 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -328,7 +328,7 @@ @endif -