Passed
Push — bugfix/relatives_not_saving ( 6485fa...f1e1c5 )
by Tristan
13:39
created

ManagerProfileController::editAuthenticated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Http\Request;
7
use App\Http\Controllers\Controller;
8
use App\Models\Lookup\Frequency;
9
use App\Models\Lookup\Department;
10
use App\Models\WorkEnvironment;
11
use App\Models\TeamCulture;
12
use App\Models\Manager;
13
14
class ManagerProfileController extends Controller {
15
16
    /**
17
     * Show a manager profile
18
     *
19
     * @param  Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 13 spaces after parameter type; 2 found
Loading history...
20
     * @param  \App\Models\Manager  $manager
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
21
     * @return \Illuminate\Http\Response
22
     */
23
    public function show(Request $request, Manager $manager) {
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

23
    public function show(/** @scrutinizer ignore-unused */ Request $request, Manager $manager) {

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...
introduced by
Method \App\Http\Controllers\ManagerProfileController::show() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
24
        $manager_profile = Lang::get('applicant/manager_profile');
25
26
        $manager_profile_sections = [
27
            [
28
                "title" => $manager_profile['section_titles']['approach'],
29
                "questions" => [
30
                    [
31
                        "title" => $manager_profile['questions']['leadership_style'],
32
                        "answer" => $manager->leadership_style
33
                    ],
34
                    [
35
                        "title" => $manager_profile['questions']['employee_expectations'],
36
                        "answer" => $manager->expectations
37
                    ],
38
                    [
39
                        "title" => $manager_profile['questions']['employee_learning'],
40
                        "answer" => $manager->employee_learning
41
                    ]
42
                ]
43
            ],
44
            [
45
                "title" => $manager_profile['section_titles']['about_me'],
46
                "questions" => [
47
                    [
48
                        "title" => $manager_profile['questions']['career_journey'],
49
                        "answer" => $manager->career_journey
50
                    ],
51
                    [
52
                        "title" => $manager_profile['questions']['learning_path'],
53
                        "answer" => $manager->learning_path
54
                    ],
55
                    [
56
                        "title" => $manager_profile['questions']['about_me'],
57
                        "answer" => $manager->about_me
58
                    ]
59
                ]
60
            ]
61
        ];
62
63
64
        return view('applicant/manager', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/m...ager_profile_sections)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
65
            "manager_profile" => $manager_profile,
66
            'urls' => Lang::get('common/urls'),
67
            'manager' => $manager,
68
            'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
69
            "manager_profile_sections" => $manager_profile_sections,
70
        ]);
71
    }
72
73
    /**
74
     * Show the form for editing the logged-in user's manager profile
75
     *
76
     * @param  Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 13 spaces after parameter type; 2 found
Loading history...
77
     * @param  \App\Models\Manager  $manager
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function edit(Request $request, Manager $manager) {
0 ignored issues
show
introduced by
Method \App\Http\Controllers\ManagerProfileController::edit() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
81
82
        //TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model
83
        $workplacePhotos = [];
84
        if ($manager->work_environment != null) {
85
            foreach($manager->work_environment->workplace_photo_captions as $photoCaption) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after FOREACH keyword; 0 found
Loading history...
86
                $workplacePhotos[] = [
87
                    'id' => $photoCaption->id,
88
                    'alt' => $photoCaption->description,
89
                    'alt_fr' => $photoCaption->description,
90
                    'url' => '/images/user.png'
91
                ];
92
            }
93
        }
94
95
        $frequencies = Frequency::all();
96
97
        return view('manager/profile', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('manager/pro...ions' => $frequencies)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
98
            /* Localization */
99
            'profile_l10n' => Lang::get('manager/profile'),
100
101
            /* Data */
102
            'urls' => Lang::get('common/urls'),
103
            'user' => $manager->user,
104
            'manager' => $manager,
105
            'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
106
            'team_culture' => $manager->team_culture,
107
            'work_environment' => $manager->work_environment,
108
            'workplace_photos' => $workplacePhotos,
109
            'departments' => Department::all(),
110
            'telework_options' => $frequencies,
111
            'flex_hour_options' => $frequencies,
112
            'radio_options' => $frequencies
113
        ]);
114
    }
115
116
    /**
117
     * Update the specified resource in storage.
118
     *
119
     * @param  \Illuminate\Http\Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
120
     * @param  \App\Models\Manager  $manager
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
121
     * @return \Illuminate\Http\Response
122
     */
