Issues (350)

Controllers/CourseSkillEvaluationController.php (4 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Course;
6
use App\Models\Enrollment;
7
use App\Models\Result;
8
use App\Models\ResultType;
9
use App\Models\Skills\SkillEvaluation;
10
use App\Models\Skills\SkillScale;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Facades\Gate;
13
14
class CourseSkillEvaluationController extends Controller
15
{
16
    /**
17
     * Show the skills overview for all students in the course.
18
     */
19
    public function index(Course $course)
20
    {
21
        if (Gate::forUser(backpack_user())->denies('view-course', $course)) {
22
            abort(403);
23
        }
24
25
        $skills = $course->skills->groupBy('skill_type_id');
0 ignored issues
show
The property skills does not seem to exist on App\Models\Course. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
26
        $enrollments = $course->enrollments()->with('skill_evaluations')->get();
27
28
        // get skill evaluations for the course
29
        $skill_evaluations = $course->skill_evaluations;
0 ignored issues
show
The property skill_evaluations does not seem to exist on App\Models\Course. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
30
31
        return view('skills.students', compact('course', 'skills', 'skill_evaluations', 'enrollments'));
32
    }
33
34
    /**
35
     * Store a skill evaluation record for a student.
36
     */
37
    public function store(Request $request)
38
    {
39
        $skill = $request->input('skill');
40
        $status = $request->input('status');
41
        $enrollment = Enrollment::findOrFail($request->input('enrollment_id'));
42
43
        if (Gate::forUser(backpack_user())->denies('view-course', $enrollment->course)) {
44
            abort(403);
45
        }
46
47
        $new_skill = SkillEvaluation::firstOrNew([
48
            'enrollment_id' => $enrollment->id,
49
            'skill_id' => $skill,
50
        ]);
51
52
        $new_skill->skill_scale_id = $status;
53
        $new_skill->save();
54
55
        return $new_skill->skill_scale_id;
56
    }
57
58
    /**
59
     * Show the form for editing a specific student's skills for the specified course.
60
     */
61
    public function edit(Enrollment $enrollment)
62
    {
63
        if (Gate::forUser(backpack_user())->denies('view-enrollment', $enrollment)) {
64
            abort(403);
65
        }
66
67
        $student_skills = $enrollment->skill_evaluations;
68
69
        $course = Course::with('evaluationType')->find($enrollment->course_id);
70
71
        $skills = $course->skills->map(function ($skill, $key) use ($student_skills) {
0 ignored issues
show
The parameter $key 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

71
        $skills = $course->skills->map(function ($skill, /** @scrutinizer ignore-unused */ $key) use ($student_skills) {

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...
The property skills does not seem to exist on App\Models\Course. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
72
            $skill['status'] = $student_skills->where('skill_id', $skill->id)->first()->skill_scale_id ?? null;
73
74
            return $skill;
75
        })->groupBy('skill_type_id');
76
77
        $result = Result::where(['enrollment_id' => $enrollment->id])->with('result_name')->first();
78
79
        $results = ResultType::all();
80
        $skillScales = SkillScale::orderBy('value')->get();
81
        $writeaccess = config('settings.teachers_can_edit_result') || backpack_user()->can('enrollments.edit') ?? 0;
82
83
        return view('skills.student', compact('enrollment', 'skills', 'skillScales', 'result', 'enrollment', 'results', 'writeaccess'));
84
    }
85
}
86