|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Lang; |
|
6
|
|
|
use Illuminate\Support\Facades\Auth; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use App\Http\Controllers\Controller; |
|
9
|
|
|
use Carbon\Carbon; |
|
10
|
|
|
use App\Models\JobPoster; |
|
11
|
|
|
use App\Models\Lookup\JobTerm; |
|
12
|
|
|
use App\Models\Lookup\Province; |
|
13
|
|
|
use App\Models\Lookup\SecurityClearance; |
|
14
|
|
|
use App\Models\Lookup\LanguageRequirement; |
|
15
|
|
|
use App\Models\Lookup\CitizenshipDeclaration; |
|
16
|
|
|
use App\Models\Lookup\Department; |
|
17
|
|
|
use App\Models\Lookup\SkillLevel; |
|
18
|
|
|
use App\Models\Lookup\CriteriaType; |
|
19
|
|
|
use App\Models\Lookup\VeteranStatus; |
|
20
|
|
|
use App\Models\JobApplication; |
|
21
|
|
|
use App\Models\Criteria; |
|
22
|
|
|
use App\Models\Skill; |
|
23
|
|
|
use App\Models\JobPosterQuestion; |
|
24
|
|
|
use App\Models\JobPosterKeyTask; |
|
25
|
|
|
use Jenssegers\Date\Date; |
|
26
|
|
|
|
|
27
|
|
|
class JobController extends Controller |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Display a listing of JobPosters. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function index() |
|
35
|
|
|
{ |
|
36
|
|
|
$now = Carbon::now(); |
|
37
|
|
|
//Find published jobs that are currently open for applications |
|
38
|
|
|
$jobs = JobPoster::where('open_date_time', '<=', $now) |
|
39
|
|
|
->where('close_date_time', '>=', $now) |
|
40
|
|
|
->where('published', true) |
|
41
|
|
|
->get(); |
|
42
|
|
|
$jobs->load('manager.work_environment'); |
|
43
|
|
|
return view('applicant/job_index', ['job_index' => Lang::get('applicant/job_index'), |
|
|
|
|
|
|
44
|
|
|
'jobs' => $jobs]); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Display a listing of a manager's JobPosters. |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Illuminate\Http\Response |
|
51
|
|
|
*/ |
|
52
|
|
|
public function managerIndex() |
|
53
|
|
|
{ |
|
54
|
|
|
$manager = Auth::user()->manager; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$veteran_applications = []; |
|
57
|
|
|
$citizen_applications = []; |
|
58
|
|
|
$other_applications = []; |
|
59
|
|
|
|
|
60
|
|
|
foreach($manager->job_posters as $job) { |
|
|
|
|
|
|
61
|
|
|
$job->submitted_applications->load(['veteran_status', 'citizenship_declaration']); |
|
62
|
|
|
$veteran_applications[$job->id] = $job->submitted_applications->filter(function($application) { |
|
|
|
|
|
|
63
|
|
|
return $application->veteran_status->name !== "none" && |
|
64
|
|
|
$application->citizenship_declaration->name === "citizen"; |
|
65
|
|
|
}); |
|
|
|
|
|
|
66
|
|
|
$citizen_applications[$job->id] = $job->submitted_applications->filter(function($application) { |
|
|
|
|
|
|
67
|
|
|
return $application->veteran_status->name === "none" && |
|
68
|
|
|
$application->citizenship_declaration->name === "citizen"; |
|
69
|
|
|
}); |
|
|
|
|
|
|
70
|
|
|
$other_applications[$job->id] = $job->submitted_applications->filter(function($application) { |
|
|
|
|
|
|
71
|
|
|
return $application->citizenship_declaration->name !== "citizen"; |
|
72
|
|
|
}); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return view('manager/job_index', [ |
|
|
|
|
|
|
76
|
|
|
"manager_job_index" => [ |
|
77
|
|
|
"title" => "My Job Posts" |
|
78
|
|
|
], |
|
79
|
|
|
'jobs' => $manager->job_posters, |
|
80
|
|
|
'veteran_applications' => $veteran_applications, |
|
81
|
|
|
'citizen_applications' => $citizen_applications, |
|
82
|
|
|
'other_applications' => $other_applications, |
|
83
|
|
|
]); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Display the specified job poster. |
|
88
|
|
|
* |
|
89
|
|
|
* @param Request $request |
|
|
|
|
|
|
90
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
|
|
91
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
public function show(Request $request, JobPoster $jobPoster) |
|
94
|
|
|
{ |
|
95
|
|
|
//TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model |
|
96
|
|
|
$workplacePhotos = []; |
|
97
|
|
|
foreach($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
|
|
|
|
|
|
98
|
|
|
$workplacePhotos[] = [ |
|
99
|
|
|
'description' => $photoCaption->description, |
|
100
|
|
|
'url' => '/images/user.png' |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
//TODO: replace route('manager.show',manager.id) in templates with link using slug |
|
105
|
|
|
|
|
106
|
|
|
$criteria = [ |
|
107
|
|
|
'essential' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
|
|
108
|
|
|
return $value->criteria_type->name == 'essential'; |
|
109
|
|
|
}), |
|
|
|
|
|
|
110
|
|
|
'asset' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
|
|
111
|
|
|
return $value->criteria_type->name == 'asset'; |
|
112
|
|
|
}), |
|
|
|
|
|
|
113
|
|
|
]; |
|
114
|
|
|
return view('applicant/job_post', [ |
|
|
|
|
|
|
115
|
|
|
'job_post' =>Lang::get('applicant/job_post'), |
|
116
|
|
|
'manager' => $jobPoster->manager, |
|
117
|
|
|
'manager_profile_photo_url' => '/images/user.png', //TODO get real photo |
|
118
|
|
|
'team_culture' => $jobPoster->manager->team_culture, |
|
119
|
|
|
'work_environment' => $jobPoster->manager->work_environment, |
|
120
|
|
|
'workplace_photos' => $workplacePhotos, |
|
121
|
|
|
'job' => $jobPoster, |
|
122
|
|
|
'criteria' => $criteria, |
|
123
|
|
|
'skill_template' => Lang::get('common/skills'), |
|
124
|
|
|
]); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Display the form for creating a new Job Poster |
|
129
|
|
|
* @param Request $request [description] |
|
|
|
|
|
|
130
|
|
|
* @return \Illuminate\Http\Response A view |
|
|
|
|
|
|
131
|
|
|
*/ |
|
132
|
|
|
public function create(Request $request) { |
|
133
|
|
|
$manager = $request->user() ? $request->user()->manager : null; |
|
134
|
|
|
|
|
135
|
|
|
//No job details exist yet because we're creating a new one |
|
136
|
|
|
$job = []; |
|
137
|
|
|
|
|
138
|
|
|
return view('manager/job_create', [ |
|
|
|
|
|
|
139
|
|
|
'job_create' => Lang::get('manager/job_create'), |
|
140
|
|
|
'manager' => $manager, |
|
141
|
|
|
'provinces' => Province::all(), |
|
142
|
|
|
'departments' => Department::all(), |
|
143
|
|
|
'language_requirments' => LanguageRequirement::all(), |
|
144
|
|
|
'security_clearances' => SecurityClearance::all(), |
|
145
|
|
|
'job' => $job, |
|
146
|
|
|
'form_action_url' => route('manager.jobs.store'), |
|
147
|
|
|
'skills' => Skill::all(), |
|
148
|
|
|
'skill_levels' => SkillLevel::all(), |
|
149
|
|
|
'skill_template' => Lang::get('common/skills'), |
|
150
|
|
|
]); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Create a new resource in storage |
|
155
|
|
|
* @param Request $request |
|
|
|
|
|
|
156
|
|
|
* @return \Illuminate\Http\Response A redirect |
|
|
|
|
|
|
157
|
|
|
*/ |
|
158
|
|
|
public function store(Request $request) { |
|
159
|
|
|
|
|
160
|
|
|
$input = $request->input(); |
|
161
|
|
|
|
|
162
|
|
|
$job = new JobPoster(); |
|
163
|
|
|
$job->manager_id = $request->user()->manager->id; |
|
164
|
|
|
$job->published = ($input['submit'] == 'publish'); |
|
165
|
|
|
$job->fill([ |
|
|
|
|
|
|
166
|
|
|
'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id, |
|
167
|
|
|
'term_qty' => $input['term_qty'], |
|
168
|
|
|
'open_date_time' => new Date($input['open_date'].$input['open_time']), |
|
169
|
|
|
'close_date_time' => new Date($input['close_date'].$input['close_time']), |
|
170
|
|
|
'start_date_time' => new Date($input['start_date_time']), |
|
171
|
|
|
'department_id' => $input['department'], |
|
172
|
|
|
'province_id' => $input['province'], |
|
173
|
|
|
'salary_min' => $input['salary_min'], |
|
174
|
|
|
'salary_max' => $input['salary_max'], |
|
175
|
|
|
'noc' => $input['noc'], |
|
176
|
|
|
'classification' => $input['classification'], |
|
177
|
|
|
'security_clearance_id' => $input['security_clearance'], |
|
178
|
|
|
'language_requirement_id' => $input['language_requirement'], |
|
179
|
|
|
'remote_work_allowed' => $request->input('remote_work_allowed', false), |
|
|
|
|
|
|
180
|
|
|
'en' => [ |
|
181
|
|
|
'city' => $input['city'], |
|
182
|
|
|
'title' => $input['title']['en'], |
|
183
|
|
|
'impact' => $input['impact']['en'], |
|
184
|
|
|
'branch' => $input['branch']['en'], |
|
185
|
|
|
'division' => $input['division']['en'], |
|
186
|
|
|
'education' => $input['education']['en'], |
|
187
|
|
|
], |
|
188
|
|
|
'fr' => [ |
|
189
|
|
|
'city' => $input['city'], |
|
190
|
|
|
'title' => $input['title']['fr'], |
|
191
|
|
|
'impact' => $input['impact']['fr'], |
|
192
|
|
|
'branch' => $input['branch']['fr'], |
|
193
|
|
|
'division' => $input['division']['fr'], |
|
194
|
|
|
'education' => $input['education']['fr'], |
|
195
|
|
|
], |
|
196
|
|
|
]); |
|
|
|
|
|
|
197
|
|
|
$job->save(); |
|
198
|
|
|
|
|
199
|
|
|
if (isset($input['task'])) { |
|
200
|
|
|
foreach($input['task'] as $task) { |
|
|
|
|
|
|
201
|
|
|
$jobPosterTask = new JobPosterKeyTask(); |
|
202
|
|
|
$jobPosterTask->job_poster_id = $job->id; |
|
203
|
|
|
$jobPosterTask->fill([ |
|
|
|
|
|
|
204
|
|
|
'en' => [ |
|
205
|
|
|
'description' => $task['en'] |
|
206
|
|
|
], |
|
207
|
|
|
'fr' => [ |
|
208
|
|
|
'description' => $task['fr'] |
|
209
|
|
|
] |
|
210
|
|
|
]); |
|
|
|
|
|
|
211
|
|
|
$jobPosterTask->save(); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
if (isset($input['question'])) { |
|
216
|
|
|
foreach($input['question'] as $question) { |
|
|
|
|
|
|
217
|
|
|
$jobQuestion = new JobPosterQuestion(); |
|
218
|
|
|
$jobQuestion->job_poster_id = $job->id; |
|
219
|
|
|
$jobQuestion->fill([ |
|
|
|
|
|
|
220
|
|
|
'en'=> [ |
|
221
|
|
|
'question' => $question['question']['en'], |
|
222
|
|
|
'description' => $question['description']['en'] |
|
223
|
|
|
], |
|
224
|
|
|
'fr'=> [ |
|
225
|
|
|
'question' => $question['question']['fr'], |
|
226
|
|
|
'description' => $question['description']['fr'] |
|
227
|
|
|
] |
|
228
|
|
|
]); |
|
|
|
|
|
|
229
|
|
|
$jobQuestion->save(); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
$criteria = $input['criteria']; |
|
234
|
|
|
|
|
235
|
|
|
//Save new criteria |
|
236
|
|
|
if (isset($criteria['new'])) { |
|
237
|
|
|
foreach($criteria['new'] as $criteriaType => $criteriaTypeInput) { |
|
|
|
|
|
|
238
|
|
|
foreach($criteriaTypeInput as $skillType => $skillTypeInput) { |
|
|
|
|
|
|
239
|
|
|
foreach($skillTypeInput as $criteriaInput) { |
|
|
|
|
|
|
240
|
|
|
$criteria = new Criteria(); |
|
241
|
|
|
$criteria->job_poster_id = $job->id; |
|
242
|
|
|
$criteria->fill([ |
|
|
|
|
|
|
243
|
|
|
'criteria_type_id' => CriteriaType::where('name', $criteriaType)->firstOrFail()->id, |
|
244
|
|
|
'skill_id' => $criteriaInput['skill_id'], |
|
245
|
|
|
'skill_level_id' => $criteriaInput['skill_level_id'], |
|
246
|
|
|
'en' => [ |
|
247
|
|
|
'description' => $criteriaInput['description']['en'], |
|
248
|
|
|
], |
|
249
|
|
|
'fr' => [ |
|
250
|
|
|
'description' => $criteriaInput['description']['fr'], |
|
251
|
|
|
], |
|
252
|
|
|
]); |
|
|
|
|
|
|
253
|
|
|
$criteria->save(); |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
return redirect( route('manager.jobs.index') ); |
|
|
|
|
|
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|