1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Lang; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use App\Models\Lookup\ApplicantProfileQuestion; |
8
|
|
|
use App\Models\Applicant; |
9
|
|
|
use App\Models\ApplicantProfileAnswer; |
10
|
|
|
use App\Http\Controllers\Controller; |
11
|
|
|
use App\Models\JobPoster; |
12
|
|
|
use App\Services\Validation\Requests\UpdateApplicationProfileValidator; |
13
|
|
|
use App\Services\Validation\Rules\LinkedInUrlRule; |
14
|
|
|
use App\Services\Validation\Rules\TwitterHandleRule; |
15
|
|
|
use Facades\App\Services\WhichPortal; |
16
|
|
|
|
17
|
|
|
class ApplicantProfileController extends Controller |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $answerFormInputName = 'applicantProfileAnswer'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Display the specified resource. |
26
|
|
|
* |
27
|
|
|
* @param \App\Models\Applicant $applicant Incoming Applicant object. |
28
|
|
|
* @return \Illuminate\Http\Response |
29
|
|
|
*/ |
30
|
|
|
public function profile(Applicant $applicant) |
31
|
|
|
{ |
32
|
|
|
$custom_breadcrumbs = [ |
33
|
|
|
'home' => route('home'), |
|
|
|
|
34
|
|
|
$applicant->user->full_name => '', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
return view( |
|
|
|
|
38
|
|
|
'manager/applicant_profile', |
39
|
|
|
[ |
40
|
|
|
// Localized strings. |
41
|
|
|
'profile' => Lang::get('manager/applicant_profile'), // Change text |
42
|
|
|
// Applicant data. |
43
|
|
|
'applicant' => $applicant, |
44
|
|
|
'profile_photo_url' => '/images/user.png', // TODO: get real photos. |
45
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Display the specified resource. |
52
|
|
|
* |
53
|
|
|
* @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
54
|
|
|
* @param \App\Models\Applicant $applicant Incoming Applicant object. |
55
|
|
|
* @return \Illuminate\Http\Response |
56
|
|
|
*/ |
57
|
|
|
public function showWithJob(JobPoster $jobPoster, Applicant $applicant) |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
// Viewing this page is only possible if the applicant has applied to the specified job. |
61
|
|
|
if ($jobPoster->submitted_applications->firstWhere('applicant_id', '==', $applicant->id) === null) { |
62
|
|
|
return abort(404); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
$custom_breadcrumbs = [ |
65
|
|
|
'home' => route('home'), |
|
|
|
|
66
|
|
|
'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
67
|
|
|
$jobPoster->title => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
68
|
|
|
'applications' => route(WhichPortal::prefixRoute('jobs.applications'), $jobPoster), |
69
|
|
|
'profile' => '', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
return view( |
|
|
|
|
73
|
|
|
'manager/applicant_profile', |
74
|
|
|
[ |
75
|
|
|
// Localized strings. |
76
|
|
|
'profile' => Lang::get('manager/applicant_profile'), // Change text |
77
|
|
|
// Applicant data. |
78
|
|
|
'applicant' => $applicant, |
79
|
|
|
'profile_photo_url' => '/images/user.png', // TODO: get real photos. |
80
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
81
|
|
|
] |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Show the form for editing the logged-in applicant's profile |
87
|
|
|
* |
88
|
|
|
* @param \Illuminate\Http\Request $request Incoming request. |
89
|
|
|
* @return \Illuminate\Http\Response |
90
|
|
|
*/ |
91
|
|
|
public function editAuthenticated(Request $request) |
92
|
|
|
{ |
93
|
|
|
$applicant = $request->user()->applicant; |
94
|
|
|
return redirect(route('profile.about.edit', $applicant)); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Show the form for editing an applicant profile |
99
|
|
|
* |
100
|
|
|
* @param \Illuminate\Http\Request $request Incoming request object. |
101
|
|
|
* @param \App\Models\Applicant $applicant Applicant to view and edit. |
102
|
|
|
* @return \Illuminate\Http\Response |
103
|
|
|
*/ |
104
|
|
|
public function edit(Request $request, Applicant $applicant) |
105
|
|
|
{ |
106
|
|
|
$profileQuestions = ApplicantProfileQuestion::all(); |
107
|
|
|
|
108
|
|
|
$profileText = Lang::get('applicant/applicant_profile'); |
109
|
|
|
|
110
|
|
|
$profileQuestionForms = []; |
111
|
|
|
foreach ($profileQuestions as $question) { |
112
|
|
|
$answerObj = $applicant->applicant_profile_answers |
113
|
|
|
->where('applicant_profile_question_id', $question->id)->first(); |
114
|
|
|
$answer = $answerObj ? $answerObj->answer : null; |
115
|
|
|
|
116
|
|
|
$formValues = [ |
117
|
|
|
'id' => $question->id, |
118
|
|
|
'question' => $question->question, |
119
|
|
|
'description' => $question->description, |
120
|
|
|
'answer' => $answer, |
121
|
|
|
'answer_label' => $profileText['about_section']['answer_label'], |
122
|
|
|
'input_name' => $this->answerFormInputName . '[' . $question->id . ']' |
123
|
|
|
]; |
124
|
|
|
array_push($profileQuestionForms, $formValues); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$linkedInUrlPattern = LinkedInUrlRule::PATTERN; |
128
|
|
|
$twitterHandlePattern = TwitterHandleRule::PATTERN; |
129
|
|
|
|
130
|
|
|
$custom_breadcrumbs = [ |
131
|
|
|
'home' => route('home'), |
|
|
|
|
132
|
|
|
'profile' => '', |
133
|
|
|
]; |
134
|
|
|
|
135
|
|
|
return view( |
|
|
|
|
136
|
|
|
'applicant/profile_01_about', |
137
|
|
|
[ |
138
|
|
|
// Localized strings. |
139
|
|
|
'profile' => $profileText, |
140
|
|
|
// Applicant data. |
141
|
|
|
'applicant' => $applicant, |
142
|
|
|
'profile_photo_url' => '/images/user.png', // TODO: get real photos. |
143
|
|
|
// Applicant Profile Questions. |
144
|
|
|
'applicant_profile_questions' => $profileQuestionForms, |
145
|
|
|
// Update route. |
146
|
|
|
'form_submit_action' => route('profile.about.update', $applicant), |
147
|
|
|
'linkedInUrlPattern' => $linkedInUrlPattern, |
148
|
|
|
'twitterHandlePattern' => $twitterHandlePattern, |
149
|
|
|
'custom_breadcrumbs' => $custom_breadcrumbs, |
150
|
|
|
] |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Update the specified resource in storage. |
156
|
|
|
* |
157
|
|
|
* @param \Illuminate\Http\Request $request Incoming request. |
158
|
|
|
* @param \App\Models\Applicant $applicant Applicant object to update. |
159
|
|
|
* @return \Illuminate\Http\Response |
160
|
|
|
*/ |
161
|
|
|
public function update(Request $request, Applicant $applicant) |
162
|
|
|
{ |
163
|
|
|
$questions = ApplicantProfileQuestion::all(); |
164
|
|
|
|
165
|
|
|
$validator = new UpdateApplicationProfileValidator($applicant); |
166
|
|
|
$validator->validate($request->all()); |
167
|
|
|
|
168
|
|
|
foreach ($questions as $question) { |
169
|
|
|
$answerName = $this->answerFormInputName . '.' . $question->id; |
170
|
|
|
if ($request->has($answerName)) { |
171
|
|
|
$answer = ApplicantProfileAnswer::where( |
172
|
|
|
[ |
173
|
|
|
'applicant_id' => $applicant->id, |
174
|
|
|
'applicant_profile_question_id' => $question->id |
175
|
|
|
] |
176
|
|
|
)->first(); |
177
|
|
|
if ($answer == null) { |
178
|
|
|
$answer = new ApplicantProfileAnswer(); |
179
|
|
|
$answer->applicant_id = $applicant->id; |
180
|
|
|
$answer->applicant_profile_question_id = $question->id; |
181
|
|
|
} |
182
|
|
|
$answer->answer = $request->input($answerName); |
183
|
|
|
$answer->save(); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$input = $request->input(); |
188
|
|
|
$applicant->fill( |
189
|
|
|
[ |
190
|
|
|
'tagline' => $input['tagline'], |
191
|
|
|
'twitter_username' => $input['twitter_username'], |
192
|
|
|
'linkedin_url' => $input['linkedin_url'], |
193
|
|
|
] |
194
|
|
|
); |
195
|
|
|
$applicant->save(); |
196
|
|
|
|
197
|
|
|
return redirect()->route('profile.about.edit', $applicant); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|