Passed
Pull Request — release/1.0.15 (#1655)
by Tristan
10:06 queued 02:47
created

UserCrudController::setupListOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 41
rs 9.392
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use App\Models\UserRole;
7
8
class UserCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...perations\ListOperation requires some properties which are not provided by App\Http\Controllers\Admin\UserCrudController: $model, $query, $entity_name_plural
Loading history...
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...rations\UpdateOperation requires some properties which are not provided by App\Http\Controllers\Admin\UserCrudController: $model, $entity_name
Loading history...
12
13
    /**
14
     * Prepare the admin interface by setting the associated
15
     * model, setting the route, and adding custom columns/fields.
16
     *
17
     * @return void
18
     */
19
    public function setup() : void
20
    {
21
        $this->crud->setModel('App\Models\User');
22
        $this->crud->setRoute('admin/user');
23
        $this->crud->setEntityNameStrings('user', 'users');
24
    }
25
26
    public function setupListOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupListOperation()
Loading history...
27
    {
28
        $this->crud->addColumn([
29
            'name' => 'name',
30
            'type' => 'text',
31
            'label' => 'Name'
32
        ]);
33
        $this->crud->addColumn([
34
            'name' => 'email',
35
            'type' => 'text',
36
            'label' => 'Email'
37
        ]);
38
        $this->crud->addColumn([
39
            'name' => 'user_role.name',
40
            'type' => 'text',
41
            'key' => 'user_role_name',
42
            'label' => 'Role'
43
        ]);
44
        $this->crud->addColumn([
45
            'name' => 'gov_email',
46
            'type' => 'text',
47
            'label' => 'Gov Email'
48
        ]);
49
        $this->crud->addColumn([
50
            'name' => 'not_in_gov',
51
            'type' => 'check',
52
            'label' => 'Not in Gov'
53
        ]);
54
        $this->crud->addColumn([
55
            'name' => 'is_priority',
56
            'type' => 'check',
57
            'label' => 'Priority'
58
        ]);
59
        $this->crud->addFilter([
60
            'name' => 'user_role',
61
            'type' => 'select2',
62
            'label' => 'Role'
63
            ], function () {
64
                return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray();
65
            }, function ($value) : void {
66
                $this->crud->addClause('where', 'user_role_id', $value);
67
            });
68
    }
69
70
    public function setupUpdateOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupUpdateOperation()
Loading history...
71
    {
72
        $this->crud->addField([
73
            'name' => 'name',
74
            'label' => 'Name',
75
            'type' => 'text',
76
            'attributes' => [
77
                'readonly'=>'readonly'
78
            ]
79
        ]);
80
        $this->crud->addField([
81
            'label' => 'Role',
82
            'type' => 'select',
83
            'name' => 'user_role_id', // The db column for the foreign key.
84
            'entity' => 'user_role', // The method that defines the relationship in your Model.
85
            'attribute' => 'name', // Foreign key attribute that is shown to user.
86
            'model' => 'App\Models\UserRole' // Foreign key model.
87
        ]);
88
        $this->crud->addField([
89
            'name' => 'is_priority',
90
            'type' => 'checkbox',
91
            'label' => 'Priority'
92
        ]);
93
    }
94
}
95