Completed
Push — master ( f0368a...52970f )
by Tristan
26:28 queued 18:03
created

JobController   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 233
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
eloc 137
dl 0
loc 233
ccs 0
cts 136
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 11 1
A create() 0 18 2
A managerIndex() 0 31 4
A show() 0 31 2
B store() 0 102 9
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Http\Request;
8
use App\Http\Controllers\Controller;
9
use Carbon\Carbon;
10
use App\Models\JobPoster;
11
use App\Models\Lookup\JobTerm;
12
use App\Models\Lookup\Province;
13
use App\Models\Lookup\SecurityClearance;
14
use App\Models\Lookup\LanguageRequirement;
15
use App\Models\Lookup\CitizenshipDeclaration;
16
use App\Models\Lookup\Department;
17
use App\Models\Lookup\SkillLevel;
18
use App\Models\Lookup\CriteriaType;
19
use App\Models\Lookup\VeteranStatus;
20
use App\Models\JobApplication;
21
use App\Models\Criteria;
22
use App\Models\Skill;
23
use App\Models\JobPosterQuestion;
24
use App\Models\JobPosterKeyTask;
25
use Jenssegers\Date\Date;
26
27
class JobController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JobController
Loading history...
28
{
29
    /**
30
     * Display a listing of JobPosters.
31
     *
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function index()
35
    {
36
        $now = Carbon::now();
37
        //Find published jobs that are currently open for applications
38
        $jobs = JobPoster::where('open_date_time', '<=', $now)
39
            ->where('close_date_time', '>=', $now)
40
            ->where('published', true)
41
            ->get();
42
        $jobs->load('manager.work_environment');
43
        return view('applicant/job_index', ['job_index' => Lang::get('applicant/job_index'),
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/j...ex'), 'jobs' => $jobs)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
44
            'jobs' => $jobs]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
45
    }
46
47
    /**
48
     * Display a listing of a manager's JobPosters.
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function managerIndex()
53
    {
54
        $manager = Auth::user()->manager;
0 ignored issues
show
Bug introduced by
Accessing manager on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
55
56
        $veteran_applications = [];
57
        $citizen_applications = [];
58
        $other_applications = [];
59
60
        foreach($manager->job_posters as $job) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
61
            $job->submitted_applications->load(['veteran_status', 'citizenship_declaration']);
62
            $veteran_applications[$job->id] = $job->submitted_applications->filter(function($application) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
63
                return $application->veteran_status->name !== "none" &&
64
                        $application->citizenship_declaration->name === "citizen";
65
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
66
            $citizen_applications[$job->id] = $job->submitted_applications->filter(function($application) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
67
                return $application->veteran_status->name === "none" &&
68
                        $application->citizenship_declaration->name === "citizen";
69
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
70
            $other_applications[$job->id] = $job->submitted_applications->filter(function($application) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
71
                return $application->citizenship_declaration->name !== "citizen";
72
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
73
        }
74
75
        return view('manager/job_index', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('manager/job...> $other_applications)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
76
            "manager_job_index" => [
77
                "title" => "My Job Posts"
78
            ],
79
            'jobs' => $manager->job_posters,
80
            'veteran_applications' => $veteran_applications,
81
            'citizen_applications' => $citizen_applications,
82
            'other_applications' => $other_applications,
83
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
84
    }
85
86
    /**
87
     * Display the specified job poster.
88
     *
89
     * @param  Request  $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
90
     * @param  \App\Models\JobPoster  $jobPoster
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
91
     * @return \Illuminate\Http\Response
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
92
     */
93
    public function show(Request $request, JobPoster $jobPoster)
94
    {
95
        //TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model
96
        $workplacePhotos = [];
97
        foreach($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
98
            $workplacePhotos[] = [
99
                'description' => $photoCaption->description,
100
                'url' => '/images/user.png'
101
            ];
102
        }
103
104
        //TODO: replace route('manager.show',manager.id) in templates with link using slug
105
106
        $criteria = [
107
            'essential' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
108
                return $value->criteria_type->name == 'essential';
109
            }),
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
110
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
111
                return $value->criteria_type->name == 'asset';
112
            }),
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
113
        ];
114
        return view('applicant/job_post', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/j...:get('common/skills'))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
115
            'job_post' =>Lang::get('applicant/job_post'),
116
            'manager' => $jobPoster->manager,
117
            'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
118
            'team_culture' => $jobPoster->manager->team_culture,
119
            'work_environment' => $jobPoster->manager->work_environment,
120
            'workplace_photos' => $workplacePhotos,
121
            'job' => $jobPoster,
122
            'criteria' => $criteria,
123
            'skill_template' => Lang::get('common/skills'),
124
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
125
    }
126
127
    /**
128
     * Display the form for creating a new Job Poster
129
     * @param  Request $request [description]
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
130
     * @return \Illuminate\Http\Response           A view
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
131
     */
