TalentStreamCategoryCrudController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 40
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setupListOperation() 0 29 2
A setup() 0 20 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
8
class TalentStreamCategoryCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
    use \Backpack\Crud\app\Http\Controllers\Operations\CreateOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
14
15
    /**
16
     * Prepare the admin interface by setting the associated
17
     * model, setting the route, and adding custom columns/fields.
18
     *
19
     * @return void
20
     */
21
    public function setup(): void
22
    {
23
        // Eloquent model to associate with this collection of views and controller actions.
24
        $this->crud->setModel('App\Models\Lookup\TalentStreamCategory');
25
        // Custom backpack route.
26
        $this->crud->setRoute('admin/talent-stream-category');
27
        // Custom strings to display within the backpack UI.
28
        $this->crud->setEntityNameStrings('talent stream category', 'talent stream categories');
29
30
        $this->crud->operation(['create', 'update'], function () {
31
            $this->crud->addField([
32
                'name' => 'key',
33
                'type' => 'text',
34
                'label' => 'key',
35
            ]);
36
            $this->crud->addField([
37
                'name' => 'name',
38
                'type' => 'text',
39
                'label' => 'Name',
40
                'limit' => 120,
41
            ]);
42
        });
43
    }
44
45
    public function setupListOperation()
46
    {
47
        // Required for order logic.
48
        $locale = 'en';
49
        if (null !== $this->request->input('locale')) {
50
            $locale = $this->request->input('locale');
51
        }
52
        App::setLocale($locale);
53
54
        $this->crud->addColumn([
55
            'name' => 'id',
56
            'type' => 'text',
57
            'label' => 'ID',
58
            'orderable' => true,
59
        ]);
60
        $this->crud->addColumn([
61
            'name' => 'key',
62
            'type' => 'text',
63
            'label' => 'Key',
64
            'orderable' => true,
65
        ]);
66
        $this->crud->addColumn([
67
            'name' => 'name',
68
            'type' => 'text',
69
            'label' => 'Name',
70
            'orderable' => true,
71
            'limit' => 70,
72
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
73
                return $query->orderBy('name->' . $locale, $columnDirection)->select('*');
74
            }
75
        ]);
76
    }
77
}
78