RemoteEventCrudController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
c 0
b 0
f 0
dl 0
loc 93
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setupUpdateOperation() 0 3 1
A setupCreateOperation() 0 36 1
A setup() 0 5 1
A setupListOperation() 0 30 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Requests\RemoteEventRequest;
6
use App\Models\Period;
7
use App\Models\RemoteEvent;
8
use App\Models\Teacher;
9
use Backpack\CRUD\app\Http\Controllers\CrudController;
10
use Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
11
use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
12
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
13
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
14
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
15
16
class RemoteEventCrudController extends CrudController
17
{
18
    use 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\Adm...moteEventCrudController: $model, $query, $entity_name_plural
Loading history...
19
    use CreateOperation;
0 ignored issues
show
Bug introduced by
The trait Backpack\CRUD\app\Http\C...rations\CreateOperation requires the property $entity_name which is not provided by App\Http\Controllers\Adm...moteEventCrudController.
Loading history...
20
    use 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\Adm...moteEventCrudController: $entity_name, $model
Loading history...
21
    use DeleteOperation;
22
23
    public function setup()
24
    {
25
        CRUD::setModel(RemoteEvent::class);
26
        CRUD::setRoute(config('backpack.base.route_prefix').'/remoteevent');
27
        CRUD::setEntityNameStrings(__('remote event'), __('remote events'));
28
    }
29
30
    public function setupListOperation()
31
    {
32
        CRUD::setColumns([
33
            [
34
                // 1-n relationship
35
                'label' => 'Period',
36
                'type' => 'relationship',
37
                'name' => 'period',
38
                'attribute' => 'name',
39
            ],
40
41
            [
42
                // 1-n relationship
43
                'label' => 'Teacher',
44
                'type' => 'relationship',
45
                'name' => 'teacher',
46
                'attribute' => 'name',
47
            ],
48
49
            [
50
                'name' => 'worked_hours',
51
                'label' => 'Worked Hours',
52
                'type' => 'number',
53
                'suffix' => ' h',
54
                'decimals' => 2,
55
            ],
56
57
            [
58
                'name' => 'name',
59
                'label' => 'Project',
60
            ],
61
62
        ]);
63
    }
64
65
    public function setupCreateOperation()
66
    {
67
        CRUD::setValidation(RemoteEventRequest::class);
68
69
        CRUD::addFields([
70
            [
71
                // 1-n relationship
72
                'label' => 'Period',
73
                'type' => 'select',
74
                'name' => 'period_id',
75
                'entity' => 'period',
76
                'attribute' => 'name',
77
                'model' => Period::class,
78
            ],
79
80
            [
81
                // 1-n relationship
82
                'label' => 'Teacher',
83
                'type' => 'select',
84
                'name' => 'teacher_id',
85
                'entity' => 'teacher',
86
                'attribute' => 'name',
87
                'model' => Teacher::class,
88
            ],
89
90
            [
91
                'name' => 'worked_hours',
92
                'label' => 'Worked Hours',
93
                'type' => 'number',
94
                'suffix' => ' h',
95
                'attributes' => ['step' => '0.01'],
96
            ],
97
98
            [
99
                'name' => 'name',
100
                'label' => 'Project',
101
            ],
102
103
        ]);
104
    }
105
106
    public function setupUpdateOperation()
107
    {
108
        $this->setupCreateOperation();
109
    }
110
}
111