Passed
Push — task/refactor-breadcrumbs ( 09deb1...5f819d )
by Yonathan
05:42
created

ApplicationController::showWithJob()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 2
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\JobPoster;
10
use App\Models\Skill;
11
use App\Models\Lookup\ReviewStatus;
12
use Facades\App\Services\WhichPortal;
13
14
class ApplicationController extends Controller
15
{
16
    /**
17
     * Display a listing of the resource.
18
     *
19
     * @return \Illuminate\Http\Response
20
     */
21
    public function index()
22
    {
23
        $applications = Auth::user()->applicant->job_applications;
24
        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

24
        return /** @scrutinizer ignore-call */ view(
Loading history...
25
            'applicant/application_index',
26
            [
27
                'application_index' => Lang::get('applicant/application_index'),
28
                'applications' => $applications,
29
                'manager_profile_photo' => '/images/user.png', // TODO: get real photo.
30
            ]
31
        );
32
    }
33
34
    /**
35
     * Determine whether the user can view the jobApplication.
36
     *
37
     * @param  \App\Models\JobPoster    $jobPoster Incoming JobPoster object.
38
     * @param  \App\Models\JobApplication $application Incoming Application object.
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function showWithJob(JobPoster $jobPoster, JobApplication $application)
42
    {
43
        $custom_breadcrumbs = [
0 ignored issues
show
Unused Code introduced by
The assignment to $custom_breadcrumbs is dead and can be removed.
Loading history...
44
            '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

44
            'home' => /** @scrutinizer ignore-call */ route('home'),
Loading history...
45
            'error' => ''
46
        ];
47
48
        if ($jobPoster->job_applications->contains($application)) {
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 specified application
57
     *
58
     * @param  \App\Models\JobApplication $application Incoming Application object.
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function show(JobApplication $application)
62
    {
63
        $response_poster = false;
64
        $jobPoster = $application->job_poster;
65
66
        if ($jobPoster->isInStrategicResponseDepartment()) {
67
            $response_poster = true;
68
        }
69
70
        $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

70
        $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...
71
            return $value->criteria_type->name == 'essential'
72
                && $value->skill->skill_type->name == 'hard';
73
        });
74
        $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

74
        $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...
75
            return $value->criteria_type->name == 'asset'
76
                && $value->skill->skill_type->name == 'hard';
77
        });
78
79
        // Display slightly different views on different portals.
80
        $view = WhichPortal::isManagerPortal() || WhichPortal::isHrPortal() ?
81
            'manager/application_post' : 'applicant/application_preview';
82
83
        $application_view = $response_poster
84
            ? 'applicant/strategic_response_application/application_view/application_layout'
85
            : 'common/application/view/view_layout';
86
87
        if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) {
88
            // Load things required for review component.
89
            $application->load(['veteran_status', 'citizenship_declaration', 'application_review', 'applicant.user']);
90
        }
91
92
93
        // If the application status is draft then get data through the applicant model.
94
        // Else, grab the data from the application itself.
95
        if ($application->isDraft()) {
96
            $source = $application->applicant;
97
        } else {
98
            $source = $application;
99
        }
100
101
        $degrees = $source->degrees;
102
        $courses = $source->courses;
103
        $work_experiences = $source->work_experiences;
104
        $skill_declarations = $source->skill_declarations;
105
        $references = $source->references;
106
        $work_samples = $source->work_samples;
107
108
        $custom_breadcrumbs = [
109
            '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

109
            'home' => /** @scrutinizer ignore-call */ route('home'),
Loading history...
110
            'applications' =>  route('applications.index'),
111
            'application' => '',
112
        ];
113
114
        if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) {
115
            $custom_breadcrumbs = [
116
                'home' => route('home'),
117
                'jobs' => route(WhichPortal::prefixRoute('jobs.index')),
118
                $jobPoster->title => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster),
119
                'applications' =>  route(WhichPortal::prefixRoute('jobs.applications'), $jobPoster),
120
                'application' => '',
121
            ];
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
            $view,
126
            [
127
                'application_view_template' => $application_view,
128
                // Localized strings.
129
                'post' => Lang::get('manager/application_post'), // Change text
130
                'is_manager_view' => WhichPortal::isManagerPortal(),
131
                'is_hr_portal' => WhichPortal::isHrPortal(),
132
                // Application Template Data.
133
                'application_template' => Lang::get('applicant/application_template'),
134
                'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'),
135
                'veteran_status_template' => Lang::get('common/veteran_status'),
136
                // Job Data.
137
                'job' => $jobPoster,
138
                // Skills Data.
139
                'skills' => Skill::all(),
140
                'skill_template' => Lang::get('common/skills'),
141
                'reference_template' => Lang::get('common/references'),
142
                'sample_template' => Lang::get('common/work_samples'),
143
                'essential_criteria' => $essential_criteria,
144
                'asset_criteria' => $asset_criteria,
145
                // Applicant Data.
146
                'applicant' => $application->applicant,
147
                'job_application' => $application,
148
                'degrees' => $degrees,
149
                'courses' => $courses,
150
                'work_experiences' => $work_experiences,
151
                'skill_declarations' => $skill_declarations,
152
                'references' => $references,
153
                'work_samples' => $work_samples,
154
                'review_statuses' => ReviewStatus::all(),
155
                'custom_breadcrumbs' => $custom_breadcrumbs,
156
                'response_poster' => $response_poster,
157
            ]
158
        );
159
    }
160
161
    /**
162
     * Delete the particular resource from storage.
163
     *
164
     * @param  \Illuminate\Http\Request   $request     Incoming Request object.
165
     * @param  \App\Models\JobApplication $application Incoming Application object.
166
     * @return \Illuminate\Http\Response
167
     */
168
    public function destroy(Request $request, JobApplication $application)
169
    {
170
        $this->authorize('delete', $application);
171
172
        $application->delete();
173
174
        if ($request->ajax()) {
175
            return [
176
                'message' => 'Application deleted'
177
            ];
178
        }
179
180
        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

180
        return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
181
    }
182
}
183