-
Notifications
You must be signed in to change notification settings - Fork 11
/
HomeController.php
102 lines (89 loc) · 2.71 KB
/
HomeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace App\Http\Controllers;
use App\Course;
use App\Department;
use App\Student;
use App\User;
use App\UserSetting;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function index(User $user, Course $course, Department $department, UserSetting $userSetting)
{
if(auth()->user()->user_type != 1 && auth()->user()->user_type != 2){
return view('auth.login');
}
$courses = $course->viewAll();
$users = $user->viewAll();
$departments = $department->viewAll();
$admin = array();
$student = array();
$professor = array();
$data = array();
$adminCount = 0;
$studentCount = 0;
$professorCount = 0;
$courseCount = $course->count();
foreach ($users as $user){
if ($user->user_type == 1 || $user->user_type == 2){
foreach ($departments as $department){
if($department->id == $user->department_id){
$user->department = $department->name;
}
}
$admin[] = $user;
$adminCount++;
}
elseif ($user->user_type == 3){
foreach ($departments as $department){
if($department->id == $user->department_id){
$user->department = $department->name;
}
}
$student[] = $user;
$studentCount++;
}
elseif ($user->user_type == 4){
foreach ($departments as $department){
if($department->id == $user->department_id){
$user->department = $department->name;
}
}
$professor[] = $user;
$professorCount++;
}
}
$data = [
'courses' => $courses,
'student' => $student,
'admin' => $admin,
'professor' => $professor,
'adminCount' => $adminCount,
'studentCount' => $studentCount,
'professorCount' => $professorCount,
'courseCount' => $courseCount,
];
return view('home')->with('data',$data);
}
public function collectAuthUser()
{
return apiSuccess(auth()->id());
}
public function studentHome()
{
return view('studentHome', ['id' => auth()->user()->identification_no,]);
}
public function test()
{
return view('welcome');
}
}