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