Passed
Push — feature/manager-summary-view ( 752e93...abc3f8 )
by Yonathan
04:49
created

JobSummaryController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 80
c 1
b 0
f 0
dl 0
loc 131
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unclaimJob() 0 6 1
C show() 0 106 11
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\JobPoster;
7
use Facades\App\Services\WhichPortal;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\Lang;
11
12
class JobSummaryController extends Controller
13
{
14
    /**
15
     * Display the specified job summary.
16
     *
17
     * @param  \Illuminate\Http\Request $request Incoming request object.
18
     * @param  \App\Models\JobPoster $job Job Poster object.
19
     * @return \Illuminate\Http\Response
20
     */
21
    public function show(Request $request, JobPoster $job)
22
    {
23
        $user = Auth::user();
24
25
        $applications = $job->submitted_applications;
26
        $advisor = $user->hr_advisor;
27
        $jobIsClaimed = ($advisor !== null) &&
28
            $advisor->claimed_job_ids->contains($job->id);
29
        $hr_advisors = $job->hr_advisors;
30
31
        $summaryLang = Lang::get('hr_advisor/job_summary');
32
33
        $job_review_data = [
34
            'imgSrc' => '/images/job-process-summary-tool-edit.svg',
35
            'imgAlt' => "{$summaryLang['edit_poster_icon']} {$summaryLang['flat_icons']}",
36
            'text' => $summaryLang['edit_poster_button'],
37
            'url' => route(WhichPortal::prefixRoute('jobs.review'), $job),
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            'url' => /** @scrutinizer ignore-call */ route(WhichPortal::prefixRoute('jobs.review'), $job),
Loading history...
38
            'disabled' => false,
39
        ];
40
41
        $job_preview_data = [
42
            'imgSrc' => '/images/job-process-summary-tool-view.svg',
43
            'imgAlt' => "{$summaryLang['view_poster_icon']} {$summaryLang['flat_icons']}",
44
            'text' => $summaryLang['view_poster_button'],
45
            'url' => route(WhichPortal::prefixRoute('jobs.preview'), $job),
46
            'disabled' => false,
47
        ];
48
49
        $screening_plan_data = [
50
            'imgSrc' => '/images/job-process-summary-tool-screen.svg',
51
            'imgAlt' => "{$summaryLang['screening_plan_icon']} {$summaryLang['flat_icons']}",
52
            'text' => $summaryLang['screening_plan_button'],
53
            'url' => route(WhichPortal::prefixRoute('jobs.screening_plan'), $job),
54
            'disabled' => false
55
        ];
56
57
        $view_applicants_data = [
58
            'imgSrc' => '/images/job-process-summary-tool-applicants.svg',
59
            'imgAlt' => "{$summaryLang['view_applicants_icon']} {$summaryLang['flat_icons']}",
60
            'text' => $summaryLang['view_applicants_button'],
61
            'url' => route(WhichPortal::prefixRoute('jobs.applications'), $job),
62
            'disabled' => !$job->isClosed(),
63
        ];
64
65
        switch ($job->job_status_id) {
66
            case 1:
67
                $status = Lang::get('common/lookup/job_status.draft');
68
                break;
69
            case 2:
70
                $status = Lang::get('common/lookup/job_status.in_review');
71
                break;
72
            case 3:
73
                $status = Lang::get('common/lookup/job_status.approved');
74
                break;
75
            case 4:
76
                $status = Lang::get('common/lookup/job_status.open');
77
                break;
78
            case 5:
79
                $status = Lang::get('common/lookup/job_status.closed');
80
                break;
81
            case 6:
82
                $status = Lang::get('common/lookup/job_status.complete');
83
                break;
84
        }
85
        // TODO: This should change based on the current status.
86
        $status_description = $job->job_status_id == 2
87
            ? $summaryLang['under_review']
88
            : '';
89
90
        $portal = '';
91
92
        if (WhichPortal::isHrPortal()) {
93
            $portal = 'hr';
94
        } elseif (WhichPortal::isManagerPortal()) {
95
            $portal = 'manager';
96
        }
97
98
        $data = [
99
            // Localized strings.
100
            'summary' => $summaryLang,
101
            'job_status' => $status,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $status does not seem to be defined for all execution paths leading up to this point.
Loading history...
102
            'job_status_description' => $status_description,
103
            'is_claimed' => $jobIsClaimed,
104
            // User data.
105
            'user' => $user,
106
            // HR Advisor data.
107
            'hr_advisors' => $hr_advisors,
108
            // Job Poster data.
109
            'job' => $job,
110
            // Application data.
111
            'applications' => $applications,
112
            // TODO: Add Routes.
113
            // 'send_manager' => ,
114
            // 'send_translation' => ,
115
            // 'approve_publishing' => ,
116
            'job_review_data' => $job_review_data,
117
            'job_preview_data' => $job_preview_data,
118
            'screening_plan_data' => $screening_plan_data,
119
            'view_applicants_data' => $view_applicants_data,
120
            'relinquish_job' => route('hr_advisor.jobs.unclaim', $job),
121
            'portal' => $portal,
122
        ];
123
124
        return view(
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        return /** @scrutinizer ignore-call */ view(
Loading history...
125
            'hr_advisor/job_summary',
126
            $data
127
        );
128
    }
129
130
    /**
131
     * Unclaim a Job Poster.
132
     *
133
     * @param  \Illuminate\Http\Request $request Incoming request object.
134
     * @param  \App\Models\JobPoster  $job
135
     * @return \Illuminate\Http\Response
136
     */
137
    public function unclaimJob(Request $request, JobPoster $job)
138
    {
139
        $hrAdvisor = $request->user()->hr_advisor;
140
        $hrAdvisor->claimed_jobs()->detach($job);
141
142
        return redirect()->route('hr_advisor.jobs.index');
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

142
        return /** @scrutinizer ignore-call */ redirect()->route('hr_advisor.jobs.index');
Loading history...
143
    }
144
}
145