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