132
    public function create(Request $request) {
133
        $manager = $request->user() ? $request->user()->manager : null;
134
135
        //No job details exist yet because we're creating a new one
136
        $job = [];
137
138
        return view('manager/job_create', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('manager/job...:get('common/skills'))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
139
            'job_create' => Lang::get('manager/job_create'),
140
            'manager' => $manager,
141
            'provinces' => Province::all(),
142
            'departments' => Department::all(),
143
            'language_requirments' => LanguageRequirement::all(),
144
            'security_clearances' => SecurityClearance::all(),
145
            'job' => $job,
146
            'form_action_url' => route('manager.jobs.store'),
147
            'skills' => Skill::all(),
148
            'skill_levels' => SkillLevel::all(),
149
            'skill_template' => Lang::get('common/skills'),
150
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
151
    }
152
153
    /**
154
     * Create a new resource in storage
155
     * @param  Request $request
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
156
     * @return \Illuminate\Http\Response           A redirect
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
157
     */
158
    public function store(Request $request) {
159
160
        $input = $request->input();
161
162
        $job = new JobPoster();
163
        $job->manager_id = $request->user()->manager->id;
164
        $job->published = ($input['submit'] == 'publish');
165
        $job->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
166
            'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id,
167
            'term_qty' => $input['term_qty'],
168
            'open_date_time' => new Date($input['open_date'].$input['open_time']),
169
            'close_date_time' => new Date($input['close_date'].$input['close_time']),
170
            'start_date_time' => new Date($input['start_date_time']),
171
            'department_id' => $input['department'],
172
            'province_id' => $input['province'],
173
            'salary_min' => $input['salary_min'],
174
            'salary_max' => $input['salary_max'],
175
            'noc' => $input['noc'],
176
            'classification' => $input['classification'],
177
            'security_clearance_id' => $input['security_clearance'],
178
            'language_requirement_id' => $input['language_requirement'],
179
            'remote_work_allowed' => $request->input('remote_work_allowed', false),
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type array|null|string expected by parameter $default of Illuminate\Http\Request::input(). ( Ignorable by Annotation )

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

179
            'remote_work_allowed' => $request->input('remote_work_allowed', /** @scrutinizer ignore-type */ false),
Loading history...
180
            'en' => [
181
                'city' => $input['city'],
182
                'title' => $input['title']['en'],
183
                'impact' => $input['impact']['en'],
184
                'branch' => $input['branch']['en'],
185
                'division' => $input['division']['en'],
186
                'education' => $input['education']['en'],
187
            ],
188
            'fr' => [
189
                'city' => $input['city'],
190
                'title' => $input['title']['fr'],
191
                'impact' => $input['impact']['fr'],
192
                'branch' => $input['branch']['fr'],
193
                'division' => $input['division']['fr'],
194
                'education' => $input['education']['fr'],
195
            ],
196
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
197
        $job->save();
198
199
        if (isset($input['task'])) {
200
            foreach($input['task'] as $task) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
201
                $jobPosterTask = new JobPosterKeyTask();
202
                $jobPosterTask->job_poster_id =  $job->id;
203
                $jobPosterTask->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
204
                    'en' => [
205
                        'description' => $task['en']
206
                    ],
207
                    'fr' => [
208
                        'description' => $task['fr']
209
                    ]
210
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
211
                $jobPosterTask->save();
212
            }
213
        }
214
215
        if (isset($input['question'])) {
216
            foreach($input['question'] as $question) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
217
                $jobQuestion = new JobPosterQuestion();
218
                $jobQuestion->job_poster_id = $job->id;
219
                $jobQuestion->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
220
                    'en'=> [
221
                        'question' => $question['question']['en'],
222
                        'description' => $question['description']['en']
223
                    ],
224
                    'fr'=> [
225
                        'question' => $question['question']['fr'],
226
                        'description' => $question['description']['fr']
227
                    ]
228
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
229
                $jobQuestion->save();
230
            }
231
        }
232
233
        $criteria = $input['criteria'];
234
235
        //Save new criteria
236
        if (isset($criteria['new'])) {
237
            foreach($criteria['new'] as $criteriaType => $criteriaTypeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
238
                foreach($criteriaTypeInput as $skillType => $skillTypeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
239
                    foreach($skillTypeInput as $criteriaInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
240
                        $criteria = new Criteria();
241
                        $criteria->job_poster_id = $job->id;
242
                        $criteria->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
243
                            'criteria_type_id' => CriteriaType::where('name', $criteriaType)->firstOrFail()->id,
244
                            'skill_id' => $criteriaInput['skill_id'],
245
                            'skill_level_id' => $criteriaInput['skill_level_id'],
246
                            'en' => [
247
                                'description' => $criteriaInput['description']['en'],
248
                            ],
249
                            'fr' => [
250
                                'description' => $criteriaInput['description']['fr'],
251
                            ],
252
                        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
253
                        $criteria->save();
254
                    }
255
                }
256
            }
257
        }
258
259
        return redirect( route('manager.jobs.index') );
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect(route('manager.jobs.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
260
    }
261
}
262