|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Judite\Models\Group; |
|
6
|
|
|
use App\Judite\Models\Course; |
|
7
|
|
|
use Illuminate\Support\Facades\DB; |
|
8
|
|
|
use App\Http\Controllers\Controller; |
|
9
|
|
|
|
|
10
|
|
|
class GroupController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Create a new controller instance. |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->middleware('auth'); |
|
18
|
|
|
$this->middleware('can.admin'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Display a listing of the resource. |
|
23
|
|
|
* |
|
24
|
|
|
* @return \Illuminate\Http\Response |
|
25
|
|
|
*/ |
|
26
|
|
|
public function index() |
|
27
|
|
|
{ |
|
28
|
|
|
$courses = DB::transaction(function () { |
|
29
|
|
|
return Course::orderedList()->get(); |
|
30
|
|
|
}); |
|
31
|
|
|
|
|
32
|
|
|
$courses = $courses->groupBy(function ($course) { |
|
33
|
|
|
return $course->present()->getOrdinalYear(); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
return view('admin.groups.index', compact('courses')); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Display the specified resource. |
|
41
|
|
|
* |
|
42
|
|
|
* @param int $id |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Illuminate\Http\Response |
|
45
|
|
|
*/ |
|
46
|
|
|
public function show($courseId) |
|
47
|
|
|
{ |
|
48
|
|
|
$groups = Group::whereCourseId($courseId)->get(); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($groups as $group) { |
|
51
|
|
|
$memberships = $group->memberships()->get(); |
|
52
|
|
|
|
|
53
|
|
|
$students = []; |
|
54
|
|
|
foreach ($memberships as $membershipKey => $membership) { |
|
55
|
|
|
$student = $membership->student()->first(); |
|
56
|
|
|
$student->name = $student->user()->first()->name; |
|
57
|
|
|
array_push($students, $student); |
|
58
|
|
|
} |
|
59
|
|
|
$group->students = $students; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return view('admin.groups.show', compact('groups')); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|