Issues (350)

app/Http/Controllers/HRController.php (4 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Teacher;
6
use App\Traits\PeriodSelection;
7
use Carbon\Carbon;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Gate;
10
use Illuminate\Support\Facades\Log;
11
12
class HRController extends Controller
13
{
14
    use PeriodSelection;
0 ignored issues
show
The trait App\Traits\PeriodSelection requires the property $id which is not provided by App\Http\Controllers\HRController.
Loading history...
15
16
    public function __construct()
17
    {
18
        parent::__construct();
19
        $this->middleware('permission:hr.view', ['except' => 'teacher']);
20
    }
21
22
    /**
23
     * Display a listing of the resource.
24
     */
25
    public function index(Request $request)
26
    {
27
        $period = $this->selectPeriod($request);
28
29
        $teachers = Teacher::with('remote_events')->with('events')->with('courses')->get();
30
31
        $report_start_date = $request->report_start_date ? Carbon::parse($request->report_start_date) : Carbon::parse($period->start);
32
        $report_end_date = $request->report_end_date ? Carbon::parse($request->report_end_date) : Carbon::parse($period->end);
33
34
        // if we are dealing with a complete period, add theoretical volumes
35
        if (! $request->report_start_date && ! $request->report_end_date) {
36
            // ensure the report end date is not before the end date to avoid inconsistent results.
37
            $report_end_date = $report_start_date->max($report_end_date);
38
39
            foreach ($teachers as $teacher) {
40
                $teacher->remoteVolume = $teacher->courses()->realcourses()->where('period_id', $period->id)->sum('remote_volume');
0 ignored issues
show
The property remoteVolume does not seem to exist on App\Models\Teacher. 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...
41
                $teacher->volume = $teacher->courses()->realcourses()->where('period_id', $period->id)->sum('volume');
0 ignored issues
show
The property volume does not seem to exist on App\Models\Teacher. 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...
42
            }
43
        }
44
45
        Log::info('HR Dahsboard viewed by '.backpack_user()->firstname);
0 ignored issues
show
Accessing firstname on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
46
47
        return view('hr.dashboard', [
48
            'selected_period' => $period,
49
            'teachers' => $teachers,
50
            'start' => $report_start_date->format('Y-m-d'),
51
            'end' => $report_end_date->format('Y-m-d'),
52
        ]);
53
    }
54
55
    public function teacher(Request $request, Teacher $teacher)
56
    {
57
        // If the user is not allowed to perform this action
58
        if (Gate::forUser(backpack_user())->denies('view-teacher-hours', $teacher)) {
59
            abort(403);
60
        }
61
62
        $period = $this->selectPeriod($request);
63
64
        return view('teacher.hours', [
65
            'selected_period' => $period,
66
            'teacher' => $teacher,
67
            'events' => $teacher->period_events($period),
68
        ]);
69
    }
70
}
71