1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Models\JobApplication; |
7
|
|
|
use App\Models\JobPoster; |
8
|
|
|
use App\Models\JobPosterQuestion; |
9
|
|
|
use App\Models\Lookup\ApplicationStatus; |
10
|
|
|
use App\Models\Lookup\CitizenshipDeclaration; |
11
|
|
|
use App\Models\Lookup\JobPosterStatus; |
12
|
|
|
use App\Models\Lookup\VeteranStatus; |
13
|
|
|
use App\Models\Manager; |
14
|
|
|
use App\Services\JobPosterDefaultQuestions; |
15
|
|
|
use App\Services\Validation\JobPosterValidator; |
16
|
|
|
use Carbon\Carbon; |
17
|
|
|
use Facades\App\Services\WhichPortal; |
18
|
|
|
use Illuminate\Http\Request; |
19
|
|
|
use Illuminate\Support\Facades\Auth; |
20
|
|
|
use Illuminate\Support\Facades\Lang; |
21
|
|
|
use Illuminate\Support\Facades\Response; |
22
|
|
|
use Illuminate\Support\Facades\Validator; |
23
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
24
|
|
|
|
25
|
|
|
class JobController extends Controller |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Display a listing of JobPosters. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Http\Response |
31
|
|
|
*/ |
32
|
|
|
public function index() |
33
|
|
|
{ |
34
|
|
|
// If true, show the Paused due to COVID-19 message. |
35
|
|
|
$emergency_response = config('seasonal.is_covid_emergency'); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Find published jobs that are currently open for applications. |
38
|
|
|
// Eager load required relationships: Department, Province, JobTerm. |
39
|
|
|
// Eager load the count of submitted applications, to prevent the relationship |
40
|
|
|
// from being actually loaded and firing off events. |
41
|
|
|
$jobs = JobPoster::where('internal_only', false) |
42
|
|
|
->where('department_id', '!=', config('app.strategic_response_department_id')) |
43
|
|
|
->where('job_poster_status_id', JobPosterStatus::where('key', 'live')->first()->id) |
44
|
|
|
->with([ |
45
|
|
|
'department', |
46
|
|
|
'province', |
47
|
|
|
'job_term', |
48
|
|
|
]) |
49
|
|
|
->withCount([ |
50
|
|
|
'submitted_applications', |
51
|
|
|
]) |
52
|
|
|
->get(); |
53
|
|
|
|
54
|
|
|
$null_alert = $emergency_response |
55
|
|
|
? Lang::get('applicant/job_index.index.covid_null_alert') |
56
|
|
|
: Lang::get('applicant/job_index.index.null_alert'); |
57
|
|
|
return view('applicant/job_index', [ |
|
|
|
|
58
|
|
|
'job_index' => Lang::get('applicant/job_index'), |
59
|
|
|
'null_alert' => $null_alert, |
60
|
|
|
'jobs' => $jobs |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Display a listing of a manager's JobPosters. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Http\Response |
68
|
|
|
*/ |
69
|
|
|
public function managerIndex() |
70
|
|
|
{ |
71
|
|
|
$manager = Auth::user()->manager; |
72
|
|
|
|
73
|
|
|
$jobs = JobPoster::where('manager_id', $manager->id) |
74
|
|
|
->with('classification') |
75
|
|
|
->withCount('submitted_applications') |
76
|
|
|
->get(); |
77
|
|
|
|
78
|
|
|
foreach ($jobs as &$job) { |
79
|
|
|
// If the chosen language is null then set to english. |
80
|
|
|
$chosen_lang = $job->chosen_lang ?: 'en'; |
81
|
|
|
|
82
|
|
|
// Show chosen lang title if current title is empty. |
83
|
|
|
if (empty($job->title)) { |
84
|
|
|
$job->title = $job->getTranslation('title', $chosen_lang); |
85
|
|
|
$job->trans_required = true; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return view('manager/job_index', [ |
|
|
|
|
90
|
|
|
// Localization Strings. |
91
|
|
|
'jobs_l10n' => Lang::get('manager/job_index'), |
92
|
|
|
// Data. |
93
|
|
|
'jobs' => $jobs, |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Display a listing of a hr advisor's JobPosters. |
99
|
|
|
* |
100
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
101
|
|
|
* @return \Illuminate\Http\Response |
102
|
|
|
*/ |
103
|
|
|
public function hrIndex(Request $request) |
104
|
|
|
{ |
105
|
|
|
$hrAdvisor = $request->user()->hr_advisor; |
106
|
|
|
return view('hr_advisor/job_index', [ |
|
|
|
|
107
|
|
|
'jobs_l10n' => Lang::get('hr_advisor/job_index'), |
108
|
|
|
'hr_advisor_id' => $hrAdvisor->id |
109
|
|
|
]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Delete a draft Job Poster. |
114
|
|
|
* |
115
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
116
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
117
|
|
|
* @return \Illuminate\Http\Response |
118
|
|
|
*/ |
119
|
|
|
public function destroy(Request $request, JobPoster $jobPoster) |
120
|
|
|
{ |
121
|
|
|
$jobPoster->delete(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Display the specified job poster. |
126
|
|
|
* |
127
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
128
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
129
|
|
|
* @return \Illuminate\Http\Response |
130
|
|
|
*/ |
131
|
|
|
public function show(Request $request, JobPoster $jobPoster) |
132
|
|
|
{ |
133
|
|
|
$jobPoster->load([ |
134
|
|
|
'department', |
135
|
|
|
'criteria.skill.skill_type', |
136
|
|
|
'manager.team_culture', |
137
|
|
|
'manager.work_environment' |
138
|
|
|
]); |
139
|
|
|
|
140
|
|
|
$user = Auth::user(); |
141
|
|
|
|
142
|
|
|
// TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
143
|
|
|
$workplacePhotos = []; |
144
|
|
|
foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
145
|
|
|
$workplacePhotos[] = [ |
146
|
|
|
'description' => $photoCaption->description, |
147
|
|
|
'url' => '/images/user.png' |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
// TODO: replace route('manager.show',manager.id) in templates with link using slug. |
152
|
|
|
$essential = $jobPoster->criteria->filter( |
153
|
|
|
function ($value, $key) { |
154
|
|
|
return $value->criteria_type->name == 'essential'; |
155
|
|
|
} |
156
|
|
|
)->sortBy('id'); |
157
|
|
|
$asset = $jobPoster->criteria->filter( |
158
|
|
|
function ($value, $key) { |
159
|
|
|
return $value->criteria_type->name == 'asset'; |
160
|
|
|
} |
161
|
|
|
)->sortBy('id'); |
162
|
|
|
$criteria = [ |
163
|
|
|
'essential' => $essential, |
164
|
|
|
'asset' => $asset, |
165
|
|
|
]; |
166
|
|
|
|
167
|
|
|
$jobLang = Lang::get('applicant/job_post'); |
168
|
|
|
|
169
|
|
|
$skillsLang = Lang::get('common/skills'); |
170
|
|
|
|
171
|
|
|
$applyButton = []; |
172
|
|
|
if (WhichPortal::isManagerPortal()) { |
173
|
|
|
$applyButton = [ |
174
|
|
|
'href' => route('manager.jobs.edit', $jobPoster->id), |
|
|
|
|
175
|
|
|
'title' => $jobLang['apply']['edit_link_title'], |
176
|
|
|
'text' => $jobLang['apply']['edit_link_label'], |
177
|
|
|
]; |
178
|
|
|
} elseif (WhichPortal::isHrPortal()) { |
179
|
|
|
if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
180
|
|
|
$applyButton = [ |
181
|
|
|
'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
182
|
|
|
'title' => null, |
183
|
|
|
'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
184
|
|
|
]; |
185
|
|
|
} else { |
186
|
|
|
$applyButton = [ |
187
|
|
|
'href' => route('hr_advisor.jobs.index'), |
188
|
|
|
'title' => null, |
189
|
|
|
'text' => Lang::get('hr_advisor/job_index.title'), |
190
|
|
|
]; |
191
|
|
|
} |
192
|
|
|
} elseif (Auth::check() && $jobPoster->isOpen()) { |
193
|
|
|
$application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
194
|
|
|
->where('job_poster_id', $jobPoster->id)->first(); |
195
|
|
|
// If applicants job application is not draft anymore then link to application preview page. |
196
|
|
|
if ($application != null && $application->application_status->name != 'draft') { |
197
|
|
|
$applyButton = [ |
198
|
|
|
'href' => route('applications.show', $application->id), |
199
|
|
|
'title' => $jobLang['apply']['view_link_title'], |
200
|
|
|
'text' => $jobLang['apply']['view_link_label'], |
201
|
|
|
]; |
202
|
|
|
} else { |
203
|
|
|
$applyButton = [ |
204
|
|
|
'href' => route('job.application.edit.1', $jobPoster->id), |
205
|
|
|
'title' => $jobLang['apply']['apply_link_title'], |
206
|
|
|
'text' => $jobLang['apply']['apply_link_label'], |
207
|
|
|
]; |
208
|
|
|
} |
209
|
|
|
} elseif (Auth::guest() && $jobPoster->isOpen()) { |
210
|
|
|
$applyButton = [ |
211
|
|
|
'href' => route('job.application.edit.1', $jobPoster->id), |
212
|
|
|
'title' => $jobLang['apply']['login_link_title'], |
213
|
|
|
'text' => $jobLang['apply']['login_link_label'], |
214
|
|
|
]; |
215
|
|
|
} else { |
216
|
|
|
$applyButton = [ |
217
|
|
|
'href' => null, |
218
|
|
|
'title' => null, |
219
|
|
|
'text' => $jobLang['apply']['job_closed_label'], |
220
|
|
|
]; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
$jpb_release_date = strtotime('2019-08-21 16:18:17'); |
224
|
|
|
$job_created_at = strtotime($jobPoster->created_at); |
225
|
|
|
|
226
|
|
|
$custom_breadcrumbs = [ |
227
|
|
|
'home' => route('home'), |
228
|
|
|
'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
229
|
|
|
$jobPoster->title ?: 'job-title-missing' => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
230
|
|
|
'preview' => '', |
231
|
|
|
]; |
232
|
|
|
|
233
|
|
|
// If the poster is part of the Strategic Talent Response dept, use the talent stream template. |
234
|
|
|
// Else, If the job poster is created after the release of the JPB. |
235
|
|
|
// Then, render with updated poster template. |
236
|
|
|
// Else, render with old poster template. |
237
|
|
|
if ($jobPoster->isInStrategicResponseDepartment()) { |
238
|
|
|
return view( |
|
|
|
|
239
|
|
|
'applicant/strategic_response_job_post', |
240
|
|
|
[ |
241
|
|
|
'job_post' => $jobLang, |
242
|
|
|
'frequencies' => Lang::get('common/lookup/frequency'), |
243
|
|
|
'skill_template' => $skillsLang, |
244
|
|
|
'job' => $jobPoster, |
245
|
|
|
'manager' => $jobPoster->manager, |
246
|
|
|
'criteria' => $criteria, |
247
|
|
|
'apply_button' => $applyButton, |
248
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
249
|
|
|
] |
250
|
|
|
); |
251
|
|
|
} elseif ($job_created_at > $jpb_release_date) { |
252
|
|
|
// Updated job poster (JPB). |
253
|
|
|
return view( |
254
|
|
|
'applicant/jpb_job_post', |
255
|
|
|
[ |
256
|
|
|
'job_post' => $jobLang, |
257
|
|
|
'frequencies' => Lang::get('common/lookup/frequency'), |
258
|
|
|
'skill_template' => $skillsLang, |
259
|
|
|
'job' => $jobPoster, |
260
|
|
|
'manager' => $jobPoster->manager, |
261
|
|
|
'criteria' => $criteria, |
262
|
|
|
'apply_button' => $applyButton, |
263
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
264
|
|
|
'structured_data' => $this->buildStructuredData($jobPoster), |
265
|
|
|
] |
266
|
|
|
); |
267
|
|
|
} else { |
268
|
|
|
// Old job poster. |
269
|
|
|
return view( |
270
|
|
|
'applicant/job_post', |
271
|
|
|
[ |
272
|
|
|
'job_post' => $jobLang, |
273
|
|
|
'frequencies' => Lang::get('common/lookup/frequency'), |
274
|
|
|
'manager' => $jobPoster->manager, |
275
|
|
|
'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
276
|
|
|
'team_culture' => $jobPoster->manager->team_culture, |
277
|
|
|
'work_environment' => $jobPoster->manager->work_environment, |
278
|
|
|
'workplace_photos' => $workplacePhotos, |
279
|
|
|
'job' => $jobPoster, |
280
|
|
|
'criteria' => $criteria, |
281
|
|
|
'apply_button' => $applyButton, |
282
|
|
|
'skill_template' => Lang::get('common/skills'), |
283
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
284
|
|
|
] |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Display the form for editing an existing Job Poster |
291
|
|
|
* Only allows editing fields that don't appear on the react-built Job Poster Builder. |
292
|
|
|
* |
293
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
294
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
295
|
|
|
* @return \Illuminate\Http\Response |
296
|
|
|
*/ |
297
|
|
|
public function edit(Request $request, JobPoster $jobPoster) |
298
|
|
|
{ |
299
|
|
|
$manager = $jobPoster->manager; |
300
|
|
|
|
301
|
|
|
$defaultQuestionManager = new JobPosterDefaultQuestions(); |
302
|
|
|
$defaultQuestionManager->initializeQuestionsIfEmpty($jobPoster); |
303
|
|
|
|
304
|
|
|
return view( |
|
|
|
|
305
|
|
|
'manager/job_create', |
306
|
|
|
[ |
307
|
|
|
// Localization Strings. |
308
|
|
|
'job_l10n' => Lang::get('manager/job_edit'), |
309
|
|
|
// Data. |
310
|
|
|
'manager' => $manager, |
311
|
|
|
'job' => $jobPoster, |
312
|
|
|
'form_action_url' => route('admin.jobs.update', $jobPoster), |
|
|
|
|
313
|
|
|
] |
314
|
|
|
); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Create a blank job poster for the specified manager |
319
|
|
|
* |
320
|
|
|
* @param \App\Models\Manager $manager Incoming Manager object. |
321
|
|
|
* @return \Illuminate\Http\Response Job Create view |
322
|
|
|
*/ |
323
|
|
|
public function createAsManager(Manager $manager) |
324
|
|
|
{ |
325
|
|
|
$jobPoster = new JobPoster(); |
326
|
|
|
$jobPoster->manager_id = $manager->id; |
327
|
|
|
|
328
|
|
|
// Save manager-specific info to the job poster - equivalent to the intro step of the JPB. |
329
|
|
|
$divisionEn = $manager->getTranslation('division', 'en'); |
330
|
|
|
$divisionFr = $manager->getTranslation('division', 'fr'); |
331
|
|
|
$jobPoster->fill([ |
332
|
|
|
'department_id' => $manager->user->department_id, |
333
|
|
|
'division' => ['en' => $divisionEn], |
334
|
|
|
'division' => ['fr' => $divisionFr], |
335
|
|
|
]); |
336
|
|
|
|
337
|
|
|
$jobPoster->save(); |
338
|
|
|
|
339
|
|
|
return redirect()->route('manager.jobs.edit', $jobPoster->id); |
|
|
|
|
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Update a resource in storage |
344
|
|
|
* NOTE: Only saves fields that are not on the react-built Job Poster Builder |
345
|
|
|
* |
346
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
347
|
|
|
* @param \App\Models\JobPoster $jobPoster Optional Job Poster object. |
348
|
|
|
* @return \Illuminate\Http\Response |
349
|
|
|
*/ |
350
|
|
|
public function store(Request $request, JobPoster $jobPoster) |
351
|
|
|
{ |
352
|
|
|
// Don't allow edits for published Job Posters |
353
|
|
|
// Also check auth while we're at it. |
354
|
|
|
$this->authorize('update', $jobPoster); |
355
|
|
|
JobPosterValidator::validateUnpublished($jobPoster); |
356
|
|
|
|
357
|
|
|
$input = $request->input(); |
358
|
|
|
|
359
|
|
|
if ($jobPoster->manager_id == null) { |
360
|
|
|
$jobPoster->manager_id = $request->user()->manager->id; |
361
|
|
|
$jobPoster->save(); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
if ($request->input('question')) { |
365
|
|
|
$validator = Validator::make($request->input('question'), [ |
366
|
|
|
'*.question.*' => 'required|string', |
367
|
|
|
], [ |
368
|
|
|
'required' => Lang::get('validation.custom.job_poster_question.required'), |
369
|
|
|
'string' => Lang::get('validation.custom.job_poster_question.string') |
370
|
|
|
]); |
371
|
|
|
|
372
|
|
|
if ($validator->fails()) { |
373
|
|
|
$request->session()->flash('errors', $validator->errors()); |
374
|
|
|
return redirect(route('admin.jobs.edit', $jobPoster->id)); |
|
|
|
|
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
$this->fillAndSaveJobPosterQuestions($input, $jobPoster, true); |
379
|
|
|
|
380
|
|
|
return redirect(route('manager.jobs.preview', $jobPoster->id)); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Fill Job Poster's questions and save |
385
|
|
|
* |
386
|
|
|
* @param mixed[] $input Field values. |
387
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
388
|
|
|
* @param boolean $replace Remove existing relationships. |
389
|
|
|
* @return void |
390
|
|
|
*/ |
391
|
|
|
protected function fillAndSaveJobPosterQuestions(array $input, JobPoster $jobPoster, bool $replace): void |
392
|
|
|
{ |
393
|
|
|
if ($replace) { |
394
|
|
|
$jobPoster->job_poster_questions()->delete(); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
if (!array_key_exists('question', $input) || !is_array($input['question'])) { |
398
|
|
|
return; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
foreach ($input['question'] as $question) { |
402
|
|
|
$jobQuestion = new JobPosterQuestion(); |
403
|
|
|
$jobQuestion->job_poster_id = $jobPoster->id; |
404
|
|
|
$jobQuestion->fill( |
405
|
|
|
[ |
406
|
|
|
'question' => [ |
407
|
|
|
'en' => $question['question']['en'], |
408
|
|
|
'fr' => $question['question']['fr'] |
409
|
|
|
|
410
|
|
|
], |
411
|
|
|
'description' => [ |
412
|
|
|
'en' => $question['description']['en'], |
413
|
|
|
'fr' => $question['description']['fr'] |
414
|
|
|
] |
415
|
|
|
] |
416
|
|
|
); |
417
|
|
|
$jobPoster->save(); |
418
|
|
|
$jobQuestion->save(); |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Downloads a CSV file with the applicants who have applied to the job poster. |
424
|
|
|
* |
425
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
426
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
427
|
|
|
*/ |
428
|
|
|
protected function downloadApplicants(JobPoster $jobPoster) |
429
|
|
|
{ |
430
|
|
|
$tables = []; |
431
|
|
|
// The first row in the array represents the names of the columns in the spreadsheet. |
432
|
|
|
$tables[0] = ['Status', 'Applicant Name', 'Email', 'Language']; |
433
|
|
|
|
434
|
|
|
$application_status_id = ApplicationStatus::where('name', 'submitted')->first()->id; |
435
|
|
|
$applications = JobApplication::where('job_poster_id', $jobPoster->id) |
436
|
|
|
->where('application_status_id', $application_status_id) |
437
|
|
|
->get(); |
438
|
|
|
|
439
|
|
|
$index = 1; |
440
|
|
|
foreach ($applications as $application) { |
441
|
|
|
$status = ''; |
442
|
|
|
$username = $application->user_name; |
443
|
|
|
$user_email = $application->user_email; |
444
|
|
|
$language = strtoupper($application->preferred_language->name); |
445
|
|
|
// If the applicants veteran status name is NOT 'none' then set status to veteran. |
446
|
|
|
$non_veteran = VeteranStatus::where('name', 'none')->first()->id; |
447
|
|
|
if ($application->veteran_status_id != $non_veteran) { |
448
|
|
|
$status = 'Veteran'; |
449
|
|
|
} else { |
450
|
|
|
// Check if the applicant is a canadian citizen. |
451
|
|
|
$canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id; |
452
|
|
|
if ($application->citizenship_declaration->id == $canadian_citizen) { |
453
|
|
|
$status = 'Citizen'; |
454
|
|
|
} else { |
455
|
|
|
$status = 'Non-citizen'; |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
$tables[$index] = [$status, $username, $user_email, $language]; |
459
|
|
|
$index++; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
$filename = $jobPoster->id . '-' . 'applicants-data.csv'; |
463
|
|
|
|
464
|
|
|
// Open file. |
465
|
|
|
$file = fopen($filename, 'w'); |
466
|
|
|
// Iterate through tables and add each line to csv file. |
467
|
|
|
foreach ($tables as $line) { |
468
|
|
|
fputcsv($file, $line); |
|
|
|
|
469
|
|
|
} |
470
|
|
|
// Close open file. |
471
|
|
|
fclose($file); |
|
|
|
|
472
|
|
|
|
473
|
|
|
$headers = [ |
474
|
|
|
'Content-Type' => 'text/csv', |
475
|
|
|
'Content-Disposition' => 'attachment; filename=' . $filename, |
476
|
|
|
]; |
477
|
|
|
|
478
|
|
|
return Response::download($filename, $filename, $headers); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Build Job Poster's structured data |
483
|
|
|
* |
484
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster object. |
485
|
|
|
* @return array |
486
|
|
|
*/ |
487
|
|
|
protected function buildStructuredData(JobPoster $jobPoster) |
488
|
|
|
{ |
489
|
|
|
$gocLang = Lang::get('common/goc'); |
490
|
|
|
|
491
|
|
|
$jobLang = Lang::get('applicant/job_post'); |
492
|
|
|
|
493
|
|
|
$essential = $jobPoster->criteria->filter( |
494
|
|
|
function ($value) { |
495
|
|
|
return $value->criteria_type->name == 'essential'; |
496
|
|
|
} |
497
|
|
|
)->sortBy('id'); |
498
|
|
|
$asset = $jobPoster->criteria->filter( |
499
|
|
|
function ($value) { |
500
|
|
|
return $value->criteria_type->name == 'asset'; |
501
|
|
|
} |
502
|
|
|
)->sortBy('id'); |
503
|
|
|
|
504
|
|
|
$skillsArray = []; |
505
|
|
|
foreach ($essential as $criterion) { |
506
|
|
|
$skillsArray[] = [ |
507
|
|
|
'skill' => $criterion['skill']['name'], |
508
|
|
|
'level' => $criterion->level_name, |
509
|
|
|
]; |
510
|
|
|
} |
511
|
|
|
foreach ($asset as $criterion) { |
512
|
|
|
$skillsArray[] = [ |
513
|
|
|
'skill' => $criterion['skill']['name'], |
514
|
|
|
'level' => $criterion->level_name, |
515
|
|
|
]; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
$skillsString = ''; |
519
|
|
|
if (!empty($skillsArray)) { |
520
|
|
|
$lastSkill = end($skillsArray); |
521
|
|
|
foreach ($skillsArray as $skillItem) { |
522
|
|
|
$skillsString .= $skillItem['skill'].' - '.$skillItem['level'].($skillItem == $lastSkill ? '.' : ', '); |
523
|
|
|
} |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
$benefitsString = ''; |
527
|
|
|
if (is_array($jobLang['structured_data']['benefits'])) { |
528
|
|
|
foreach ($jobLang['structured_data']['benefits'] as $benefit) { |
529
|
|
|
$benefitsString .= $benefit.' '; |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
$tasksString = ''; |
534
|
|
|
if (is_array($jobPoster['job_poster_key_tasks'])) { |
535
|
|
|
$lastTask = end($jobPoster['job_poster_key_tasks']); |
|
|
|
|
536
|
|
|
foreach ($jobPoster['job_poster_key_tasks'] as $task) { |
537
|
|
|
$tasksString .= $task['description'].' '.($skillItem == $lastSkill ? '' : ' | '); |
|
|
|
|
538
|
|
|
} |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
$securityClearanceString = $jobLang['structured_data']['security_clearance_requirement_level'].': ' |
542
|
|
|
.$jobPoster['security_clearance']['value'].'. ' |
543
|
|
|
.$jobLang['structured_data']['security_clearance_requirement_description']; |
544
|
|
|
|
545
|
|
|
$structuredData = [ |
546
|
|
|
'@context' => 'https://schema.org', |
547
|
|
|
'@type' => 'JobPosting', |
548
|
|
|
'@id' => url()->current(), |
|
|
|
|
549
|
|
|
'url' => url('/'), |
550
|
|
|
'inLanguage' => app()->getLocale(), |
|
|
|
|
551
|
|
|
'applicantLocationRequirements' => [ |
552
|
|
|
'@type' => 'Country', |
553
|
|
|
'sameAs' => 'https://www.wikidata.org/wiki/Q16', |
554
|
|
|
'name' => 'Canada' |
555
|
|
|
], |
556
|
|
|
'applicationContact' => [ |
557
|
|
|
'@type' => 'ContactPoint', |
558
|
|
|
'email' => '[email protected]' |
559
|
|
|
], |
560
|
|
|
'baseSalary' => [ |
561
|
|
|
'@type' => 'MonetaryAmount', |
562
|
|
|
'currency' => 'CAD', |
563
|
|
|
'minValue' => $jobPoster['salary_min'], |
564
|
|
|
'maxValue' => $jobPoster['salary_max'], |
565
|
|
|
], |
566
|
|
|
'datePosted' => $jobPoster['open_date_time'], |
567
|
|
|
'employerOverview' => $jobLang['structured_data']['employer_overview'], |
568
|
|
|
'employmentType' => $jobLang['structured_data']['employment_type'], |
569
|
|
|
'estimatedSalary' => [ |
570
|
|
|
'@type' => 'MonetaryAmount', |
571
|
|
|
'currency' => 'CAD', |
572
|
|
|
'minValue' => $jobPoster['salary_min'], |
573
|
|
|
'maxValue' => $jobPoster['salary_max'] |
574
|
|
|
], |
575
|
|
|
'hiringOrganization' => [ |
576
|
|
|
'@type' => 'GovernmentOrganization', |
577
|
|
|
'name' => $jobPoster['manager']['user']['department']['name'], |
578
|
|
|
'parentOrganization' => [ |
579
|
|
|
'@type' => 'GovernmentOrganization', |
580
|
|
|
'name' => $jobLang['structured_data']['parent_organization'], |
581
|
|
|
'url' => $gocLang['logo_link'], |
582
|
|
|
'logo' => asset('/images/logo_canada_colour.png'), |
|
|
|
|
583
|
|
|
] |
584
|
|
|
], |
585
|
|
|
'industry' => $jobLang['structured_data']['industry'], |
586
|
|
|
'jobBenefits' => $benefitsString, |
587
|
|
|
'jobLocation' => [ |
588
|
|
|
'@type' => 'Place', |
589
|
|
|
'address' => [ |
590
|
|
|
'@type' => 'PostalAddress', |
591
|
|
|
'addressLocality' => $jobPoster['city'], |
592
|
|
|
'addressRegion' => $jobPoster['province']['value'], |
593
|
|
|
'addressCountry' => 'CA' |
594
|
|
|
] |
595
|
|
|
], |
596
|
|
|
'jobStartDate' => $jobPoster['start_date_time'], |
597
|
|
|
'qualifications' => $jobPoster['education'], |
598
|
|
|
'responsibilities' => $tasksString, |
599
|
|
|
'salaryCurrency' => 'CAD', |
600
|
|
|
'securityClearanceRequirement' => $securityClearanceString, |
601
|
|
|
'skills' => $skillsString, |
602
|
|
|
'specialCommitments' => $jobLang['structured_data']['special_commitments'], |
603
|
|
|
'title' => $jobPoster['title'], |
604
|
|
|
'totalJobOpenings' => '1', |
605
|
|
|
'validThrough' => $jobPoster['close_date_time'], |
606
|
|
|
'description' => $jobPoster['hire_impact'] ? nl2br($jobPoster['hire_impact']) : '', |
607
|
|
|
]; |
608
|
|
|
|
609
|
|
|
if ($jobPoster['remote_work_allowed'] == true) { |
610
|
|
|
$structuredData['jobLocationType'] = 'TELECOMMUTE'; |
611
|
|
|
}; |
612
|
|
|
|
613
|
|
|
return $structuredData; |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
|