1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Gate; |
6
|
|
|
use App\Models\JobPoster; |
7
|
|
|
use App\Models\Criteria; |
8
|
|
|
use App\Models\Assessment; |
9
|
|
|
use App\Models\RatingGuideQuestion; |
10
|
|
|
use App\Models\RatingGuideAnswer; |
11
|
|
|
use App\Models\Lookup\AssessmentType; |
12
|
|
|
use Facades\App\Services\WhichPortal; |
13
|
|
|
use Illuminate\Support\Facades\Auth; |
14
|
|
|
use Illuminate\Support\Facades\Lang; |
15
|
|
|
|
16
|
|
|
class AssessmentPlanController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Return all the criteria, Assessments, Assessments, |
20
|
|
|
* RatingGuideQuestions, and RatingGuideAnswers associated with a job, |
21
|
|
|
* as an array. |
22
|
|
|
* |
23
|
|
|
* @param \App\Models\JobPoster $jobPoster Job Poster to retrieve assessment plan for. |
24
|
|
|
* @return mixed[] |
25
|
|
|
*/ |
26
|
|
|
public function getForJob(JobPoster $jobPoster) |
27
|
|
|
{ |
28
|
|
|
$criteria = Criteria::where('job_poster_id', $jobPoster->id)->get(); |
29
|
|
|
$criteriaTranslated = []; |
30
|
|
|
foreach ($criteria as $criterion) { |
31
|
|
|
// TODO: getTranslationsArray probably makes DB calls every loop. Find a way to profile & optimize. |
32
|
|
|
$criteriaTranslated[] = array_merge($criterion->toArray(), $criterion->getTranslations()); |
33
|
|
|
} |
34
|
|
|
$criteriaIds = $criteria->pluck('id'); |
35
|
|
|
$assessments = Assessment::whereIn('criterion_id', $criteriaIds)->get(); |
36
|
|
|
// Check for newly created assessment plan, and initialize any empty criteria to have the |
37
|
|
|
// "Narrative Review" option set. |
38
|
|
|
$assessmentCriteriaIds = $assessments->pluck('criterion_id'); |
39
|
|
|
$emptyAssessments = array_diff($criteriaIds->toArray(), $assessmentCriteriaIds->toArray()); |
40
|
|
|
if (!empty($emptyAssessments)) { |
41
|
|
|
$narrativeReview = AssessmentType::where('key', 'narrative_assessment')->first(); |
42
|
|
|
foreach ($emptyAssessments as $criterionId) { |
43
|
|
|
Assessment::create([ |
44
|
|
|
'criterion_id' => $criterionId, |
45
|
|
|
'assessment_type_id' => $narrativeReview->id |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
$assessments = Assessment::whereIn('criterion_id', $criteriaIds)->get(); |
49
|
|
|
} |
50
|
|
|
$questions = RatingGuideQuestion::where('job_poster_id', $jobPoster->id)->get(); |
51
|
|
|
$answers = RatingGuideAnswer::whereIn('rating_guide_question_id', $questions->pluck('id'))->get(); |
52
|
|
|
return [ |
53
|
|
|
'criteria' => $criteriaTranslated, |
54
|
|
|
'assessments' => $assessments->toArray(), |
55
|
|
|
'rating_guide_questions' => $questions->toArray(), |
56
|
|
|
'rating_guide_answers' => $answers->toArray() |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function show(JobPoster $jobPoster) |
61
|
|
|
{ |
62
|
|
|
// Show demo notification if the user is a demoManager and is not an hr-advisor that has claimed the job. |
63
|
|
|
$display_demo_notification = Auth::user() !== null && |
64
|
|
|
Auth::user()->isDemoManager() && |
65
|
|
|
(!$jobPoster->hr_advisors->contains('user_id', Auth::user()->id) && |
66
|
|
|
Auth::user()->isHrAdvisor()); |
67
|
|
|
|
68
|
|
|
$portal = WhichPortal::isHrPortal() ? 'hr' : 'manager'; |
69
|
|
|
|
70
|
|
|
return view('manager/assessment_plan', [ |
|
|
|
|
71
|
|
|
'title' => Lang::get('manager/assessment_plan.title'), |
72
|
|
|
'job_id' => $jobPoster->id, |
73
|
|
|
'display_demo_notification' => $display_demo_notification, |
74
|
|
|
'portal' => $portal, |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
|