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