1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Jenssegers\Date\Date; |
6
|
|
|
use App\Models\Lookup\Department; |
7
|
|
|
use App\Models\Lookup\JobPosterStatus; |
8
|
|
|
use App\Services\JobStatusTransitionManager; |
9
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
10
|
|
|
use Illuminate\Support\Facades\App; |
11
|
|
|
|
12
|
|
|
class JobPosterCrudController extends CrudController |
13
|
|
|
{ |
14
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
15
|
1 |
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation { |
16
|
|
|
update as traitUpdate; |
17
|
1 |
|
} |
18
|
1 |
|
|
19
|
1 |
|
/** |
20
|
|
|
* Prepare the admin interface by setting the associated |
21
|
1 |
|
* model, setting the route, and adding custom columns/fields. |
22
|
1 |
|
* |
23
|
|
|
* @return void |
24
|
1 |
|
*/ |
25
|
1 |
|
public function setup(): void |
26
|
|
|
{ |
27
|
|
|
$this->crud->setModel('App\Models\JobPoster'); |
28
|
|
|
$this->crud->setRoute('admin/job-poster'); |
29
|
1 |
|
$this->crud->setEntityNameStrings('Job Poster', 'Job Posters'); |
30
|
|
|
|
31
|
1 |
|
if (!$this->request->has('order')) { |
32
|
1 |
|
$this->crud->orderBy('close_date_time', 'desc'); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function setupListOperation() |
37
|
1 |
|
{ |
38
|
|
|
// Required for order logic. |
39
|
|
|
$locale = 'en'; |
40
|
|
|
if (null !== $this->request->input('locale')) { |
41
|
1 |
|
$locale = $this->request->input('locale'); |
42
|
1 |
|
} |
43
|
|
|
App::setLocale($locale); |
44
|
|
|
|
45
|
|
|
// Add the custom blade buttons found in resources/views/vendor/backpack/crud/buttons/. |
46
|
1 |
|
$this->crud->addButtonFromView('line', 'job_admin_edit', 'job_admin_edit', 'end'); |
47
|
1 |
|
$this->crud->addButtonFromView('line', 'spb_link', 'spb_link', 'end'); |
48
|
|
|
$this->crud->addButtonFromView('line', 'jpb_link', 'jpb_link', 'end'); |
49
|
|
|
$this->crud->addButtonFromView('line', 'job_poster_link', 'job_poster_link', 'end'); |
50
|
|
|
$this->crud->addButtonFromView('line', 'applicants_download', 'applicants_download', 'end'); |
51
|
|
|
|
52
|
1 |
|
$this->crud->addColumn([ |
53
|
1 |
|
'name' => 'id', |
54
|
|
|
'type' => 'number', |
55
|
|
|
'label' => 'ID' |
56
|
|
|
]); |
57
|
1 |
|
$this->crud->addColumn([ |
58
|
1 |
|
'name' => 'title', |
59
|
|
|
'type' => 'text', |
60
|
|
|
'label' => 'Title', |
61
|
|
|
'searchLogic' => function ($query, $column, $searchTerm) use ($locale): void { |
62
|
1 |
|
$query->orWhere('title->' . $locale, 'ilike', "%$searchTerm%"); |
63
|
1 |
|
}, |
64
|
1 |
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
65
|
1 |
|
return $query->orderBy('title->' . $locale, $columnDirection)->select('*'); |
66
|
|
|
} |
67
|
|
|
]); |
68
|
|
|
$this->crud->addColumn([ |
69
|
|
|
'name' => 'job_poster_status.key', |
70
|
|
|
'label' => 'Status', |
71
|
1 |
|
'type' => 'text', |
72
|
|
|
'orderable' => true, |
73
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) { |
74
|
1 |
|
return $query->leftJoin('job_poster_status', 'job_poster_status.id', '=', 'job_posters.job_poster_status_id') |
75
|
1 |
|
->orderBy('job_poster_status.key', $columnDirection)->select('job_posters.*'); |
76
|
|
|
} |
77
|
|
|
]); |
78
|
|
|
$this->crud->addColumn([ |
79
|
|
|
'name' => 'isOpen', |
80
|
|
|
'label' => 'Open', |
81
|
|
|
'type' => 'closure', |
82
|
1 |
|
'orderable' => false, |
83
|
1 |
|
'function' => function ($entry) { |
84
|
|
|
return $entry->isOpen() ? |
85
|
|
|
'<span><i class="fa fa-check-circle"></i></span>' : |
86
|
|
|
'<span><i class="fa fa-circle"></i></span>'; |
87
|
|
|
} |
88
|
|
|
]); |
89
|
|
|
$this->crud->addColumn([ |
90
|
1 |
|
'name' => 'isClosed', |
91
|
1 |
|
'label' => 'Closed', |
92
|
1 |
|
'type' => 'closure', |
93
|
|
|
'orderable' => false, |
94
|
|
|
'function' => function ($entry) { |
95
|
|
|
return $entry->isClosed() ? |
96
|
|
|
'<span><i class="fa fa-check-circle"></i></span>' : |
97
|
1 |
|
'<span><i class="fa fa-circle"></i></span>'; |
98
|
|
|
} |
99
|
|
|
]); |
100
|
|
|
|
101
|
|
|
$this->crud->addColumn([ |
102
|
|
|
'name' => 'internal_only', |
103
|
|
|
'label' => 'Internal Only', |
104
|
|
|
'type' => 'check', |
105
|
|
|
]); |
106
|
|
|
|
107
|
|
|
$this->crud->addColumn([ |
108
|
|
|
'name' => 'manager_user_name', |
109
|
|
|
'type' => 'closure', |
110
|
|
|
'label' => 'Manager', |
111
|
|
|
'orderable' => false, |
112
|
|
|
'function' => function ($entry) { |
113
|
|
|
return '<a href="' . route('manager.profile.edit', $entry->manager->id) . '" target="_blank">' . $entry->manager->user->full_name . '</a>'; |
|
|
|
|
114
|
|
|
} |
115
|
|
|
]); |
116
|
|
|
$this->crud->addColumn([ |
117
|
|
|
'name' => 'department.name', |
118
|
|
|
'label' => 'Department', |
119
|
|
|
'type' => 'text' |
120
|
|
|
]); |
121
|
|
|
$this->crud->addColumn([ |
122
|
|
|
'name' => 'submitted_applications_count', |
123
|
|
|
'label' => 'Applications', |
124
|
|
|
'type' => 'closure', |
125
|
|
|
'function' => |
126
|
|
|
function ($entry) { |
127
|
|
|
return $entry->submitted_applications_count() > 0 ? |
128
|
|
|
'<a target="_blank" href="' . route('manager.jobs.applications', $entry->id) . '">' . $entry->submitted_applications_count() . ' (View <i class="fa fa-external-link"></i>)</a>' : |
|
|
|
|
129
|
|
|
$entry->submitted_applications_count(); |
130
|
|
|
} |
131
|
|
|
]); |
132
|
|
|
|
133
|
|
|
// Filters. |
134
|
|
|
$this->crud->addFilter([ |
135
|
|
|
'name' => 'departments', |
136
|
|
|
'type' => 'select2_multiple', |
137
|
|
|
'label' => 'Filter by department' |
138
|
|
|
], function () { |
139
|
|
|
return Department::all()->pluck('name', 'id')->toArray(); |
140
|
|
|
}, function ($values) { |
141
|
|
|
$this->crud->addClause('WhereHas', 'department', function ($query) use ($values) { |
142
|
|
|
foreach (json_decode($values) as $key => $value) { |
143
|
|
|
if ($key === 0) { |
144
|
|
|
$query->where('id', $value); |
145
|
|
|
} else { |
146
|
|
|
$query->orWhere('id', $value); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
}); |
150
|
|
|
}); |
151
|
|
|
|
152
|
|
|
$this->crud->addFilter([ |
153
|
|
|
'name' => 'statuses', |
154
|
|
|
'type' => 'select2_multiple', |
155
|
|
|
'label' => 'Filter by status' |
156
|
|
|
], function () { |
157
|
|
|
// Using key because some of the job status names are the same. |
158
|
|
|
return JobPosterStatus::all()->pluck('key', 'id')->toArray(); |
159
|
|
|
}, function ($values) { |
160
|
|
|
$this->crud->addClause('WhereHas', 'job_poster_status', function ($query) use ($values) { |
161
|
|
|
foreach (json_decode($values) as $key => $value) { |
162
|
|
|
if ($key === 0) { |
163
|
|
|
$query->where('id', $value); |
164
|
|
|
} else { |
165
|
|
|
$query->orWhere('id', $value); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
}); |
169
|
|
|
}); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function setupUpdateOperation() |
173
|
|
|
{ |
174
|
|
|
$this->crud->addField([ |
175
|
|
|
'name' => 'title', |
176
|
|
|
'label' => 'Title', |
177
|
|
|
'type' => 'text', |
178
|
|
|
'attributes' => [ |
179
|
|
|
'readonly' => 'readonly' |
180
|
|
|
] |
181
|
|
|
]); |
182
|
|
|
$this->crud->addField([ |
183
|
|
|
'name' => 'salary_min', |
184
|
|
|
'type' => 'number', |
185
|
|
|
'label' => 'Minimum Salary', |
186
|
|
|
]); |
187
|
|
|
$this->crud->addField([ |
188
|
|
|
'name' => 'salary_max', |
189
|
|
|
'type' => 'number', |
190
|
|
|
'label' => 'Maximum Salary', |
191
|
|
|
]); |
192
|
|
|
$this->crud->addField([ |
193
|
|
|
'name' => 'noc', |
194
|
|
|
'type' => 'number', |
195
|
|
|
'label' => 'NOC Code', |
196
|
|
|
]); |
197
|
|
|
$this->crud->addField([ |
198
|
|
|
'name' => 'open_date_time', |
199
|
|
|
'label' => 'Open Date', |
200
|
|
|
'type' => 'date_picker', |
201
|
|
|
'date_picker_options' => [ |
202
|
|
|
'todayBtn' => 'linked', |
203
|
|
|
'format' => 'yyyy-mm-dd', |
204
|
|
|
], |
205
|
|
|
]); |
206
|
|
|
$this->crud->addField([ |
207
|
|
|
'name' => 'close_date_time', |
208
|
|
|
'label' => 'Close Date', |
209
|
|
|
'type' => 'date_picker', |
210
|
|
|
'date_picker_options' => [ |
211
|
|
|
'todayBtn' => 'linked', |
212
|
|
|
'format' => 'yyyy-mm-dd', |
213
|
|
|
], |
214
|
|
|
]); |
215
|
|
|
$this->crud->addField([ |
216
|
|
|
'name' => 'start_date_time', |
217
|
|
|
'label' => 'Start Date', |
218
|
|
|
'type' => 'date_picker', |
219
|
|
|
'date_picker_options' => [ |
220
|
|
|
'todayBtn' => 'linked', |
221
|
|
|
'format' => 'yyyy-mm-dd', |
222
|
|
|
], |
223
|
|
|
]); |
224
|
|
|
$this->crud->addField([ |
225
|
|
|
'name' => 'process_number', |
226
|
|
|
'type' => 'text', |
227
|
|
|
'label' => 'Process #', |
228
|
|
|
]); |
229
|
|
|
$this->crud->addField([ |
230
|
|
|
'name' => 'priority_clearance_number', |
231
|
|
|
'type' => 'number', |
232
|
|
|
'label' => 'Priority Clearance #', |
233
|
|
|
]); |
234
|
|
|
$this->crud->addField([ |
235
|
|
|
'name' => 'loo_issuance_date', |
236
|
|
|
'type' => 'date_picker', |
237
|
|
|
'label' => 'Letter of Offer Issuance Date', |
238
|
|
|
'date_picker_options' => [ |
239
|
|
|
'todayBtn' => 'linked', |
240
|
|
|
'format' => 'yyyy-mm-dd', |
241
|
|
|
], |
242
|
|
|
]); |
243
|
|
|
|
244
|
|
|
$this->crud->addField([ |
245
|
|
|
'name' => 'internal_only', |
246
|
|
|
'type' => 'checkbox', |
247
|
|
|
'label' => 'Internal Only (Do not list this poster on the Browse Jobs page. You must access it with the direct URL.)', |
248
|
|
|
]); |
249
|
|
|
|
250
|
|
|
$transitionManager = new JobStatusTransitionManager(); |
251
|
|
|
$job = $this->crud->getCurrentEntry(); |
252
|
|
|
$legalDestinations = $transitionManager->legalDestinations($job->job_poster_status->key); |
253
|
|
|
$validStatuses = JobPosterStatus::all()->filter(function ($status) use ($job, $legalDestinations) { |
254
|
|
|
return in_array($status->key, $legalDestinations) || $status->id === $job->job_poster_status_id; |
255
|
|
|
}); |
256
|
|
|
$statusOptions = $validStatuses->mapWithKeys(function ($status) { |
257
|
|
|
return [$status->id => $status->key]; |
258
|
|
|
}); |
259
|
|
|
$this->crud->addField([ |
260
|
|
|
'name' => 'job_poster_status_id', |
261
|
|
|
'label' => 'Status', |
262
|
|
|
'type' => 'select_from_array', |
263
|
|
|
'options' => $statusOptions, |
264
|
|
|
'allows_null' => false, |
265
|
|
|
'default' => $job->job_poster_status_id, |
266
|
|
|
]); |
267
|
|
|
|
268
|
|
|
// Strategic Talent Response fields |
269
|
|
|
$this->crud->addField([ |
270
|
|
|
'label' => 'Talent Stream', |
271
|
|
|
'type' => 'select', |
272
|
|
|
'name' => 'talent_stream_id', // the db column for the foreign key |
273
|
|
|
'entity' => 'talent_stream', // the method that defines the relationship in your Model |
274
|
|
|
'attribute' => 'name', // foreign key attribute that is shown to user |
275
|
|
|
]); |
276
|
|
|
$this->crud->addField([ |
277
|
|
|
'label' => 'Talent Stream Subcategory', |
278
|
|
|
'type' => 'select', |
279
|
|
|
'name' => 'talent_stream_category_id', // the db column for the foreign key |
280
|
|
|
'entity' => 'talent_stream_category', // the method that defines the relationship in your Model |
281
|
|
|
'attribute' => 'name', // foreign key attribute that is shown to user |
282
|
|
|
]); |
283
|
|
|
$this->crud->addField([ |
284
|
|
|
'label' => 'Job Skill Level', |
285
|
|
|
'type' => 'select', |
286
|
|
|
'name' => 'job_skill_level_id', // the db column for the foreign key |
287
|
|
|
'entity' => 'job_skill_level', // the method that defines the relationship in your Model |
288
|
|
|
'attribute' => 'name', // foreign key attribute that is shown to user |
289
|
|
|
]); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function update() |
293
|
|
|
{ |
294
|
|
|
$open_date_time = $this->crud->request->request->get('open_date_time'); |
295
|
|
|
$close_date_time = $this->crud->request->request->get('close_date_time'); |
296
|
|
|
$start_date_time = $this->crud->request->request->get('start_date_time'); |
297
|
|
|
|
298
|
|
|
$job = $this->crud->getCurrentEntry(); |
299
|
|
|
|
300
|
|
|
$open_date_current = new Date("$job->open_date_time"); |
301
|
|
|
$close_date_current = new Date("$job->close_date_time"); |
302
|
|
|
$start_date_current = new Date("$job->start_date_time"); |
303
|
|
|
|
304
|
|
|
if ($open_date_current->format('Y-m-d') !== $open_date_time) { |
305
|
|
|
$this->crud->request->request->remove('open_date_time'); |
306
|
|
|
// Manipulates the input field to save the "start of day" timestamp. |
307
|
|
|
$this->crud->request->request->add([ |
308
|
|
|
'open_date_time' => $open_date_time !== null ? ptDayStartToUtcTime($open_date_time) : null |
309
|
|
|
]); |
310
|
|
|
} else { |
311
|
|
|
$this->crud->request->request->add([ |
312
|
|
|
'open_date_time' => $open_date_current |
313
|
|
|
]); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
if ($close_date_current->format('Y-m-d') !== $close_date_time) { |
317
|
|
|
$this->crud->request->request->remove('close_date_time'); |
318
|
|
|
// Manipulates the input field to save the "end of day" timestamp. |
319
|
|
|
$this->crud->request->request->add([ |
320
|
|
|
'close_date_time' => $close_date_time !== null ? ptDayEndToUtcTime($close_date_time) : null |
321
|
|
|
]); |
322
|
|
|
} else { |
323
|
|
|
$this->crud->request->request->add([ |
324
|
|
|
'close_date_time' => $close_date_current |
325
|
|
|
]); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
if ($start_date_current->format('Y-m-d') !== $start_date_time) { |
329
|
|
|
$this->crud->request->request->remove('start_date_time'); |
330
|
|
|
// Manipulates the input field to save the "start of day" timestamp. |
331
|
|
|
$this->crud->request->request->add([ |
332
|
|
|
'start_date_time' => $start_date_time !== null ? ptDayStartToUtcTime($start_date_time) : null |
333
|
|
|
]); |
334
|
|
|
} else { |
335
|
|
|
$this->crud->request->request->add([ |
336
|
|
|
'start_date_time' => $start_date_current |
337
|
|
|
]); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
$response = $this->traitUpdate(); |
341
|
|
|
|
342
|
|
|
return $response; |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|