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; |
|
|
|
|
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
|
|
|
|