123
    public function update(Request $request, Manager $manager) {
0 ignored issues
show
introduced by
Method \App\Http\Controllers\ManagerProfileController::update() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
124
        $input = $request->input();
125
126
        //TODO: remove control of name in production
127
        $manager->user->name = $input['name'];
128
        $manager->user->save();
129
130
        $manager->fill([
131
            'department_id' => $input['department'],
132
            'twitter_username' => $input['twitter_username'],
133
            'linkedin_url' => $input['linkedin_url'],
134
            //'work_review_frequency_id' => [],
135
            //'stay_late_frequency_id' => [],
136
            //'engage_team_frequency_id' => [],
137
            //'development_opportunity_frequency_id',
138
            //'refuse_low_value_work_frequency_id',
139
            'years_experience' => $input['years_experience'],
140
            'en' => [
141
                'about_me' => $input['about_me']['en'],
142
                //'greatest_accomplishment',
143
                'branch' =>  $input['branch']['en'],
144
                'division' => $input['division']['en'],
145
                'position' => $input['position']['en'],
146
                'leadership_style' => $input['leadership_style']['en'],
147
                'employee_learning' => $input['employee_learning']['en'],
148
                'expectations' => $input['expectations']['en'],
149
                'education' => $input['education']['en'],
150
                'career_journey' => $input['career_journey']['en'],
151
                'learning_path' => $input['learning_path']['en']
152
            ],
153
            'fr' => [
154
                'about_me' => $input['about_me']['fr'],
155
                //'greatest_accomplishment',
156
                'branch' =>  $input['branch']['fr'],
157
                'division' => $input['division']['fr'],
158
                'position' => $input['position']['fr'],
159
                'leadership_style' => $input['leadership_style']['fr'],
160
                'employee_learning' => $input['employee_learning']['fr'],
161
                'expectations' => $input['expectations']['fr'],
162
                'education' => $input['education']['fr'],
163
                'career_journey' => $input['career_journey']['fr'],
164
                'learning_path' => $input['learning_path']['fr']
165
            ]
166
        ]);
167
168
        $manager->save();
169
170
        $work_environment = $manager->work_environment;
171
        $work_environment->fill([
172
            'en' => [
173
                'things_to_know' => $input['things_to_know']['en']
174
            ],
175
            'fr' => [
176
                'things_to_know' => $input['things_to_know']['fr']
177
            ]
178
        ]);
179
        //Slider select inputs can be missing from input if nothing was selected
180
        if (isset($input['telework'])) {
181
            $work_environment->telework_allowed_frequency_id = $input['telework'];
182
        }
183
        if (isset($input['flex_hours'])) {
184
            $work_environment->flexible_hours_frequency_id = $input['flex_hours'];
185
        }
186
        $work_environment->save();
187
188
        $team_culture = $manager->team_culture;
189
        $team_culture->fill([
190
            'team_size' => $input['team_size'],
191
            'gc_directory_url' => $input['gc_directory_url'],
192
            'en' => [
193
                'operating_context' => $input['operating_context']['en'],
194
                'what_we_value' => $input['what_we_value']['en'],
195
                'how_we_work' => $input['how_we_work']['en']
196
            ],
197
            'fr' => [
198
                'operating_context' => $input['operating_context']['fr'],
199
                'what_we_value' => $input['what_we_value']['fr'],
200
                'how_we_work' => $input['how_we_work']['fr']
201
            ]
202
        ]);
203
        $team_culture->save();
204
205
        //TODO: save workplace Photos
206
207
        //Use the button that was clicked to decide which element to redirect to
208
        switch ($input['submit']) {
209
            case 'about_me':
210
                $hash = '#managerProfileSectionAbout';
211
                break;
212
            case 'team_culture':
213
                $hash = '#managerProfileSectionCulture';
214
                break;
215
            case 'work_environment':
216
                $hash = '#managerProfileSectionEnvrionment';
217
                break;
218
            case 'leadership':
219
                $hash = '#managerProfileSectionLeadership';
220
                break;
221
            default:
222
                $hash = "";
223
                break;
224
        }
225
226
        return redirect( route('manager.profile.edit', $manager).$hash );
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect(route('m...it', $manager) . $hash) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
227
    }
228
229
}
230