Passed
Push — feature/create_job__controller ( 068bf5 )
by Tristan
08:15
created

JobController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 Barryvdh\Debugbar\Facade as Debugbar;
9
use App\Http\Controllers\Controller;
10
use Carbon\Carbon;
11
use App\Models\JobPoster;
12
use App\Models\Lookup\JobTerm;
13
use App\Models\Lookup\Province;
14
use App\Models\Lookup\SecurityClearance;
15
use App\Models\Lookup\LanguageRequirement;
16
use App\Models\Lookup\Department;
17
use App\Models\JobPosterQuestion;
18
use App\Models\JobPosterKeyTask;
19
use Jenssegers\Date\Date;
20
21
class JobController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JobController
Loading history...
22
{
23
    /**
24
     * Display a listing of JobPosters.
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28
    public function index()
29
    {
30
        $now = Carbon::now();
31
        //Find jobs that are currently open for applications
32
        $jobs = JobPoster::where('open_date_time', '<=', $now)->where('close_date_time', '>=', $now)->get();
33
        return view('applicant/job_index', ['job_index' => Lang::get('applicant/job_index'),
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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...
34
            '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...
35
    }
36
37
    /**
38
     * Display the specified job poster.
39
     *
40
     * @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...
41
     * @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...
42
     * @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...
43
     */
44
    public function show(Request $request, JobPoster $jobPoster)
45
    {
46
        //TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model
47
        $workplacePhotos = [];
48
        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...
49
            $workplacePhotos[] = [
50
                'description' => $photoCaption->description,
51
                'url' => '/images/user.png'
52
            ];
53
        }
54
55
        //TODO: replace route('manager.show',manager.id) in templates with link using slug
56
57
        $criteria = [
58
            '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...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
59
                return $value->criteria_type->name == 'essential';
60
            }),
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...
61
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
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...
62
                return $value->criteria_type->name == 'asset';
63
            })
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...
64
        ];
65
66
        return view('applicant/job_post', [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug Best Practice introduced by
The expression return view('applicant/j...riteria' => $criteria)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
67
            'job_post' =>Lang::get('applicant/job_post'),
68
            'manager' => $jobPoster->manager,
69
            'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
70
            'team_culture' => $jobPoster->manager->team_culture,
71
            'work_environment' => $jobPoster->manager->work_environment,
72
            'workplace_photos' => $workplacePhotos,
73
            'job' => $jobPoster,
74
            'criteria' => $criteria,
75
        ]);
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...
76
    }
77
78
    /**
79
     * Display the form for creating a new Job Poster
80
     * @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...
81
     * @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...
82
     */
83
    public function create(Request $request) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
84
        $manager = $request->user() ? $request->user()->manager : null;
85
86
        //No job details exist yet because we're creating a new one
87
        $job = [];
88
89
        return view('manager/job_create', [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug Best Practice introduced by
The expression return view('manager/job...'manager.jobs.store'))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
90
            'manager_job_create' => Lang::get('manager/job_create'),
91
            'manager' => $manager,
92
            'provinces' => Province::all(),
93
            'departments' => Department::all(),
94
            'language_requirments' => LanguageRequirement::all(),
95
            'security_clearances' => SecurityClearance::all(),
96
            'job' => $job,
97
            'form_action_url' => route('manager.jobs.store')
98
        ]);
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...
99
    }
100
101
    /**
102
     * Create a new resource in storage
103
     * @param  Request $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
104
     * @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...
105
     */
106
    public function store(Request $request) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
107
108
        $input = $request->input();
109
110
        $job = new JobPoster();
111
        $job->manager_id = $request->user()->manager->id;
112
        $job->published = ($input['submit'] == 'publish');
113
        $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...
114
            'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id,
115
            'term_qty' => $input['term_qty'],
116
            'open_date_time' => new Date($input['open_date_time']),
117
            'close_date_time' => new Date($input['close_date_time']),
118
            'start_date_time' => new Date($input['start_date_time']),
119
            'department_id' => $input['department'],
120
            'province_id' => $input['province'],
121
            'salary_min' => $input['salary_min'],
122
            'salary_max' => $input['salary_max'],
123
            'noc' => $input['noc'],
124
            'classification' => $input['classification'],
125
            'security_clearance_id' => $input['security_clearance'],
126
            'language_requirement_id' => $input['language_requirement'],
127
            'en' => [
128
                'city' => $input['city'],
129
                'title' => $input['title']['en'],
130
                'impact' => $input['impact']['en'],
131
                'branch' => $input['branch']['en'],
132
                'division' => $input['division']['en']
133
            ],
134
            'fr' => [
135
                'city' => $input['city'],
136
                'title' => $input['title']['fr'],
137
                'impact' => $input['impact']['fr'],
138
                'branch' => $input['branch']['fr'],
139
                'division' => $input['division']['fr']
140
            ],
141
        ]);
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...
142
        $job->save();
143
144
        if (isset($input['task'])) {
145
            foreach($input['task'] as $task) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
146
                $jobPosterTask = new JobPosterKeyTask();
147
                $jobPosterTask->job_poster_id =  $job->id;
148
                $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...
149
                    'en' => [
150
                        'description' => $task['en']
151
                    ],
152
                    'fr' => [
153
                        'description' => $task['fr']
154
                    ]
155
                ]);
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...
156
                $jobPosterTask->save();
157
            }
158
        }
159
160
        if (isset($input['question'])) {
161
            foreach($input['question'] as $question) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
162
                $jobQuestion = new JobPosterQuestion();
163
                $jobQuestion->job_poster_id = $job->id;
164
                $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...
165
                    'en'=> [
166
                        'question' => $question['question']['en'],
167
                        'description' => $question['description']['en']
168
                    ],
169
                    'fr'=> [
170
                        'question' => $question['question']['fr'],
171
                        'description' => $question['description']['fr']
172
                    ]
173
                ]);
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...
174
                $jobQuestion->save();
175
            }
176
        }
177
        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...
178
    }
179
}
180