Passed
Push — feature/hr-admin-panel ( cd39be...90d889 )
by Grant
03:48
created

ManagerCrudController::setupUpdateOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 17
rs 9.8333
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
7
class ManagerCrudController extends CrudController
8
{
9
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
11
12
    /**
13
     * Prepare the admin interface by setting the associated
14
     * model, setting the route, and adding custom columns/fields.
15
     *
16
     * @return void
17
     */
18
    public function setup() : void
19
    {
20
        $this->crud->setModel('App\Models\User');
21
        $this->crud->setRoute('admin/manager');
22
        $this->crud->setEntityNameStrings('manager', 'managers');
23
24
        // Don't show 'basic' users.
25
        $this->crud->addClause('whereIn', 'user_role_id', [2, 3]);
26
    }
27
28
    public function setupListOperation()
29
    {
30
        $this->crud->removeButton('update');
31
32
        $this->crud->addColumn([
33
            'name' => 'manager.id',
34
            'key' => 'manager_id',
35
            'type' => 'number',
36
            'label' => 'ID'
37
        ]);
38
        $this->crud->addColumn([
39
            'name' => 'full_name',
40
            'key' => 'manager_name',
41
            'type' => 'text',
42
            'label' => 'Name'
43
        ]);
44
        $this->crud->addColumn([
45
            'name' => 'user_role.name',
46
            'type' => 'text',
47
            'key' => 'user_role_name',
48
            'label' => 'Role'
49
        ]);
50
        $this->crud->addColumn([
51
            'name' => 'email',
52
            'key' => 'manager_email',
53
            'type' => 'text',
54
            'label' => 'Email'
55
        ]);
56
        $this->crud->addColumn([
57
            'name' => 'gov_email',
58
            'key' => 'government_email',
59
            'type' => 'text',
60
            'label' => 'Government Email'
61
        ]);
62
        $this->crud->addColumn([
63
            'name' => 'department.name',
64
            'key' => 'manager_department',
65
            'type' => 'text',
66
            'label' => 'Department',
67
            'limit' => 70
68
        ]);
69
70
        // Add the custom blade button found in resources/views/vendor/backpack/crud/buttons/profile_edit.blade.php.
71
        $this->crud->addButtonFromView('line', 'create_job_poster', 'create_job_poster', 'beginning');
72
        $this->crud->addButtonFromView('line', 'profile_edit', 'profile_edit', 'end');
73
    }
74
}
75