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 JobPosterStatusTransitionCrudController extends CrudController |
9
|
|
|
{ |
10
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
11
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
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
|
|
|
// Eloquent model to associate with this collection of views and controller actions. |
22
|
|
|
$this->crud->setModel('App\Models\Lookup\JobPosterStatusTransition'); |
23
|
|
|
// Custom backpack route. |
24
|
|
|
$this->crud->setRoute('admin/job-poster-status-transition'); |
25
|
|
|
// Custom strings to display within the backpack UI. |
26
|
|
|
$this->crud->setEntityNameStrings('job status transition', 'job status transitions'); |
27
|
|
|
|
28
|
|
|
$this->crud->operation(['update'], function () { |
29
|
|
|
$this->crud->addField([ |
30
|
|
|
'name' => 'key', |
31
|
|
|
'type' => 'text', |
32
|
|
|
'label' => 'Key', |
33
|
|
|
'attributes' => ['disabled' => 'disabled'] |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
$this->crud->addField([ |
37
|
|
|
'name' => 'name', |
38
|
|
|
'type' => 'text', |
39
|
|
|
'label' => 'Name', |
40
|
|
|
'limit' => 120, |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$this->crud->addField([ // Select |
44
|
|
|
'label' => 'Owner User Role', |
45
|
|
|
'type' => 'select', |
46
|
|
|
'name' => 'owner_user_role_id', // the db column for the foreign key |
47
|
|
|
'entity' => 'owner_user_role', // the method that defines the relationship in your Model |
48
|
|
|
'attribute' => 'key', // foreign key attribute that is shown to user |
49
|
|
|
'model' => \App\Models\UserRole::class, // foreign key model |
50
|
|
|
'attributes' => ['disabled' => 'disabled'] |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$this->crud->addField([ // Select |
54
|
|
|
'label' => 'From Status', |
55
|
|
|
'type' => 'select', |
56
|
|
|
'name' => 'from_job_poster_status_id', // the db column for the foreign key |
57
|
|
|
'entity' => 'from', // the method that defines the relationship in your Model |
58
|
|
|
'attribute' => 'key', // foreign key attribute that is shown to user |
59
|
|
|
'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
60
|
|
|
'attributes' => ['disabled' => 'disabled'] |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$this->crud->addField([ // Select |
64
|
|
|
'label' => 'To Status', |
65
|
|
|
'type' => 'select', |
66
|
|
|
'name' => 'to_job_poster_status_id', // the db column for the foreign key |
67
|
|
|
'entity' => 'to', // the method that defines the relationship in your Model |
68
|
|
|
'attribute' => 'key', // foreign key attribute that is shown to user |
69
|
|
|
'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
70
|
|
|
'attributes' => ['disabled' => 'disabled'] |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$this->crud->addField([ |
74
|
|
|
'name' => 'button_style', |
75
|
|
|
'label' => 'Button Style', |
76
|
|
|
'type' => 'select_from_array', |
77
|
|
|
'options' => ['default' => 'default', 'stop' => 'stop', 'go' => 'go'], |
78
|
|
|
'allows_null' => false, |
79
|
|
|
'default' => 'default', |
80
|
|
|
'fake' => true, // show the field, but don’t store it in the database column above |
81
|
|
|
'store_in' => 'metadata' // [optional] the database column name where you want the fake fields to ACTUALLY be stored as a JSON array |
82
|
|
|
]); |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function setupListOperation() |
87
|
|
|
{ |
88
|
|
|
// Required for order logic. |
89
|
|
|
$locale = 'en'; |
90
|
|
|
if (null !== $this->request->input('locale')) { |
91
|
|
|
$locale = $this->request->input('locale'); |
92
|
|
|
} |
93
|
|
|
App::setLocale($locale); |
94
|
|
|
|
95
|
|
|
// Add custom columns to the Department index view. |
96
|
|
|
$this->crud->addColumn([ |
97
|
|
|
'name' => 'id', |
98
|
|
|
'type' => 'text', |
99
|
|
|
'label' => 'ID', |
100
|
|
|
'orderable' => true, |
101
|
|
|
]); |
102
|
|
|
|
103
|
|
|
$this->crud->addColumn([ |
104
|
|
|
'name' => 'name', |
105
|
|
|
'type' => 'text', |
106
|
|
|
'label' => 'Name', |
107
|
|
|
'orderable' => true, |
108
|
|
|
'limit' => 70, |
109
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
110
|
|
|
return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
111
|
|
|
} |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
|
$this->crud->addColumn([ |
115
|
|
|
'name' => 'from.name', |
116
|
|
|
'type' => 'text', |
117
|
|
|
'label' => 'From status', |
118
|
|
|
'orderable' => false, |
119
|
|
|
]); |
120
|
|
|
|
121
|
|
|
$this->crud->addColumn([ |
122
|
|
|
'name' => 'to.name', |
123
|
|
|
'type' => 'text', |
124
|
|
|
'label' => 'To status', |
125
|
|
|
'orderable' => false, |
126
|
|
|
]); |
127
|
|
|
|
128
|
|
|
$this->crud->addColumn([ |
129
|
|
|
'name' => 'owner_user_role.name', |
130
|
|
|
'type' => 'text', |
131
|
|
|
'label' => 'Owner User Role', |
132
|
|
|
'orderable' => false, |
133
|
|
|
]); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|