Passed
Push — dev6 ( 871906...b95c31 )
by Ron
14:50
created

BuildNavbar::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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