From 07ae91b00ff8ff41125ff25a6f31cfbdf2c730a8 Mon Sep 17 00:00:00 2001 From: akemi Date: Wed, 7 Dec 2022 17:46:18 -0500 Subject: [PATCH 1/2] Created method in users.php for adding up all assigned to user and providing an integer value. this then used to grey out buttons on user view if user has nothing assigned. --- app/Models/User.php | 18 ++++++++++++++++++ resources/views/users/view.blade.php | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 8211fabd6..5bf378f05 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -338,6 +338,24 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id'); } + /** + * Establishes a count of all items assigned + * + * @author J. Vinsmoke + * @since [v6.1] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + Public function allassignedcount() { + $assetsCount = $this->assets()->count(); + $licensesCount = $this->licenses()->count(); + $accessoriesCount = $this->accessories()->count(); + $consumablesCount = $this->consumables()->count(); + + $totalcount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount; + + return (int) $totalcount; + } + /** * Establishes the user -> actionlogs relationship * diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 445515449..7c9788ec3 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -179,17 +179,20 @@ @can('view', $user)
+ @if($user->allassignedcount() != '0') {{ trans('admin/users/general.print_assigned') }}
@endcan @can('view', $user)
- @if(!empty($user->email)) + @if(!empty($user->email) && ($user->allassignedcount() != '0'))
{{ csrf_field() }}
+ @elseif(!empty($user->email) && ($user->allassignedcount() == '0')) + @else @endif From f3e57d7dc0186bb2466a7968c5e49402a4495864 Mon Sep 17 00:00:00 2001 From: akemidx Date: Tue, 13 Dec 2022 16:00:59 -0500 Subject: [PATCH 2/2] fixing PR --- app/Models/User.php | 10 +++++----- resources/lang/en/admin/users/message.php | 1 + resources/views/users/view.blade.php | 9 ++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 5bf378f05..c3f7f80b9 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -338,23 +338,23 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id'); } - /** + /** * Establishes a count of all items assigned * * @author J. Vinsmoke * @since [v6.1] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - Public function allassignedcount() { + Public function allAssignedCount() { $assetsCount = $this->assets()->count(); $licensesCount = $this->licenses()->count(); $accessoriesCount = $this->accessories()->count(); $consumablesCount = $this->consumables()->count(); - $totalcount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount; + $totalCount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount; - return (int) $totalcount; - } + return (int) $totalCount; + } /** * Establishes the user -> actionlogs relationship diff --git a/resources/lang/en/admin/users/message.php b/resources/lang/en/admin/users/message.php index 11292a069..247a1b321 100644 --- a/resources/lang/en/admin/users/message.php +++ b/resources/lang/en/admin/users/message.php @@ -15,6 +15,7 @@ return array( 'password_resets_sent' => 'The selected users who are activated and have a valid email addresses have been sent a password reset link.', 'password_reset_sent' => 'A password reset link has been sent to :email!', 'user_has_no_email' => 'This user does not have an email address in their profile.', + 'user_has_no_assets_assigned' => 'This user does not have any assets assigned', 'success' => array( diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 7c9788ec3..17bc7bdf1 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -179,19 +179,22 @@ @can('view', $user)
- @if($user->allassignedcount() != '0') + @if($user->allAssignedCount() != '0') {{ trans('admin/users/general.print_assigned') }} + @else + + @endif
@endcan @can('view', $user)
- @if(!empty($user->email) && ($user->allassignedcount() != '0')) + @if(!empty($user->email) && ($user->allAssignedCount() != '0'))
{{ csrf_field() }}
- @elseif(!empty($user->email) && ($user->allassignedcount() == '0')) + @elseif(!empty($user->email) && ($user->allAssignedCount() == '0')) @else