Passed
Push — master ( 8c9d15...53e72a )
by Thomas
07:13
created

FiltersSearchableLevels   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A CourseController::__construct() 0 4 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Course;
6
use App\Models\Level;
7
use App\Models\Period;
8
use App\Models\Rhythm;
9
use App\Models\Student;
10
use App\Traits\FiltersSearchableLevels;
11
use Illuminate\Http\Request;
12
use Spatie\QueryBuilder\AllowedFilter;
13
use Spatie\QueryBuilder\QueryBuilder;
14
15
class CourseController extends Controller
16
{
17
    public function __construct()
18
    {
19
        parent::__construct();
20
        $this->middleware('permission:courses.view');
21
    }
22
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @param \Illuminate\Http\Request $request
27
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
28
     */
29
    public function index(Request $request)
30
    {
31
        $defaultPeriod = Period::get_default_period();
32
        $rhythms = Rhythm::all();
33
        $levels = Level::all();
34
        $isAllowedToEdit = backpack_user()->hasPermissionTo('courses.edit') ? 1 : 0;
0 ignored issues
show
Bug introduced by
The method hasPermissionTo() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

34
        $isAllowedToEdit = backpack_user()->/** @scrutinizer ignore-call */ hasPermissionTo('courses.edit') ? 1 : 0;
Loading history...
35
        $mode = $request->mode ?? 'view';
36
        $student = Student::with('enrollments')->find($request->student_id) ?? collect(['']);
37
        $enrollment_id = $request->enrollment_id ?? 'none';
38
39
        return view('courses.list', compact('defaultPeriod', 'isAllowedToEdit', 'rhythms', 'levels', 'mode', 'student', 'enrollment_id'));
40
    }
41
42
    public function search()
43
    {
44
        return QueryBuilder::for(Course::class)->where('campus_id', 1)
45
        ->with('room')->withCount('events')->withCount('children')->withCount('enrollments')
46
        ->allowedFilters([
47
            'name',
48
            'period_id',
49
            'rhythm_id',
50
            AllowedFilter::custom('searchable_levels', new FiltersSearchableLevels()),
51
            'teacher_id', ])
52
        ->get();
53
    }
54
}
55