diff --git a/app/Http/Controllers/Admin/AdminAttendancesController.php b/app/Http/Controllers/Admin/AdminAttendancesController.php index 1743f2a..bb2def8 100644 --- a/app/Http/Controllers/Admin/AdminAttendancesController.php +++ b/app/Http/Controllers/Admin/AdminAttendancesController.php @@ -4,9 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\User; -use App\Subject; -use App\Room; + use App\Classes; use App\Attendance; diff --git a/app/Http/Controllers/Admin/AdminClassesController.php b/app/Http/Controllers/Admin/AdminClassesController.php index 41431b6..8885d39 100644 --- a/app/Http/Controllers/Admin/AdminClassesController.php +++ b/app/Http/Controllers/Admin/AdminClassesController.php @@ -4,11 +4,9 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\User; + use App\Subject; -use App\Room; use App\Classes; -use App\Attendance; class AdminClassesController extends Controller { diff --git a/app/Http/Controllers/Admin/AdminSubjectsController.php b/app/Http/Controllers/Admin/AdminSubjectsController.php index d075c2b..13b8191 100644 --- a/app/Http/Controllers/Admin/AdminSubjectsController.php +++ b/app/Http/Controllers/Admin/AdminSubjectsController.php @@ -4,11 +4,11 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; + use App\User; use App\Subject; use App\Room; -use App\Classes; -use App\Attendance; + class AdminSubjectsController extends Controller { diff --git a/app/Http/Controllers/User/UserAttendancesController.php b/app/Http/Controllers/User/UserAttendancesController.php new file mode 100644 index 0000000..3eb9c73 --- /dev/null +++ b/app/Http/Controllers/User/UserAttendancesController.php @@ -0,0 +1,53 @@ +get(); + $subjects_ids = $subjects->pluck('id')->toArray(); + $classes = Classes::whereIn('subject_id', $subjects_ids)->get(); + $classes_ids = $classes->pluck('id')->toArray(); + $attendances = Attendance::whereIn('classes_id', $classes_ids)->get(); + $attendances_grouped = $attendances->groupBy($groupBy); + return view('user.user_attendances', ['attendances' => $attendances, 'attendances_grouped' => $attendances_grouped, 'classes' => $classes, 'grouped_by' => $groupBy]); + } + + public function add_attendance($user_id, Request $request) + { + $classes_id = $request->input('classes_id'); + $student_id_number = $request->input('student_id'); + $student_name = $request->input('student_name'); + $student_surname = $request->input('student_surname'); + $seat_number = $request->input('seat_number'); + Attendance::create([ + 'classes_id' => $classes_id, + 'student_id_number' => $student_id_number, + 'student_name' => $student_name, + 'student_surname' => $student_surname, + 'seat_number' => $seat_number, + ]); + return redirect(route('user_attendances', [$user_id, 'classes_id'])); + } + + public function delete_attendance($user_id, $attendance_id, $groupBy) + { + Attendance::find($attendance_id)->delete(); + return redirect(route('user_attendances', [$user_id, $groupBy])); + } + + public function edit_attendance($user_id, $attendance_id, $groupBy) + { + Attendance::find($attendance_id); + return redirect(route('user_attendances', [$user_id, $groupBy])); + } +} diff --git a/app/Http/Controllers/User/UserClassesController.php b/app/Http/Controllers/User/UserClassesController.php new file mode 100644 index 0000000..874fa99 --- /dev/null +++ b/app/Http/Controllers/User/UserClassesController.php @@ -0,0 +1,44 @@ +get(); + $subjects_ids = $subjects->pluck('id')->toArray(); + $classes = Classes::whereIn('subject_id', $subjects_ids)->get(); + $classes_grouped = $classes->groupBy($groupBy); + return view('user.user_classes', ['classes' => $classes, 'classes_grouped' => $classes_grouped, 'subjects' => $subjects, 'grouped_by' => $groupBy]); + } + + public function add_classes($user_id, Request $request) + { + $subject_id = $request->input('subject_id'); + $date = $request->input('date'); + Classes::create([ + 'subject_id' => $subject_id, + 'date' => $date + ]); + return redirect(route('user_classes', [$user_id, 'name'])); + } + + public function delete_classes($user_id, $classes_id, $groupBy) + { + Classes::find($classes_id)->delete(); + return redirect(route('user_classes', [$user_id, $groupBy])); + } + + public function edit_classes($user_id, $classes_id, $groupBy) + { + Classes::find($classes_id); + return redirect(route('user_classes', [$user_id, $groupBy])); + } +} diff --git a/app/Http/Controllers/User/UserSubjectsController.php b/app/Http/Controllers/User/UserSubjectsController.php new file mode 100644 index 0000000..02431a5 --- /dev/null +++ b/app/Http/Controllers/User/UserSubjectsController.php @@ -0,0 +1,55 @@ +get(); + $subjects_grouped = $subjects->groupBy($groupBy); + $rooms = Room::all(); + $weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; + $types = ['Lecture', 'Excercises', 'Labs', 'Other']; + return view('user.user_subjects', ['subjects' => $subjects, 'rooms' => $rooms, 'weekdays' => $weekdays, + 'types' => $types, 'subjects_grouped' => $subjects_grouped, 'grouped_by' => $groupBy]); + } + + public function add_subject($user_id, Request $request) + { + $name = $request->input('name'); + $type = $request->input('type'); + $weekday = $request->input('weekday'); + $time = $request->input('time'); + $room_id = $request->input('room_id'); + $user_id_n = $user_id; + Subject::create([ + 'name' => $name, + 'type' => $type, + 'weekday'=> $weekday, + 'time' => $time, + 'room_id' => $room_id, + 'user_id' => $user_id_n + ]); + return redirect(route('user_subjects', [$user_id, 'weekday'])); + } + + public function delete_subject($user_id, $subject_id, $groupBy) + { + Subject::find($subject_id)->delete(); + return redirect(route('user_subjects', [$user_id, $groupBy])); + } + + public function edit_subject($user_id, $subject_id, $groupBy) + { + Subject::find($subject_id); + return redirect(route('user_subjects', [$user_id, $groupBy])); + } +} diff --git a/database/seeds/AttendancesTableSeeder.php b/database/seeds/AttendancesTableSeeder.php new file mode 100644 index 0000000..5d18782 --- /dev/null +++ b/database/seeds/AttendancesTableSeeder.php @@ -0,0 +1,30 @@ +insert([ + 'classes_id' => 1, + 'student_id_number' => '416010', + 'student_name' => 'Joanna', + 'student_surname' => 'Paliwoda', + 'seat_number' => 13 + ]); + + DB::table('attendances')->insert([ + 'classes_id' => 1, + 'student_id_number' => '416111', + 'student_name' => 'Piotr', + 'student_surname' => 'Nowak', + 'seat_number' => 6 + ]); + } +} diff --git a/database/seeds/ClassesTableSeeder.php b/database/seeds/ClassesTableSeeder.php new file mode 100644 index 0000000..cb2d9a3 --- /dev/null +++ b/database/seeds/ClassesTableSeeder.php @@ -0,0 +1,24 @@ +insert([ + 'subject_id' => 1, + 'date' => '2019-12-02', + ]); + + DB::table('classes')->insert([ + 'subject_id' => 2, + 'date' => '2019-12-02', + ]); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index ae42e5a..ae23538 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,43 +11,13 @@ class DatabaseSeeder extends Seeder */ public function run() { - DB::table('users')->insert([ - 'name' => 'admin', - 'surname' => 'main', - 'email' => 'admin@admin.com', - 'password' => bcrypt('pass1234'), - 'is_Admin' => true - ]); - DB::table('users')->insert([ - 'name' => 'test', - 'surname' => 'user', - 'email' => 'test@test.com', - 'password' => bcrypt('test1234'), - 'is_Admin' => false - ]); - $this->call([ + UsersTableSeeder::class, RoomsTableSeeder::class, + SubjectsTableSeeder::class, + ClassesTableSeeder::class, + AttendancesTableSeeder::class, ]); - DB::table('subjects')->insert([ - 'name' => 'Systemy Informatyczne UA0', - 'type' => 'Excercises', - 'weekday' => 'Monday', - 'time' => '17:15', - 'room_id' => 1, - 'user_id' => 2 - ]); - DB::table('classes')->insert([ - 'subject_id' => 1, - 'date' => '2019-12-02', - ]); - DB::table('attendances')->insert([ - 'classes_id' => 1, - 'student_id_number' => '416010', - 'student_name' => 'Joanna', - 'student_surname' => 'Paliwoda', - 'seat_number' => 13 - ]); } } diff --git a/database/seeds/SubjectsTableSeeder.php b/database/seeds/SubjectsTableSeeder.php new file mode 100644 index 0000000..c4dc0ca --- /dev/null +++ b/database/seeds/SubjectsTableSeeder.php @@ -0,0 +1,32 @@ +insert([ + 'name' => 'Systemy Informatyczne UA0', + 'type' => 'Lecture', + 'weekday' => 'Monday', + 'time' => '15:30', + 'room_id' => 32, + 'user_id' => 2 + ]); + + DB::table('subjects')->insert([ + 'name' => 'Systemy Informatyczne UA0', + 'type' => 'Excercises', + 'weekday' => 'Monday', + 'time' => '17:15', + 'room_id' => 7, + 'user_id' => 3 + ]); + } +} diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php new file mode 100644 index 0000000..677677a --- /dev/null +++ b/database/seeds/UsersTableSeeder.php @@ -0,0 +1,38 @@ +insert([ + 'name' => 'admin', + 'surname' => 'main', + 'email' => 'admin@admin.com', + 'password' => bcrypt('pass1234'), + 'is_Admin' => true + ]); + + DB::table('users')->insert([ + 'name' => 'Krzysztof', + 'surname' => 'Jassem', + 'email' => 'krzysztof@jassem.com', + 'password' => bcrypt('pass1234'), + 'is_Admin' => false + ]); + + DB::table('users')->insert([ + 'name' => 'Jan ', + 'surname' => 'Kowalski', + 'email' => 'jan@kowalski.com', + 'password' => bcrypt('pass1234'), + 'is_Admin' => false + ]); + } +} diff --git a/resources/views/admin/admin_attendances.blade.php b/resources/views/admin/admin_attendances.blade.php index de36200..f745dbf 100644 --- a/resources/views/admin/admin_attendances.blade.php +++ b/resources/views/admin/admin_attendances.blade.php @@ -45,7 +45,7 @@