Skip to content

Commit

Permalink
implement student assignment feature and answering
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 3, 2020
1 parent ac373b5 commit 3f2a514
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
32 changes: 29 additions & 3 deletions app/Http/Controllers/AssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ class AssignmentController extends Controller
public function index(Classroom $classroom) {
$assignments = Assignment::where('classroom_id', $classroom->id)->get();

return view('teacher.course.assignment', [
if (auth('student')->check()) {
$view = 'student.course.assignment';
} else {
$view = 'teacher.course.assignment';
}

return view($view, [
'classroom' => $classroom,
'assignments' => $assignments
]);
Expand Down Expand Up @@ -88,7 +94,27 @@ public function storeInput(Request $request, $classroom, $assignment) {
return redirect()->route('teacher.assignment', [$classroom]);
}

public function show(Classroom $classroom) {
return 'show single task or quiz';
public function show(Classroom $classroom, Assignment $assignment) {
if (auth('student')->check()) {
$view = 'student.class.task';
} else {
$view = 'teacher.class.task';
}

$questions = $assignment->questions;

return view($view, [
'classroom' => $classroom,
'assignment' => $assignment,
'questions' => $questions
]);
}

public function answer(Request $request, Classroom $classroom) {
$this->validate($request, [
'answer' => 'required|max:255'
]);

return redirect()->route('student.assignment', $classroom->id);
}
}
6 changes: 3 additions & 3 deletions resources/views/student/class/task.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="flex flex-col container w-5/6 mx-auto my-4 py-8 px-16 border-2 border-gray-100 gap-4">
<div class="text-center">
<h1 class="text-2xl bg-gray-50 font-bold mx-auto py-4">Task1</h1>
<h1 class="text-2xl bg-gray-50 font-bold mx-auto py-4">{{ $assignment->title }}</h1>
</div>
<div class="flex flex-row gap-4">
<div class="bg-gray-50 w-1/3 h-full">
Expand All @@ -22,8 +22,8 @@
<h1 class="text-xl font-bold">Question:</h1>
</div>
<div class="mx-auto px-6">
<p class="text-base mb-4">Task Test 123</p>
<form action="" method="POST">
<p class="text-base mb-4">{{ $questions[0]['question'] }}</p>
<form action="{{ route('student.assignment.show', [$classroom->id, $assignment->id]) }}" method="POST">
@csrf
<div class="mb-4">
<textarea name="answer" id="answer" cols="70" rows="10" class="bg-gray-50 border-2 border-gray-300 py-4 px-4 rounded-lg @error('answer') border-red-500 @enderror" value="{{ old('answer') }}">
Expand Down
28 changes: 16 additions & 12 deletions resources/views/student/course/assignment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
@section('nav')
<div class="text-center my-2">
<button class="py-1 px-9 bg-white text-gray-300 rounded">
<a href="#" class="text-sm">Subject Matter</a>
<a href="{{ route('student.subjectmatter', $classroom->id) }}" class="text-sm">Subject Matter</a>
</button>
</div>
<div class="text-center my-2 border-r-2 border-blue-500">
<button class="py-1 px-9 bg-white text-black rounded">
<a href="#" class="text-sm">Assignment</a>
<a href="{{ route('student.assignment', $classroom->id) }}" class="text-sm">Assignment</a>
</button>
</div>
<div class="text-center my-2">
<button class="py-1 px-9 bg-white text-gray-300 rounded">
<a href="#" class="text-sm">Review</a>
<a href="{{ route('student.review', $classroom->id) }}" class="text-sm">Review</a>
</button>
</div>
@endsection
Expand All @@ -22,9 +22,9 @@
<div class="container">
<div class="flex flex-wrap flex-col md:flex-row items-center bg-white mt-2 mb-10 w-9/12 mx-auto rounded-lg">
<div class="flex flex-col xl:w-2/5 overflow-y-hidden lg:items-start pl-4">
<h1 class="text-xl text-black text-left mb-4">Pemrograman</h1>
<h1 class="text-sm text-blacktext-left">Melati</h1>
<p class="text-sm text-left">SMAN 8 Jogja</p>
<h1 class="text-xl text-black text-left mb-4">{{ $classroom->class_name }}</h1>
<h1 class="text-sm text-blacktext-left">{{ $classroom->teacher->name }}</h1>
<p class="text-sm text-left">{{ $classroom->teacher->school_name }}</p>
</div>
<div class="xl:w-3/5 overflow-y-hidden rounded-lg">
<img class="w-full rounded-lg" src="{{asset('img/logo.PNG')}}">
Expand All @@ -34,12 +34,16 @@
<div class="my-4 text-black text-xl font-bold mx-auto w-9/12">
<h1>Assignment :</h1>
</div>
<a href="#">
<div class="bg-white w-9/12 mx-auto my-6 rounded flex border-2 hover:border-gray-600">
<h1 class="text-black text-base w-9/12 px-4 py-4">Task1</h1>
<h1 class="text-black text-small italic font-bold w-3/12 bg-gray-200 px-4 py-4">Available</h1>
</div>
</a>

@foreach ($assignments as $assignment)
<a href="{{ route('student.assignment.show', [$classroom->id, $assignment->id]) }}">
<div class="bg-white w-9/12 mx-auto my-6 rounded flex border-2 hover:border-gray-600">
<h1 class="text-black text-base w-9/12 px-4 py-4">{{ $assignment->title }}</h1>
<h1 class="text-black text-small italic font-bold w-3/12 bg-gray-200 px-4 py-4">Available</h1>
</div>
</a>
@endforeach

</div>
</div>
@endsection
7 changes: 0 additions & 7 deletions resources/views/student/course/subjectmatter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
</div>
</div>
<div class="container w-full">
<a href="{{ route('student.subjectmatter.create', $classroom->id) }}">
<div class="bg-white w-4/12 mx-auto my-6 rounded flex bg-gray-200 hover:bg-gray-300">
<h1 class="text-black text-base w-10/12 px-4 py-4">Create New Subject Matter</h1>
<h1 class="text-black text-base italic font-extrabold w-2/12 px-4 py-4">+</h1>
</div>
</a>

<div class="my-4 text-black text-xl font-bold mx-auto w-9/12">
<h1>Subject Matter :</h1>
</div>
Expand Down
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
Route::get('/student/classroom/{classroom}/subject-matter/{subject}', [SubjectMatterController::class, 'show'])->name('student.subjectmatter.show');

Route::get('/student/classroom/{classroom}/assignment', [AssignmentController::class, 'index'])->name('student.assignment');
Route::get('/student/classroom/{classroom}/assignment/{assignment}', [AssignmentController::class, 'show']);
Route::get('/student/classroom/{classroom}/assignment/{assignment}', [AssignmentController::class, 'show'])->name('student.assignment.show');
Route::post('/student/classroom/{classroom}/assignment/{assignment}', [AssignmentController::class, 'answer']);

Route::get('/student/classroom/{classroom}/review', [ReviewController::class, 'index'])->name('student.review');
});
Expand Down

0 comments on commit 3f2a514

Please sign in to comment.