Passed
Push — feature/response-screening ( e0fe27...dc9872 )
by Chris
04:25 queued 11s
created

StrategicResponseController::index()   B

Complexity

Conditions 7
Paths 11

Size

Total Lines 47
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 47
rs 8.5226
cc 7
nc 11
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\JobPoster;
7
use App\Models\Lookup\JobSkillLevel;
8
use App\Models\Lookup\TalentStream;
9
use App\Models\Lookup\TalentStreamCategory;
10
use Illuminate\Support\Facades\Lang;
11
12
class StrategicResponseController extends Controller
13
{
14
15
    /**
16
     * Show the strategic response home page.
17
     * @return \Illuminate\Http\Response
18
     */
19
    public function index()
20
    {
21
22
        $stream_names = TalentStream::all();
23
        $stream_specialties = TalentStreamCategory::all();
24
        $job_skill_levels = JobSkillLevel::all();
25
26
        $strategic_response_id = config('app.strategic_response_department_id');
0 ignored issues
show
Bug introduced by
The function config 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

26
        $strategic_response_id = /** @scrutinizer ignore-call */ config('app.strategic_response_department_id');
Loading history...
27
        $strategic_response_jobs = JobPoster::where('department_id', $strategic_response_id)->get();
28
29
        $streams = [];
30
        // Iterate through all talent streams.
31
        foreach ($stream_names as $stream) {
32
            $stream_jobs = $strategic_response_jobs->where('talent_stream_id', $stream->id);
33
            $specialties = [];
34
            foreach ($stream_specialties as $specialty) {
35
                $stream_specialty_jobs = $stream_jobs->where('talent_stream_category_id', $specialty->id);
36
                if ($stream_specialty_jobs->isNotEmpty()) {
37
                    $levels = [];
38
                    foreach ($job_skill_levels as $level) {
39
                        $job = $stream_specialty_jobs->firstWhere('job_skill_level_id', $level->id);
40
                        if ($job) {
41
                            $levels[$level->name] = ['title' => $level->name, 'job_id' => $job->id];
42
                        } else {
43
                            $levels[$level->name] = ['title' => $level->name, 'job_id' => null];
44
                        }
45
                    }
46
47
                    // Push specialty title and associated levels to specialty array.
48
                    $specialties[$specialty->name] = [
49
                        'title' => $specialty->name,
50
                        'levels' => $levels,
51
                    ];
52
                }
53
            }
54
            if (!empty($specialties)) {
55
                ksort($specialties);
56
57
                // Push stream title and specialties to streams array.
58
                $streams[$stream->name] = ['title' => $stream->name, 'specialties' => $specialties];
59
            }
60
        }
61
        ksort($streams);
62
63
        return view('response/index/index', [
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

63
        return /** @scrutinizer ignore-call */ view('response/index/index', [
Loading history...
64
            'response' => Lang::get('response/index'),
65
            'streams' => $streams,
66
        ]);
67
    }
68
}
69