Passed
Push — dev6 ( d58043...568a9a )
by Ron
17:54
created

BuildNavbar   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrimaryNavbar() 0 17 1
A getModules() 0 24 4
A build() 0 9 1
A getAdminNavbar() 0 12 2
1
<?php
2
3
namespace App\Actions;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Gate;
7
use Illuminate\Support\Facades\Log;
8
use Nwidart\Modules\Facades\Module;
9
10
class BuildNavbar
11
{
12
    protected $user;
13
14
    public function build($user)
15
    {
16
        $this->user = $user;
17
18
        $admin   = []; // $this->getAdminNavbar();
19
        $navBar  = $this->getPrimaryNavbar();
20
        $modules = $this->getModules();
21
22
        return array_merge($navBar, $admin, $modules);
23
    }
24
25
    /*
26
    *   Main navigation menu that is always included
27
    */
28
    protected function getPrimaryNavbar()
29
    {
30
        return [
31
            [
32
                'name'  => 'Dashboard',
33
                'route' => route('dashboard'),
34
                'icon'  => 'fas fa-tachometer-alt',
35
            ],
36
            [
37
                'name'  => 'Customers',
38
                'route' => '#', // route('customers.index'),
39
                'icon'  => 'fas fa-user-tie',
40
            ],
41
            [
42
                'name'  => 'Tech Tips',
43
                'route' => '#', // route('tech-tips.index'),
44
                'icon'  => 'fas fa-tools',
45
            ],
46
        ];
47
    }
48
49
    /*
50
    *   If the user has any admin abilities, show the admin link
51
    */
52
    protected function getAdminNavbar()
53
    {
54
        if(Gate::allows('admin-link', $this->user))
55
        {
56
            return [[
57
                'name'  => 'Administration',
58
                'route' => '#', // route('admin.index'),
59
                'icon'  => 'fas fa-user-shield',
60
            ]];
61
        }
62
63
        return [];
64
    }
65
66
    /*
67
    *   If any add-on modules have been installed, add those to the navigation bar
68
    */
69
    protected function getModules()
70
    {
71
        $nav     = [];
72
        $modules = Module::allEnabled();
73
74
        foreach($modules as $module)
75
        {
76
            $name = $module->getLowerName();
77
            $navData = config($name.'.navbar');
78
79
            foreach($navData as $n)
80
            {
81
                if($n['enable'])
82
                {
83
                    $nav[] = [
84
                        'name'  => $n['name'],
85
                        'route' => route($n['route']),
86
                        'icon'  => $n['icon'],
87
                    ];
88
                }
89
            }
90
        }
91
92
        return $nav;
93
    }
94
}
95