Passed
Push — feature/skills-admin-panel ( d2c311 )
by Grant
33:17 queued 17:58
created

SkillCrudController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 82%

Importance

Changes 0
Metric Value
wmc 4
eloc 62
dl 0
loc 119
ccs 41
cts 50
cp 0.82
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 3 1
B setup() 0 89 2
A update() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Illuminate\Support\Facades\App;
7
use App\Models\Lookup\SkillType;
8
// Validation.
9
use App\Http\Requests\SkillCrudRequest as StoreRequest;
10
use App\Http\Requests\SkillCrudRequest as UpdateRequest;
11
12
class SkillCrudController extends CrudController
13
{
14
    /**
15
     * Prepare the admin interface by setting the associated
16
     * model, setting the route, and adding custom columns/fields.
17
     *
18
     * @return void
19
     */
20 1
    public function setup() : void
21
    {
22
        // Workaround for how the unique_translation validation
23
        // works in App\Http\Requests\SkillCrudRequest.
24 1
        $locale = 'en';
25 1
        if (null !== $this->request->input('locale')) {
26
            $locale = $this->request->input('locale');
27
        }
28 1
        App::setLocale($locale);
29
30
        // Eloquent model to associate with this collection
31
        // of views and controller actions.
32 1
        $this->crud->setModel('App\Models\Skill');
33
        // Custom backpack route.
34 1
        $this->crud->setRoute('admin/skill');
35
        // Custom strings to display within the backpack UI,
36
        // things like Create Skill, Delete Skills, etc.
37 1
        $this->crud->setEntityNameStrings('Skill', 'Skills');
38
39
        // Add custom columns to the Skill index view.
40 1
        $this->crud->addColumn([
41 1
            'name' => 'name',
42 1
            'type' => 'text',
43 1
            'label' => 'Name',
44
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
45
                $query->orWhere('name->' . $locale, 'like', "%$searchTerm%");
46 1
            },
47
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
48
                return $query->orderBy('name->' . $locale, $columnDirection)->select('*');
49 1
            }
50
        ]);
51 1
        $this->crud->addColumn([
52 1
            'name' => 'description',
53 1
            'type' => 'text',
54 1
            'label' => 'Description',
55
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
56
                $query->orWhere('description->' . $locale, 'like', "%$searchTerm%");
57 1
            },
58
            'orderable' => false,
59
        ]);
60 1
        $this->crud->addColumn([
61 1
            'name' => 'skill_type.name',
62 1
            'type' => 'text',
63 1
            'label' => 'Type',
64
            'orderable' => true,
65
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
0 ignored issues
show
Unused Code introduced by
The import $locale is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
66
                return $query->orderBy('skill_type_id', $columnDirection)->select('*');
67 1
            }
68
        ]);
69 1
        $this->crud->addColumn([
70 1
            'name' => 'is_culture_skill',
71
            'label' => 'isCultureSkill',
72
            'type' => 'checkbox'
73
        ]);
74 1
        $this->crud->addColumn([
75 1
            'name' => 'is_future_skill',
76
            'label' => 'isFutureSkill',
77
            'type' => 'checkbox'
78
        ]);
79
80
81
        // Add custom fields to the create/update views.
82 1
        $this->crud->addField([
83 1
            'name' => 'name',
84
            'type' => 'text',
85
            'label' => 'Name',
86
        ]);
87 1
        $this->crud->addField([
88 1
            'name' => 'description',
89
            'type' => 'textarea',
90
            'label' => 'Description'
91
        ]);
92 1
        $this->crud->addField([
93 1
            'name' => 'skill_type_id',
94 1
            'label' => 'Type',
95 1
            'type' => 'select_from_array',
96 1
            'options' => SkillType::all()->pluck('name', 'id')->toArray(),
97
            'allow_null' => false,
98
99
        ]);
100 1
        $this->crud->addField([
101 1
            'name' => 'is_culture_skill',
102
            'label' => 'Culture',
103
            'type' => 'checkbox'
104
        ]);
105 1
        $this->crud->addField([
106 1
            'name' => 'is_future_skill',
107
            'label' => 'Future',
108
            'type' => 'checkbox'
109
        ]);
110 1
    }
111
    /**
112
    * Action for creating a new Skill in the database.
113
    *
114
    * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request.
115
    * @return \Illuminate\Http\RedirectResponse
116
    */
117
    public function store(StoreRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

117
    public function store(/** @scrutinizer ignore-unused */ StoreRequest $request) // phpcs:ignore

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118
    {
119
        return parent::storeCrud();
120
    }
121
122
    /**
123
    * Action for creating a new Skill in the database.
124
    *
125
    * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request.
126
    * @return \Illuminate\Http\RedirectResponse
127
    */
128
    public function update(UpdateRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

128
    public function update(/** @scrutinizer ignore-unused */ UpdateRequest $request) // phpcs:ignore

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
129
    {
130
        return parent::updateCrud();
131
    }
132
}
133