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