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 Barryvdh\Debugbar\Facade as Debugbar; |
9
|
|
|
use App\Http\Controllers\Controller; |
10
|
|
|
use Carbon\Carbon; |
11
|
|
|
use App\Models\JobPoster; |
12
|
|
|
use App\Models\Lookup\JobTerm; |
13
|
|
|
use App\Models\Lookup\Province; |
14
|
|
|
use App\Models\Lookup\SecurityClearance; |
15
|
|
|
use App\Models\Lookup\LanguageRequirement; |
16
|
|
|
use App\Models\Lookup\Department; |
17
|
|
|
use App\Models\JobPosterQuestion; |
18
|
|
|
use App\Models\JobPosterKeyTask; |
19
|
|
|
use Jenssegers\Date\Date; |
20
|
|
|
|
21
|
|
|
class JobController extends Controller |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Display a listing of JobPosters. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\Response |
27
|
|
|
*/ |
28
|
|
|
public function index() |
29
|
|
|
{ |
30
|
|
|
$now = Carbon::now(); |
31
|
|
|
//Find jobs that are currently open for applications |
32
|
|
|
$jobs = JobPoster::where('open_date_time', '<=', $now)->where('close_date_time', '>=', $now)->get(); |
33
|
|
|
return view('applicant/job_index', ['job_index' => Lang::get('applicant/job_index'), |
|
|
|
|
34
|
|
|
'jobs' => $jobs]); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Display the specified job poster. |
39
|
|
|
* |
40
|
|
|
* @param Request $request |
|
|
|
|
41
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
42
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function show(Request $request, JobPoster $jobPoster) |
45
|
|
|
{ |
46
|
|
|
//TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model |
47
|
|
|
$workplacePhotos = []; |
48
|
|
|
foreach($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
|
|
|
|
49
|
|
|
$workplacePhotos[] = [ |
50
|
|
|
'description' => $photoCaption->description, |
51
|
|
|
'url' => '/images/user.png' |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
//TODO: replace route('manager.show',manager.id) in templates with link using slug |
56
|
|
|
|
57
|
|
|
$criteria = [ |
58
|
|
|
'essential' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
59
|
|
|
return $value->criteria_type->name == 'essential'; |
60
|
|
|
}), |
|
|
|
|
61
|
|
|
'asset' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
62
|
|
|
return $value->criteria_type->name == 'asset'; |
63
|
|
|
}) |
|
|
|
|
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
return view('applicant/job_post', [ |
|
|
|
|
67
|
|
|
'job_post' =>Lang::get('applicant/job_post'), |
68
|
|
|
'manager' => $jobPoster->manager, |
69
|
|
|
'manager_profile_photo_url' => '/images/user.png', //TODO get real photo |
70
|
|
|
'team_culture' => $jobPoster->manager->team_culture, |
71
|
|
|
'work_environment' => $jobPoster->manager->work_environment, |
72
|
|
|
'workplace_photos' => $workplacePhotos, |
73
|
|
|
'job' => $jobPoster, |
74
|
|
|
'criteria' => $criteria, |
75
|
|
|
]); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Display the form for creating a new Job Poster |
80
|
|
|
* @param Request $request [description] |
|
|
|
|
81
|
|
|
* @return \Illuminate\Http\Response A view |
|
|
|
|
82
|
|
|
*/ |
83
|
|
|
public function create(Request $request) { |
|
|
|
|
84
|
|
|
$manager = $request->user() ? $request->user()->manager : null; |
85
|
|
|
|
86
|
|
|
//No job details exist yet because we're creating a new one |
87
|
|
|
$job = []; |
88
|
|
|
|
89
|
|
|
return view('manager/job_create', [ |
|
|
|
|
90
|
|
|
'manager_job_create' => Lang::get('manager/job_create'), |
91
|
|
|
'manager' => $manager, |
92
|
|
|
'provinces' => Province::all(), |
93
|
|
|
'departments' => Department::all(), |
94
|
|
|
'language_requirments' => LanguageRequirement::all(), |
95
|
|
|
'security_clearances' => SecurityClearance::all(), |
96
|
|
|
'job' => $job, |
97
|
|
|
'form_action_url' => route('manager.jobs.store') |
98
|
|
|
]); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Create a new resource in storage |
103
|
|
|
* @param Request $request |
|
|
|
|
104
|
|
|
* @return \Illuminate\Http\Response A redirect |
|
|
|
|
105
|
|
|
*/ |
106
|
|
|
public function store(Request $request) { |
|
|
|
|
107
|
|
|
|
108
|
|
|
$input = $request->input(); |
109
|
|
|
|
110
|
|
|
$job = new JobPoster(); |
111
|
|
|
$job->manager_id = $request->user()->manager->id; |
112
|
|
|
$job->published = ($input['submit'] == 'publish'); |
113
|
|
|
$job->fill([ |
|
|
|
|
114
|
|
|
'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id, |
115
|
|
|
'term_qty' => $input['term_qty'], |
116
|
|
|
'open_date_time' => new Date($input['open_date_time']), |
117
|
|
|
'close_date_time' => new Date($input['close_date_time']), |
118
|
|
|
'start_date_time' => new Date($input['start_date_time']), |
119
|
|
|
'department_id' => $input['department'], |
120
|
|
|
'province_id' => $input['province'], |
121
|
|
|
'salary_min' => $input['salary_min'], |
122
|
|
|
'salary_max' => $input['salary_max'], |
123
|
|
|
'noc' => $input['noc'], |
124
|
|
|
'classification' => $input['classification'], |
125
|
|
|
'security_clearance_id' => $input['security_clearance'], |
126
|
|
|
'language_requirement_id' => $input['language_requirement'], |
127
|
|
|
'en' => [ |
128
|
|
|
'city' => $input['city'], |
129
|
|
|
'title' => $input['title']['en'], |
130
|
|
|
'impact' => $input['impact']['en'], |
131
|
|
|
'branch' => $input['branch']['en'], |
132
|
|
|
'division' => $input['division']['en'] |
133
|
|
|
], |
134
|
|
|
'fr' => [ |
135
|
|
|
'city' => $input['city'], |
136
|
|
|
'title' => $input['title']['fr'], |
137
|
|
|
'impact' => $input['impact']['fr'], |
138
|
|
|
'branch' => $input['branch']['fr'], |
139
|
|
|
'division' => $input['division']['fr'] |
140
|
|
|
], |
141
|
|
|
]); |
|
|
|
|
142
|
|
|
$job->save(); |
143
|
|
|
|
144
|
|
|
if (isset($input['task'])) { |
145
|
|
|
foreach($input['task'] as $task) { |
|
|
|
|
146
|
|
|
$jobPosterTask = new JobPosterKeyTask(); |
147
|
|
|
$jobPosterTask->job_poster_id = $job->id; |
148
|
|
|
$jobPosterTask->fill([ |
|
|
|
|
149
|
|
|
'en' => [ |
150
|
|
|
'description' => $task['en'] |
151
|
|
|
], |
152
|
|
|
'fr' => [ |
153
|
|
|
'description' => $task['fr'] |
154
|
|
|
] |
155
|
|
|
]); |
|
|
|
|
156
|
|
|
$jobPosterTask->save(); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (isset($input['question'])) { |
161
|
|
|
foreach($input['question'] as $question) { |
|
|
|
|
162
|
|
|
$jobQuestion = new JobPosterQuestion(); |
163
|
|
|
$jobQuestion->job_poster_id = $job->id; |
164
|
|
|
$jobQuestion->fill([ |
|
|
|
|
165
|
|
|
'en'=> [ |
166
|
|
|
'question' => $question['question']['en'], |
167
|
|
|
'description' => $question['description']['en'] |
168
|
|
|
], |
169
|
|
|
'fr'=> [ |
170
|
|
|
'question' => $question['question']['fr'], |
171
|
|
|
'description' => $question['description']['fr'] |
172
|
|
|
] |
173
|
|
|
]); |
|
|
|
|
174
|
|
|
$jobQuestion->save(); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
return redirect( route('manager.jobs.index') ); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|