Passed
Push — feature/application-translatio... ( 2578af...96b410 )
by Tristan
06:21
created

ApplicationController::showVersionTwo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 1
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;
25
        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

25
        return /** @scrutinizer ignore-call */ view(
Loading history...
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
     * Determine whether the user can view the jobApplication.
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 showWithJob(JobPoster $jobPoster, JobApplication $application)
43
    {
44
        if ($jobPoster->job_applications->contains($application)) {
45
            // If the application is version two then show the version two application review page.
46
            if ($application->version_id !== null && $application->version_id == 2) {
47
                return $this->showVersionTwo($application);
48
            }
49
            return $this->show($application);
50
        } else {
51
            return abort(404);
0 ignored issues
show
Bug introduced by
The function abort 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

51
            return /** @scrutinizer ignore-call */ abort(404);
Loading history...
52
        }
53
    }
54
55
    /**
56
     * "Display version two of application, from Manager perspective, with review toolbar included."
57
     * @param  \App\Models\JobApplication $application Incoming Application object.
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function showVersionTwo(JobApplication $application)
61
    {
62
        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

62
        return /** @scrutinizer ignore-call */ view(
Loading history...
63
            'manager/application_timeline_review',
64
            [
65
                'applicant' => $application->applicant,
66
                'application' => $application,
67
                'application_template' => Lang::get('applicant/application_template'),
68
                'job_id' => $application->job_poster_id,
69
                'review_statuses' => ReviewStatus::all(),
70
                'is_hr_portal' => WhichPortal::isHrPortal(),
71
            ]
72
        );
73
    }
74
75
    /**
76
     * Display specified application
77
     *
78
     * @param  \App\Models\JobApplication $application Incoming Application object.
79
     * @return \Illuminate\Http\Response
80
     */
81
    public function show(JobApplication $application)
82
    {
83
        $response_poster = false;
84
        $show_review = true;
85
        $jobPoster = $application->job_poster;
86
87
        if ($jobPoster->isInStrategicResponseDepartment()) {
88
            $response_poster = true;
89
            $show_review = false;
90
        }
91
92
        $essential_criteria = $jobPoster->criteria->filter(function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

92
        $essential_criteria = $jobPoster->criteria->filter(function ($value, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
            return $value->criteria_type->name == 'essential'
94
                && $value->skill->skill_type->name == 'hard';
95
        });
96
        $asset_criteria = $jobPoster->criteria->filter(function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

96
        $asset_criteria = $jobPoster->criteria->filter(function ($value, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
            return $value->criteria_type->name == 'asset'
98
                && $value->skill->skill_type->name == 'hard';
99
        });
100
101
        // Display slightly different views on different portals.
102
        $view = WhichPortal::isManagerPortal() || WhichPortal::isHrPortal() ?
103
            'manager/application_post' : 'applicant/application_preview';
104
105
        $application_view = $response_poster
106
            ? 'applicant/strategic_response_application/application_view/application_layout'
107
            : 'common/application/view/view_layout';
108
109
        if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) {
110
            // Load things required for review component.
111
            $application->load(['veteran_status', 'citizenship_declaration', 'application_review', 'applicant.user']);
112
        }
113
114
115
        // If the application status is draft then get data through the applicant model.
116
        // Else, grab the data from the application itself.
117
        if ($application->isDraft()) {
118
            $source = $application->applicant;
119
            $show_review = false;
120
        } else {
121
            $source = $application;
122
        }
123
124
        $degrees = $source->degrees;
125
        $courses = $source->courses;
126
        $work_experiences = $source->work_experiences;
127
        $skill_declarations = $source->skill_declarations;
128
        $references = $source->references;
129
        $work_samples = $source->work_samples;
130
131
        $custom_breadcrumbs = [
132
            'home' => route('home'),
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

132
            'home' => /** @scrutinizer ignore-call */ route('home'),
Loading history...
133
            'applications' =>  route('applications.index'),
134
            'application' => '',
135
        ];
136
137
        if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) {
138
            $custom_breadcrumbs = [
139
                'home' => route('home'),
140
                'jobs' => route(WhichPortal::prefixRoute('jobs.index')),
141
                $jobPoster->title => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster),
142
                'applications' =>  route(WhichPortal::prefixRoute('jobs.applications'), $jobPoster),
143
                'application' => '',
144
            ];
145
        }
146
147
        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

147
        return /** @scrutinizer ignore-call */ view(
Loading history...
148
            $view,
149
            [
150
                'application_view_template' => $application_view,
151
                // Localized strings.
152
                'post' => Lang::get('manager/application_post'), // Change text
153
                'is_manager_view' => WhichPortal::isManagerPortal(),
154
                'is_hr_portal' => WhichPortal::isHrPortal(),
155
                // Application Template Data.
156
                'application_template' => Lang::get('applicant/application_template'),
157
                'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'),
158
                'veteran_status_template' => Lang::get('common/veteran_status'),
159
                // Job Data.
160
                'job' => $jobPoster,
161
                // Skills Data.
162
                'skills' => Skill::all(),
163
                'skill_template' => Lang::get('common/skills'),
164
                'reference_template' => Lang::get('common/references'),
165
                'sample_template' => Lang::get('common/work_samples'),
166
                'essential_criteria' => $essential_criteria,
167
                'asset_criteria' => $asset_criteria,
168
                // Applicant Data.
169
                'applicant' => $application->applicant,
170
                'job_application' => $application,
171
                'degrees' => $degrees,
172
                'courses' => $courses,
173
                'work_experiences' => $work_experiences,
174
                'skill_declarations' => $skill_declarations,
175
                'references' => $references,
176
                'work_samples' => $work_samples,
177
                'review_statuses' => ReviewStatus::all(),
178
                'custom_breadcrumbs' => $custom_breadcrumbs,
179
                'response_poster' => $response_poster,
180
                'show_review' => $show_review,
181
            ]
182
        );
183
    }
184
185
    /**
186
     * Delete the particular resource from storage.
187
     *
188
     * @param  \Illuminate\Http\Request   $request     Incoming Request object.
189
     * @param  \App\Models\JobApplication $application Incoming Application object.
190
     * @return \Illuminate\Http\Response
191
     */
192
    public function destroy(Request $request, JobApplication $application)
193
    {
194
        $this->authorize('delete', $application);
195
196
        $application->delete();
197
198
        if ($request->ajax()) {
199
            return [
200
                'message' => 'Application deleted'
201
            ];
202
        }
203
204
        return redirect()->back();
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

204
        return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
205
    }
206
}
207