1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Support\Facades\Lang; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use App\Models\JobApplication; |
9
|
|
|
use App\Models\JobApplicationVersion; |
10
|
|
|
use App\Models\JobPoster; |
11
|
|
|
use App\Models\Skill; |
12
|
|
|
use App\Models\Lookup\ReviewStatus; |
13
|
|
|
use Facades\App\Services\WhichPortal; |
14
|
|
|
|
15
|
|
|
class ApplicationController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Display a listing of the resource. |
19
|
|
|
* |
20
|
|
|
* @return \Illuminate\Http\Response |
21
|
|
|
*/ |
22
|
|
|
public function index() |
23
|
|
|
{ |
24
|
|
|
$applications = Auth::user()->applicant->job_applications->load('application_status'); |
25
|
|
|
return view( |
|
|
|
|
26
|
|
|
'applicant/application_index', |
27
|
|
|
[ |
28
|
|
|
'application_index' => Lang::get('applicant/application_index'), |
29
|
|
|
'applications' => $applications, |
30
|
|
|
'manager_profile_photo' => '/images/user.png', // TODO: get real photo. |
31
|
|
|
] |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Display the application preview. |
37
|
|
|
* |
38
|
|
|
* @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
39
|
|
|
* @param \App\Models\JobApplication $application Incoming Application object. |
40
|
|
|
* @return \Illuminate\Http\Response |
41
|
|
|
*/ |
42
|
|
|
public function show(JobApplication $application) |
43
|
|
|
{ |
44
|
|
|
// If the application is version two then show the version two application review page. |
45
|
|
|
if ($application->version_id !== null && $application->version_id == 2) { |
46
|
|
|
return $this->showVersionTwo($application); |
47
|
|
|
} |
48
|
|
|
return $this->showVersionOne($application); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Display the application preview with the review toolbar. |
53
|
|
|
* |
54
|
|
|
* @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
55
|
|
|
* @param \App\Models\JobApplication $application Incoming Application object. |
56
|
|
|
* @return \Illuminate\Http\Response |
57
|
|
|
*/ |
58
|
|
|
public function showWithToolbar(JobPoster $jobPoster, JobApplication $application) |
59
|
|
|
{ |
60
|
|
|
if ($jobPoster->job_applications->contains($application)) { |
61
|
|
|
return $this->show($application); |
62
|
|
|
} else { |
63
|
|
|
return abort(404); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Display specified application (version 2) |
69
|
|
|
* |
70
|
|
|
* @param \App\Models\JobApplication $application Incoming Application object. |
71
|
|
|
* @return \Illuminate\Http\Response |
72
|
|
|
*/ |
73
|
|
|
public function showVersionTwo(JobApplication $application) |
74
|
|
|
{ |
75
|
|
|
if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) { |
76
|
|
|
return view( |
|
|
|
|
77
|
|
|
'manager/application_timeline_review', |
78
|
|
|
[ |
79
|
|
|
'applicant' => $application->applicant, |
80
|
|
|
'application' => $application, |
81
|
|
|
'application_template' => Lang::get('applicant/application_template'), |
82
|
|
|
'job_id' => $application->job_poster_id, |
83
|
|
|
'review_statuses' => ReviewStatus::all(), |
84
|
|
|
'is_hr_portal' => WhichPortal::isHrPortal(), |
85
|
|
|
] |
86
|
|
|
); |
87
|
|
|
} else { |
88
|
|
|
return view( |
89
|
|
|
'applicant/application_timeline_preview', |
90
|
|
|
[ |
91
|
|
|
'applicant' => $application->applicant, |
92
|
|
|
'application' => $application, |
93
|
|
|
'application_template' => Lang::get('applicant/application_template'), |
94
|
|
|
'job_id' => $application->job_poster_id, |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Display specified application (version 1) |
102
|
|
|
* |
103
|
|
|
* @param \App\Models\JobApplication $application Incoming Application object. |
104
|
|
|
* @return \Illuminate\Http\Response |
105
|
|
|
*/ |
106
|
|
|
public function showVersionOne(JobApplication $application) |
107
|
|
|
{ |
108
|
|
|
$response_poster = false; |
109
|
|
|
$show_review = true; |
110
|
|
|
$jobPoster = $application->job_poster; |
111
|
|
|
|
112
|
|
|
$essential_criteria = $jobPoster->criteria->filter(function ($value, $key) { |
|
|
|
|
113
|
|
|
return $value->criteria_type->name == 'essential' |
114
|
|
|
&& $value->skill->skill_type->name == 'hard'; |
115
|
|
|
}); |
116
|
|
|
$asset_criteria = $jobPoster->criteria->filter(function ($value, $key) { |
|
|
|
|
117
|
|
|
return $value->criteria_type->name == 'asset' |
118
|
|
|
&& $value->skill->skill_type->name == 'hard'; |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
// Display slightly different views on different portals. |
122
|
|
|
$view = WhichPortal::isManagerPortal() || WhichPortal::isHrPortal() ? |
123
|
|
|
'manager/application_post' : 'applicant/application_preview'; |
124
|
|
|
|
125
|
|
|
$application_view = 'common/application/view/view_layout'; |
126
|
|
|
|
127
|
|
|
if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) { |
128
|
|
|
// Load things required for review component. |
129
|
|
|
$application->load(['veteran_status', 'citizenship_declaration', 'application_review', 'applicant.user']); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
// If the application status is draft then get data through the applicant model. |
134
|
|
|
// Else, grab the data from the application itself. |
135
|
|
|
if ($application->isDraft()) { |
136
|
|
|
$source = $application->applicant; |
137
|
|
|
$show_review = false; |
138
|
|
|
} else { |
139
|
|
|
$source = $application; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$degrees = $source->degrees; |
143
|
|
|
$courses = $source->courses; |
144
|
|
|
$work_experiences = $source->work_experiences; |
145
|
|
|
$skill_declarations = $source->skill_declarations; |
146
|
|
|
$references = $source->references; |
147
|
|
|
$work_samples = $source->work_samples; |
148
|
|
|
|
149
|
|
|
$custom_breadcrumbs = [ |
150
|
|
|
'home' => route('home'), |
|
|
|
|
151
|
|
|
'applications' => route('applications.index'), |
152
|
|
|
'application' => '', |
153
|
|
|
]; |
154
|
|
|
|
155
|
|
|
if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) { |
156
|
|
|
$custom_breadcrumbs = [ |
157
|
|
|
'home' => route('home'), |
158
|
|
|
'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
159
|
|
|
$jobPoster->title => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
160
|
|
|
'applications' => route(WhichPortal::prefixRoute('jobs.applications'), $jobPoster), |
161
|
|
|
'application' => '', |
162
|
|
|
]; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return view( |
|
|
|
|
166
|
|
|
$view, |
167
|
|
|
[ |
168
|
|
|
'application_view_template' => $application_view, |
169
|
|
|
// Localized strings. |
170
|
|
|
'post' => Lang::get('manager/application_post'), // Change text |
171
|
|
|
'is_manager_view' => WhichPortal::isManagerPortal(), |
172
|
|
|
'is_hr_portal' => WhichPortal::isHrPortal(), |
173
|
|
|
// Application Template Data. |
174
|
|
|
'application_template' => Lang::get('applicant/application_template'), |
175
|
|
|
'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'), |
176
|
|
|
'veteran_status_template' => Lang::get('common/veteran_status'), |
177
|
|
|
// Job Data. |
178
|
|
|
'job' => $jobPoster, |
179
|
|
|
// Skills Data. |
180
|
|
|
'skills' => Skill::all(), |
181
|
|
|
'skill_template' => Lang::get('common/skills'), |
182
|
|
|
'reference_template' => Lang::get('common/references'), |
183
|
|
|
'sample_template' => Lang::get('common/work_samples'), |
184
|
|
|
'essential_criteria' => $essential_criteria, |
185
|
|
|
'asset_criteria' => $asset_criteria, |
186
|
|
|
// Applicant Data. |
187
|
|
|
'applicant' => $application->applicant, |
188
|
|
|
'job_application' => $application, |
189
|
|
|
'degrees' => $degrees, |
190
|
|
|
'courses' => $courses, |
191
|
|
|
'work_experiences' => $work_experiences, |
192
|
|
|
'skill_declarations' => $skill_declarations, |
193
|
|
|
'references' => $references, |
194
|
|
|
'work_samples' => $work_samples, |
195
|
|
|
'review_statuses' => ReviewStatus::all(), |
196
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
197
|
|
|
'response_poster' => $response_poster, |
198
|
|
|
'show_review' => $show_review, |
199
|
|
|
] |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Delete the particular resource from storage. |
205
|
|
|
* |
206
|
|
|
* @param \Illuminate\Http\Request $request Incoming Request object. |
207
|
|
|
* @param \App\Models\JobApplication $application Incoming Application object. |
208
|
|
|
* @return \Illuminate\Http\Response |
209
|
|
|
*/ |
210
|
|
|
public function destroy(Request $request, JobApplication $application) |
211
|
|
|
{ |
212
|
|
|
$this->authorize('delete', $application); |
213
|
|
|
|
214
|
|
|
$application->delete(); |
215
|
|
|
|
216
|
|
|
if ($request->ajax()) { |
217
|
|
|
return [ |
218
|
|
|
'message' => 'Application deleted' |
219
|
|
|
]; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return redirect()->back(); |
|
|
|
|
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|