1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Lang; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
use Illuminate\Support\Facades\Mail; |
9
|
|
|
use Illuminate\Http\RedirectResponse; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use Illuminate\Http\Response; |
12
|
|
|
use Illuminate\View\View; |
13
|
|
|
use App\Http\Controllers\Controller; |
14
|
|
|
|
15
|
|
|
use Carbon\Carbon; |
16
|
|
|
|
17
|
|
|
use App\Mail\JobPosterReviewRequested; |
18
|
|
|
|
19
|
|
|
use App\Exceptions\AdminException; |
20
|
|
|
|
21
|
|
|
use App\Models\Criteria; |
22
|
|
|
use App\Models\JobPoster; |
23
|
|
|
use App\Models\JobPosterKeyTask; |
24
|
|
|
use App\Models\JobPosterQuestion; |
25
|
|
|
use App\Models\Lookup\JobTerm; |
26
|
|
|
use App\Models\Lookup\Province; |
27
|
|
|
use App\Models\Lookup\SecurityClearance; |
28
|
|
|
use App\Models\Lookup\LanguageRequirement; |
29
|
|
|
use App\Models\Lookup\Department; |
30
|
|
|
use App\Models\Lookup\SkillLevel; |
31
|
|
|
use App\Models\Lookup\CriteriaType; |
32
|
|
|
use App\Models\Skill; |
33
|
|
|
use App\Models\Manager; |
34
|
|
|
|
35
|
|
|
use App\Services\Validation\JobPosterValidator; |
36
|
|
|
use Jenssegers\Date\Date; |
37
|
|
|
|
38
|
|
|
class JobController extends Controller |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Display a listing of JobPosters. |
42
|
|
|
* |
43
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
44
|
|
|
*/ |
45
|
|
|
public function index() |
46
|
|
|
{ |
47
|
|
|
$now = Carbon::now(); |
48
|
|
|
|
49
|
|
|
// Find published jobs that are currently open for applications. |
50
|
|
|
// Eager load required relationships: Department, Province, JobTerm. |
51
|
|
|
// Eager load the count of submitted applications, to prevent the relationship |
52
|
|
|
// from being actually loaded and firing off events. |
53
|
|
|
$jobs = JobPoster::where('open_date_time', '<=', $now) |
54
|
|
|
->where('close_date_time', '>=', $now) |
55
|
|
|
->where('published', true) |
56
|
|
|
->with([ |
57
|
|
|
'department', |
58
|
|
|
'province', |
59
|
|
|
'job_term', |
60
|
|
|
]) |
61
|
|
|
->withCount([ |
62
|
|
|
'submitted_applications', |
63
|
|
|
]) |
64
|
|
|
->get(); |
65
|
|
|
return view('applicant/job_index', [ |
66
|
|
|
'job_index' => Lang::get('applicant/job_index'), |
67
|
|
|
'jobs' => $jobs |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Display a listing of a manager's JobPosters. |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
75
|
|
|
*/ |
76
|
1 |
|
public function managerIndex() |
77
|
|
|
{ |
78
|
1 |
|
$manager = Auth::user()->manager; |
|
|
|
|
79
|
1 |
|
$jobs = JobPoster::where('manager_id', $manager->id) |
80
|
1 |
|
->withCount('submitted_applications') |
81
|
1 |
|
->get(); |
82
|
|
|
|
83
|
1 |
|
return view('manager/job_index', [ |
84
|
|
|
/*Localization Strings*/ |
85
|
1 |
|
'jobs_l10n' => Lang::get('manager/job_index'), |
86
|
|
|
|
87
|
|
|
/* Data */ |
88
|
1 |
|
'jobs' => $jobs, |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Submit the Job Poster for review. |
94
|
|
|
* |
95
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
96
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
97
|
|
|
* |
98
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
99
|
|
|
*/ |
100
|
1 |
|
public function submitForReview(Request $request, JobPoster $jobPoster) |
101
|
|
|
{ |
102
|
|
|
// Update review request timestamp |
103
|
1 |
|
$jobPoster->review_requested_at = new Date(); |
104
|
1 |
|
$jobPoster->save(); |
105
|
|
|
|
106
|
|
|
// Refresh model instance with updated DB values. |
107
|
1 |
|
$jobPoster = JobPoster::withCount('submitted_applications')->where('id', $jobPoster->id)->first(); |
108
|
|
|
|
109
|
|
|
// Send email |
110
|
1 |
|
$reviewer_email = config('mail.reviewer_email'); |
111
|
1 |
|
if (isset($reviewer_email)) { |
112
|
1 |
|
Mail::to($reviewer_email)->send(new JobPosterReviewRequested($jobPoster, Auth::user())); |
|
|
|
|
113
|
|
|
} else { |
114
|
|
|
Log::error('The reviewer email environment variable is not set.'); |
115
|
|
|
} |
116
|
|
|
|
117
|
1 |
|
return view('manager/job_index/job', [ |
118
|
|
|
/*Localization Strings*/ |
119
|
1 |
|
'jobs_l10n' => Lang::get('manager/job_index'), |
120
|
1 |
|
'job' => $jobPoster |
121
|
|
|
]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Delete a draft Job Poster. |
126
|
|
|
* |
127
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
128
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function destroy(Request $request, JobPoster $jobPoster) : void |
133
|
|
|
{ |
134
|
|
|
$jobPoster->delete(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Display the specified job poster. |
139
|
|
|
* |
140
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
141
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
142
|
|
|
* |
143
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
144
|
|
|
*/ |
145
|
4 |
|
public function show(Request $request, JobPoster $jobPoster) |
146
|
|
|
{ |
147
|
4 |
|
$jobPoster->load([ |
148
|
4 |
|
'department', |
149
|
|
|
'criteria.skill.skill_type', |
150
|
|
|
'manager.team_culture', |
151
|
|
|
'manager.work_environment' |
152
|
|
|
]); |
153
|
|
|
|
154
|
4 |
|
$user = Auth::user(); |
|
|
|
|
155
|
|
|
|
156
|
|
|
//TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model |
157
|
4 |
|
$workplacePhotos = []; |
158
|
4 |
|
foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
159
|
|
|
$workplacePhotos[] = [ |
160
|
|
|
'description' => $photoCaption->description, |
161
|
|
|
'url' => '/images/user.png' |
162
|
|
|
]; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
//TODO: replace route('manager.show',manager.id) in templates with link using slug |
166
|
|
|
|
167
|
|
|
$criteria = [ |
168
|
4 |
|
'essential' => $jobPoster->criteria->filter( |
169
|
|
|
function ($value, $key) { |
170
|
2 |
|
return $value->criteria_type->name == 'essential'; |
171
|
4 |
|
} |
172
|
|
|
), |
173
|
4 |
|
'asset' => $jobPoster->criteria->filter( |
174
|
|
|
function ($value, $key) { |
175
|
2 |
|
return $value->criteria_type->name == 'asset'; |
176
|
4 |
|
} |
177
|
|
|
), |
178
|
|
|
]; |
179
|
|
|
|
180
|
4 |
|
$jobLang = Lang::get('applicant/job_post'); |
181
|
|
|
|
182
|
4 |
|
$applyButton = []; |
183
|
4 |
|
if (!$jobPoster->published && $this->authorize('update', $jobPoster)) { |
184
|
|
|
$applyButton = [ |
185
|
2 |
|
'href' => route('manager.jobs.edit', $jobPoster->id), |
186
|
2 |
|
'title' => $jobLang['apply']['edit_link_title'], |
187
|
2 |
|
'text' => $jobLang['apply']['edit_link_label'], |
188
|
|
|
]; |
189
|
2 |
|
} elseif (Auth::check() && $jobPoster->isOpen()) { |
190
|
|
|
$applyButton = [ |
191
|
1 |
|
'href' => route('job.application.edit.1', $jobPoster->id), |
192
|
1 |
|
'title' => $jobLang['apply']['apply_link_title'], |
193
|
1 |
|
'text' => $jobLang['apply']['apply_link_label'], |
194
|
|
|
]; |
195
|
1 |
|
} elseif (Auth::guest() && $jobPoster->isOpen()) { |
196
|
|
|
$applyButton = [ |
197
|
1 |
|
'href' => route('job.application.edit.1', $jobPoster->id), |
198
|
1 |
|
'title' => $jobLang['apply']['login_link_title'], |
199
|
1 |
|
'text' => $jobLang['apply']['login_link_label'], |
200
|
|
|
]; |
201
|
|
|
} else { |
202
|
|
|
$applyButton = [ |
203
|
|
|
'href' => null, |
204
|
|
|
'title' => null, |
205
|
|
|
'text' => $jobLang['apply']['job_closed_label'], |
206
|
|
|
]; |
207
|
|
|
} |
208
|
|
|
|
209
|
4 |
|
return view( |
210
|
4 |
|
'applicant/job_post', |
211
|
|
|
[ |
212
|
4 |
|
'job_post' => $jobLang, |
213
|
4 |
|
'manager' => $jobPoster->manager, |
214
|
4 |
|
'manager_profile_photo_url' => '/images/user.png', //TODO get real photo |
215
|
4 |
|
'team_culture' => $jobPoster->manager->team_culture, |
216
|
4 |
|
'work_environment' => $jobPoster->manager->work_environment, |
217
|
4 |
|
'workplace_photos' => $workplacePhotos, |
218
|
4 |
|
'job' => $jobPoster, |
219
|
4 |
|
'criteria' => $criteria, |
220
|
4 |
|
'apply_button' => $applyButton, |
221
|
4 |
|
'skill_template' => Lang::get('common/skills'), |
222
|
|
|
] |
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Create a blank job poster for the specified manager |
228
|
|
|
* |
229
|
|
|
* @param Manager $manager |
|
|
|
|
230
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
231
|
|
|
*/ |
|
|
|
|
232
|
2 |
|
public function createAsManager(Manager $manager) |
233
|
|
|
{ |
234
|
2 |
|
$jobPoster = new JobPoster(); |
235
|
2 |
|
$jobPoster->manager_id = $manager->id; |
236
|
2 |
|
$managerEn = $manager->translate('en'); |
237
|
2 |
|
$managerFr = $manager->translate('fr'); |
238
|
|
|
|
239
|
|
|
try { |
240
|
2 |
|
$jobPoster->fill([ |
241
|
2 |
|
'department_id' => $manager->department_id, |
242
|
|
|
'en' => [ |
243
|
2 |
|
'branch' => $managerEn->branch, |
244
|
2 |
|
'division' => $managerEn->division, |
245
|
|
|
], |
246
|
|
|
'fr' => [ |
247
|
2 |
|
'branch' => $managerFr->branch, |
248
|
2 |
|
'division' => $managerFr->division, |
249
|
|
|
] |
250
|
|
|
]); |
251
|
2 |
|
$jobPoster->save(); |
252
|
|
|
} catch (\Exception $e) { |
253
|
|
|
throw new AdminException( |
254
|
|
|
'Manager missing the following required fields: Department, Branch and Division.', |
255
|
|
|
500, |
256
|
|
|
null, |
257
|
|
|
[ |
258
|
|
|
'Back to Admin' => '/admin', |
259
|
|
|
'Manager Profile' => "/manager/profile/$manager->id/edit" |
260
|
|
|
] |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
2 |
|
$defaultQuestions = $this->populateDefaultQuestions(); |
265
|
2 |
|
if (!empty($defaultQuestions)) { |
266
|
2 |
|
$jobPoster->job_poster_questions()->saveMany($defaultQuestions); |
267
|
|
|
} |
268
|
|
|
|
269
|
2 |
|
return redirect()->route('manager.jobs.edit', $jobPoster->id); |
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Display the form for creating a new Job Poster |
274
|
|
|
* |
275
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
276
|
|
|
* |
277
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
278
|
|
|
*/ |
279
|
|
|
public function create(Request $request) |
280
|
|
|
{ |
281
|
|
|
return $this->populateCreateView($request); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Display the form for editing an existing Job Poster |
286
|
|
|
* |
287
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
288
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
289
|
|
|
* |
290
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
291
|
|
|
*/ |
292
|
1 |
|
public function edit(Request $request, JobPoster $jobPoster) |
293
|
|
|
{ |
294
|
1 |
|
return $this->populateCreateView($request, $jobPoster); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Get the manager from the request object and check if creating or editing |
299
|
|
|
* |
300
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
301
|
|
|
* @param \App\Models\JobPoster $jobPoster Optional Job Poster object. |
302
|
|
|
* |
303
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
304
|
|
|
*/ |
305
|
1 |
|
public function populateCreateView(Request $request, JobPoster $jobPoster = null) |
306
|
|
|
{ |
307
|
1 |
|
if ($jobPoster == null || $jobPoster->manager == null) { |
308
|
|
|
$manager = $request->user() ? $request->user()->manager : null; |
309
|
|
|
} else { |
310
|
1 |
|
$manager = $jobPoster->manager; |
311
|
|
|
} |
312
|
|
|
|
313
|
1 |
|
if (isset($jobPoster)) { |
314
|
1 |
|
$job = $jobPoster; |
315
|
1 |
|
$route = ['manager.jobs.update', $jobPoster]; |
316
|
1 |
|
$jobHeading = 'manager/job_edit'; |
317
|
|
|
} else { |
318
|
|
|
$job = []; |
319
|
|
|
$defaultQuestions = $this->populateDefaultQuestions(); |
320
|
|
|
if (!empty($defaultQuestions)) { |
321
|
|
|
$job['job_poster_questions'] = $defaultQuestions; |
322
|
|
|
} |
323
|
|
|
$route = ['manager.jobs.store']; |
324
|
|
|
$jobHeading = 'manager/job_create'; |
325
|
|
|
} |
326
|
|
|
|
327
|
1 |
|
$skillLangs = Lang::get('common/skills'); |
328
|
|
|
|
329
|
1 |
|
$softSkills = Skill::whereHas( |
330
|
1 |
|
'skill_type', |
331
|
|
|
function ($query) : void { |
332
|
1 |
|
$query->where('name', '=', 'soft'); |
333
|
1 |
|
} |
334
|
1 |
|
)->get() |
335
|
1 |
|
->mapWithKeys( |
336
|
|
|
function ($skill) { |
337
|
|
|
return [ |
338
|
1 |
|
$skill->id => $skill->name |
339
|
|
|
]; |
340
|
1 |
|
} |
341
|
|
|
) |
342
|
1 |
|
->all(); |
343
|
|
|
|
344
|
1 |
|
$hardSkills = Skill::whereHas( |
345
|
1 |
|
'skill_type', |
346
|
|
|
function ($query) : void { |
347
|
1 |
|
$query->where('name', '=', 'hard'); |
348
|
1 |
|
} |
349
|
1 |
|
)->get() |
350
|
1 |
|
->mapWithKeys( |
351
|
|
|
function ($skill) { |
352
|
|
|
return [ |
353
|
1 |
|
$skill->id => $skill->name |
354
|
|
|
]; |
355
|
1 |
|
} |
356
|
|
|
) |
357
|
1 |
|
->all(); |
358
|
|
|
|
359
|
1 |
|
asort($softSkills, SORT_LOCALE_STRING); |
360
|
1 |
|
asort($hardSkills, SORT_LOCALE_STRING); |
361
|
|
|
|
362
|
|
|
$skills = [ |
363
|
|
|
'essential' => [ |
364
|
1 |
|
'hard' => $hardSkills, |
365
|
1 |
|
'soft' => $softSkills |
366
|
|
|
], |
367
|
|
|
'asset' => [ |
368
|
1 |
|
'hard' => $hardSkills, |
369
|
1 |
|
'soft' => $softSkills |
370
|
|
|
] |
371
|
|
|
]; |
372
|
|
|
|
373
|
1 |
|
$skillLevelCollection = SkillLevel::all(); |
374
|
|
|
|
375
|
1 |
|
$skillLevels = array(); |
376
|
|
|
|
377
|
1 |
|
$skillLevels['hard'] = $skillLevelCollection->mapWithKeys( |
378
|
|
|
function ($skillLevel) use ($skillLangs) { |
379
|
1 |
|
return [$skillLevel->id => $skillLangs['skill_levels']['hard'][$skillLevel->name]]; |
380
|
1 |
|
} |
381
|
1 |
|
)->all(); |
382
|
|
|
|
383
|
1 |
|
$skillLevels['soft'] = $skillLevelCollection->mapWithKeys( |
384
|
|
|
function ($skillLevel) use ($skillLangs) { |
385
|
1 |
|
return [$skillLevel->id => $skillLangs['skill_levels']['soft'][$skillLevel->name]]; |
386
|
1 |
|
} |
387
|
1 |
|
)->all(); |
388
|
|
|
|
389
|
1 |
|
return view( |
390
|
1 |
|
'manager/job_create', |
391
|
|
|
[ |
392
|
|
|
/*Localization Strings*/ |
393
|
1 |
|
'job_l10n' => Lang::get('manager/job_create'), |
394
|
|
|
|
395
|
|
|
/* Data */ |
396
|
1 |
|
'job' => Lang::get($jobHeading), |
397
|
1 |
|
'manager' => $manager, |
398
|
1 |
|
'provinces' => Province::all(), |
399
|
1 |
|
'departments' => Department::all(), |
400
|
1 |
|
'language_requirments' => LanguageRequirement::all(), |
401
|
1 |
|
'security_clearances' => SecurityClearance::all(), |
402
|
1 |
|
'job' => $job, |
403
|
1 |
|
'form_action_url' => route(/** @scrutinizer ignore-type */ ...$route), // phpcs:ignore |
|
|
|
|
404
|
1 |
|
'skills' => $skills, |
405
|
1 |
|
'skill_levels' => $skillLevels, |
406
|
1 |
|
'skill_template' => $skillLangs, |
407
|
|
|
] |
408
|
|
|
); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Create a new resource in storage |
413
|
|
|
* |
414
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
415
|
|
|
* @param \App\Models\JobPoster $jobPoster Optional Job Poster object. |
416
|
|
|
* |
417
|
|
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse A redirect to the Job Index |
418
|
|
|
*/ |
419
|
3 |
|
public function store(Request $request, JobPoster $jobPoster = null) |
420
|
|
|
{ |
421
|
|
|
// Don't allow edits for published Job Posters |
422
|
|
|
// Also check auth while we're at it |
423
|
3 |
|
if (isset($jobPoster)) { |
424
|
3 |
|
$this->authorize('update', $jobPoster); |
425
|
3 |
|
JobPosterValidator::validateUnpublished($jobPoster); |
426
|
|
|
} else { |
427
|
|
|
$this->authorize('create', JobPoster::class); |
428
|
|
|
} |
429
|
|
|
|
430
|
3 |
|
$input = $request->input(); |
431
|
|
|
|
432
|
3 |
|
$job = (isset($jobPoster) ? $jobPoster : new JobPoster()); |
433
|
|
|
|
434
|
3 |
|
if ($job->manager_id == null) { |
435
|
|
|
$job->manager_id = $request->user()->manager->id; |
436
|
|
|
$job->save(); |
437
|
|
|
} |
438
|
|
|
|
439
|
3 |
|
$this->fillAndSaveJobPoster($input, $job); |
440
|
|
|
|
441
|
3 |
|
$this->fillAndSaveJobPosterTasks($input, $job, isset($jobPoster)); |
442
|
|
|
|
443
|
3 |
|
$this->fillAndSaveJobPosterQuestions($input, $job, isset($jobPoster)); |
444
|
|
|
|
445
|
3 |
|
$this->fillAndSaveJobPosterCriteria($input, $job, isset($jobPoster)); |
446
|
|
|
|
447
|
3 |
|
return redirect(route('manager.jobs.show', $job->id)); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Fill Job Poster model's properties and save |
452
|
|
|
* |
453
|
|
|
* @param mixed[] $input Field values. |
454
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
455
|
|
|
* |
456
|
|
|
* @return void |
457
|
|
|
*/ |
458
|
3 |
|
protected function fillAndSaveJobPoster(array $input, JobPoster $jobPoster) : void |
459
|
|
|
{ |
460
|
3 |
|
$jobPoster->fill( |
461
|
|
|
[ |
462
|
3 |
|
'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id, |
463
|
3 |
|
'term_qty' => $input['term_qty'], |
464
|
3 |
|
'open_date_time' => ptDayStartToUtcTime($input['open_date']), |
465
|
3 |
|
'close_date_time' => ptDayEndToUtcTime($input['close_date']), |
466
|
3 |
|
'start_date_time' => ptDayStartToUtcTime($input['start_date']), |
467
|
3 |
|
'department_id' => $input['department'], |
468
|
3 |
|
'province_id' => $input['province'], |
469
|
3 |
|
'salary_min' => $input['salary_min'], |
470
|
3 |
|
'salary_max' => $input['salary_max'], |
471
|
3 |
|
'noc' => $input['noc'], |
472
|
3 |
|
'classification' => $input['classification'], |
473
|
3 |
|
'security_clearance_id' => $input['security_clearance'], |
474
|
3 |
|
'language_requirement_id' => $input['language_requirement'], |
475
|
3 |
|
'remote_work_allowed' => (isset($input['remote_work_allowed']) ? $input['remote_work_allowed'] : false), |
476
|
|
|
'en' => [ |
477
|
3 |
|
'city' => $input['city'], |
478
|
3 |
|
'title' => $input['title']['en'], |
479
|
3 |
|
'impact' => $input['impact']['en'], |
480
|
3 |
|
'branch' => $input['branch']['en'], |
481
|
3 |
|
'division' => $input['division']['en'], |
482
|
3 |
|
'education' => $input['education']['en'], |
483
|
|
|
], |
484
|
|
|
'fr' => [ |
485
|
3 |
|
'city' => $input['city'], |
486
|
3 |
|
'title' => $input['title']['fr'], |
487
|
3 |
|
'impact' => $input['impact']['fr'], |
488
|
3 |
|
'branch' => $input['branch']['fr'], |
489
|
3 |
|
'division' => $input['division']['fr'], |
490
|
3 |
|
'education' => $input['education']['fr'], |
491
|
|
|
], |
492
|
|
|
] |
493
|
|
|
); |
494
|
3 |
|
$jobPoster->save(); |
495
|
3 |
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Fill Job Poster's tasks and save |
499
|
|
|
* |
500
|
|
|
* @param mixed[] $input Field values. |
501
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
502
|
|
|
* @param boolean $replace Remove existing relationships. |
503
|
|
|
* |
504
|
|
|
* @return void |
505
|
|
|
*/ |
506
|
3 |
|
protected function fillAndSaveJobPosterTasks(array $input, JobPoster $jobPoster, bool $replace) : void |
507
|
|
|
{ |
508
|
3 |
|
if ($replace) { |
509
|
3 |
|
$jobPoster->job_poster_key_tasks()->delete(); |
510
|
|
|
} |
511
|
|
|
|
512
|
3 |
|
if (!array_key_exists('task', $input) || !is_array($input['task'])) { |
513
|
3 |
|
return; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
foreach ($input['task'] as $task) { |
517
|
|
|
$jobPosterTask = new JobPosterKeyTask(); |
518
|
|
|
$jobPosterTask->job_poster_id = $jobPoster->id; |
519
|
|
|
$jobPosterTask->fill( |
520
|
|
|
[ |
521
|
|
|
'en' => [ |
522
|
|
|
'description' => $task['en'] |
523
|
|
|
], |
524
|
|
|
'fr' => [ |
525
|
|
|
'description' => $task['fr'] |
526
|
|
|
] |
527
|
|
|
] |
528
|
|
|
); |
529
|
|
|
$jobPosterTask->save(); |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Fill Job Poster's questions and save |
535
|
|
|
* |
536
|
|
|
* @param mixed[] $input Field values. |
537
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
538
|
|
|
* @param boolean $replace Remove existing relationships. |
539
|
|
|
* |
540
|
|
|
* @return void |
541
|
|
|
*/ |
542
|
3 |
|
protected function fillAndSaveJobPosterQuestions(array $input, JobPoster $jobPoster, bool $replace) : void |
543
|
|
|
{ |
544
|
3 |
|
if ($replace) { |
545
|
3 |
|
$jobPoster->job_poster_questions()->delete(); |
546
|
|
|
} |
547
|
|
|
|
548
|
3 |
|
if (!array_key_exists('question', $input) || !is_array($input['question'])) { |
549
|
3 |
|
return; |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
foreach ($input['question'] as $question) { |
553
|
|
|
$jobQuestion = new JobPosterQuestion(); |
554
|
|
|
$jobQuestion->job_poster_id = $jobPoster->id; |
555
|
|
|
$jobQuestion->fill( |
556
|
|
|
[ |
557
|
|
|
'en' => [ |
558
|
|
|
'question' => $question['question']['en'], |
559
|
|
|
'description' => $question['description']['en'] |
560
|
|
|
], |
561
|
|
|
'fr' => [ |
562
|
|
|
'question' => $question['question']['fr'], |
563
|
|
|
'description' => $question['description']['fr'] |
564
|
|
|
] |
565
|
|
|
] |
566
|
|
|
); |
567
|
|
|
$jobQuestion->save(); |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Fill Job Poster's criteria and save |
573
|
|
|
* |
574
|
|
|
* @param mixed[] $input Field values. |
575
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
576
|
|
|
* @param boolean $replace Remove existing relationships. |
577
|
|
|
* |
578
|
|
|
* @return void |
579
|
|
|
*/ |
580
|
3 |
|
protected function fillAndSaveJobPosterCriteria(array $input, JobPoster $jobPoster, bool $replace) : void |
581
|
|
|
{ |
582
|
3 |
|
if ($replace) { |
583
|
3 |
|
$jobPoster->criteria()->delete(); |
584
|
|
|
} |
585
|
|
|
|
586
|
3 |
|
if (!array_key_exists('criteria', $input) || !is_array($input['criteria'])) { |
587
|
3 |
|
return; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$criteria = $input['criteria']; |
591
|
|
|
|
592
|
|
|
$combinedCriteria = []; |
593
|
|
|
if (isset($criteria['old'])) { |
594
|
|
|
$combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['old']); |
595
|
|
|
} |
596
|
|
|
if (isset($criteria['new'])) { |
597
|
|
|
$combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['new']); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
if (! empty($combinedCriteria)) { |
601
|
|
|
foreach ($combinedCriteria as $criteriaType => $criteriaTypeInput) { |
602
|
|
|
foreach ($criteriaTypeInput as $skillType => $skillTypeInput) { |
603
|
|
|
foreach ($skillTypeInput as $criteriaInput) { |
604
|
|
|
$criteria = new Criteria(); |
605
|
|
|
$criteria->job_poster_id = $jobPoster->id; |
606
|
|
|
$criteria->fill( |
607
|
|
|
[ |
608
|
|
|
'criteria_type_id' => CriteriaType::where('name', $criteriaType)->firstOrFail()->id, |
609
|
|
|
'skill_id' => $criteriaInput['skill_id'], |
610
|
|
|
'skill_level_id' => $criteriaInput['skill_level_id'], |
611
|
|
|
'en' => [ |
612
|
|
|
'description' => $criteriaInput['description']['en'], |
613
|
|
|
], |
614
|
|
|
'fr' => [ |
615
|
|
|
'description' => $criteriaInput['description']['fr'], |
616
|
|
|
], |
617
|
|
|
] |
618
|
|
|
); |
619
|
|
|
$criteria->save(); |
620
|
|
|
} |
621
|
|
|
} |
622
|
|
|
} |
623
|
|
|
} |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Get the localized default questions and add them to an array. |
628
|
|
|
* |
629
|
|
|
* @return mixed[]|void |
630
|
|
|
*/ |
631
|
2 |
|
protected function populateDefaultQuestions() |
632
|
|
|
{ |
633
|
|
|
$defaultQuestions = [ |
634
|
2 |
|
'en' => array_values(Lang::get('manager/job_create', [], 'en')['questions']), |
635
|
2 |
|
'fr' => array_values(Lang::get('manager/job_create', [], 'fr')['questions']), |
636
|
|
|
]; |
637
|
|
|
|
638
|
2 |
|
if (count($defaultQuestions['en']) !== count($defaultQuestions['fr'])) { |
639
|
|
|
Log::warning('There must be the same number of French and English default questions for a Job Poster.'); |
640
|
|
|
return; |
641
|
|
|
} |
642
|
|
|
|
643
|
2 |
|
$jobQuestions = []; |
644
|
|
|
|
645
|
2 |
|
for ($i = 0; $i < count($defaultQuestions['en']); $i++) { |
|
|
|
|
646
|
2 |
|
$jobQuestion = new JobPosterQuestion(); |
647
|
2 |
|
$jobQuestion->fill( |
648
|
|
|
[ |
649
|
|
|
'en' => [ |
650
|
2 |
|
'question' => $defaultQuestions['en'][$i], |
651
|
|
|
], |
652
|
|
|
'fr' => [ |
653
|
2 |
|
'question' => $defaultQuestions['fr'][$i], |
654
|
|
|
] |
655
|
|
|
] |
656
|
|
|
); |
657
|
2 |
|
$jobQuestions[] = $jobQuestion; |
658
|
|
|
} |
659
|
|
|
|
660
|
2 |
|
return $jobQuestions; |
661
|
|
|
} |
662
|
|
|
} |
663
|
|
|
|