UserSettingsTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterUserSettings() 0 20 4
1
<?php
2
3
namespace App\Traits;
4
5
use App\Models\User;
6
use App\Models\UserSetting;
7
use App\Models\UserRolePermissions;
8
9
trait UserSettingsTrait
10
{
11
    protected function filterUserSettings(User $user)
12
    {
13
        //  Pull the user settings
14
        $userSettings = UserSetting::where('user_id', $user->user_id)->with('UserSettingType')->get();
15
16
        foreach($userSettings as $key => $setting)
17
        {
18
            //  Determine if this setting is linked to a permission feature (i.e. should not be displayed if the user cannot access the feature)
19
            if(!is_null($setting->UserSettingType->perm_type_id))
20
            {
21
                $allowed = UserRolePermissions::where('role_id', $user->role_id)->where('perm_type_id', $setting->UserSettingType->perm_type_id)->first();
22
23
                if(!$allowed->allow)
24
                {
25
                    $userSettings->forget($key);
26
                }
27
            }
28
        }
29
30
        return $userSettings;
31
    }
32
}
33