Skip to content

Commit

Permalink
Implement assignment show lists, create, store
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 3, 2020
1 parent d163860 commit c984061
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 65 deletions.
79 changes: 79 additions & 0 deletions app/Http/Controllers/AssignmentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Http\Controllers;

use App\Models\Assignment;
use App\Models\Classroom;
use Illuminate\Http\Request;

class AssignmentController extends Controller
{
public function index(Classroom $classroom) {
$assignments = Assignment::where('classroom_id', $classroom->id)->get();

return view('teacher.course.assignment', [
'classroom' => $classroom,
'assignments' => $assignments
]);
}

public function create(Classroom $classroom) {
return view('teacher.class.createassignment', [
'classroom' => $classroom
]);
}

public function createTask(Classroom $classroom) {
return view('teacher.class.createtask');
}

public function storeTask(Request $request, Classroom $classroom) {
return 'stored task';
}

public function createQuiz(Classroom $classroom) {
return view('teacher.class.createquiztest', [
'classroom' => $classroom
]);
}

public function storeQuiz(Request $request, Classroom $classroom) {
$this->validate($request, [
'title' => 'required|max:255',
'number_of_multiple_choice' => 'required|integer|max:10',
'number_of_essay' => 'required|integer|max:10',
]);

$classroom->assignments()->create([
'title' => $request->title,
'number_of_multiple_choice' => $request->number_of_multiple_choice,
'number_of_essay' => $request->number_of_essay,
'is_task' => false
]);

return redirect()->route('assignment', $classroom->id);
}

public function input(Classroom $classroom, Assignment $assignment) {
return view('teacher.class.inputtask', [
'classroom' => $classroom,
'assignment' => $assignment
]);
}

public function storeInput(Request $request) {
$this->validate($request, [
'question' => 'required'
]);

Assignment::create([
'question' => $request->question
]);

return redirect()->route('assignment');
}

public function show(Classroom $classroom) {
return 'show single task or quiz';
}
}
12 changes: 4 additions & 8 deletions app/Http/Controllers/SubjectMatterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

class SubjectMatterController extends Controller
{
public function classroom() {
return $this->belongsTo(Classroom::class);
}

public function indexSubjectMatter(Classroom $classroom) {
public function index(Classroom $classroom) {
$subjects = SubjectMatter::where('classroom_id', $classroom->id)->get();

return view('teacher.course.subjectmatter', [
Expand All @@ -21,17 +17,17 @@ public function indexSubjectMatter(Classroom $classroom) {
]);
}

public function showSubjectMatter(Classroom $classroom, SubjectMatter $subject) {
public function show(Classroom $classroom, SubjectMatter $subject) {
return "a single subjectmatter: {$subject->title}";
}

public function createSubjectMatter(Classroom $classroom) {
public function create(Classroom $classroom) {
return view('teacher.class.createsubjectmatter', [
'classroom' => $classroom
]);
}

public function storeSubjectMatter(Classroom $classroom, Request $request) {
public function store(Classroom $classroom, Request $request) {
$this->validate($request, [
'title' => 'required|max:255',
'link' => 'url',
Expand Down
32 changes: 32 additions & 0 deletions app/Models/Assignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Assignment extends Model
{
use HasFactory;

protected $fillable = [
'title',
'number_of_multiple_choice',
'number_of_essay',
'is_task',
];

protected $casts = [
'is_task' => 'boolean',
'questions' => 'array'
];

public function classroom() {
return $this->belongsTo(Classroom::class);
}

public function path() {
return "/teacher/classroom/{$this->classroom->id}/assignment/{$this->id}";
}

}
4 changes: 4 additions & 0 deletions app/Models/Classroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function subjectMatters() {
return $this->hasMany(SubjectMatter::class);
}

public function assignments() {
return $this->hasMany(Assignment::class);
}

public function teacher() {
return $this->belongsTo(Teacher::class);
}
Expand Down
38 changes: 38 additions & 0 deletions database/migrations/2020_12_03_021722_create_assignments_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAssignmentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('assignments', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->unsignedSmallInteger('number_of_multiple_choice');
$table->unsignedSmallInteger('number_of_essay');
$table->boolean('is_task');
$table->json('questions')->nullable();

$table->foreignId('classroom_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('assignments');
}
}
11 changes: 7 additions & 4 deletions resources/views/layouts/teachercourse.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
<div class="bg-gray-100 pt-7">

@yield('maincontent')

</div>
<div class="h-screen bg-white pt-6">
<div class="mb-6 text-black text-base text-center">
<a href="#">{{ auth()->guard('teacher')->user()->name }}</a>
<button class="px-1 pb-1 bg-red-500 text-white rounded hover:bg-red-600 ml-6">
<a href="#" class="text-xs">Logout</a>
<a href="{{ route('teacher.dashboard') }}">{{ auth()->guard('teacher')->user()->name }}</a>
<form action="{{ route('logout.teacher') }}" method="POST" class="inline">
@csrf
<button class="px-1 pb-1 bg-red-500 text-white rounded hover:bg-red-600 ml-6" type="submit">
Logout
</button>
</form>
</div>
</div>
</div>
Expand Down
24 changes: 12 additions & 12 deletions resources/views/teacher/class/createassignment.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('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('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('subjectmatter', $classroom->id) }}" class="text-sm">Review</a>
</button>
</div>
@endsection
Expand All @@ -22,29 +22,29 @@
<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">Pengolahan Citra Digital</h1>
<h1 class="text-sm text-blacktext-left">Wahyono, Ph.D</h1>
<p class="text-sm text-left">Universitas Gadjah Mada</p>
<h1 class="text-xl text-black text-left mb-4">{{ $classroom->class_name }}</h1>
<h1 class="text-sm text-blacktext-left">{{ auth('teacher')->user()->name }}</h1>
<p class="text-sm text-left">{{ auth('teacher')->user()->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')}}">
<img class="w-full rounded-lg" src="{{ asset('img/logo.PNG') }}">
</div>
</div>
<div class="container w-full">
<div class="my-4 text-black text-xl font-bold mx-auto w-9/12">
<h1> Select the type of assignment :</h1>
</div>

<div class="container flex flex-nowrap justify-center gap-8">
<a href="#">
<a href="{{ route('assignment.create.quiz', $classroom->id) }}">
<div class="bg-white my-6 rounded flex col justify-center items-center bg-blue-100 hover:bg-blue-300" style="width: 20rem; height: 20rem;">
<h1 class="text-black text-small font-bold">Quiz / Test</h1>
</div>
</div>
</a>
<a href="#">
<a href="{{ route('assignment.create.task', $classroom->id) }}">
<div class="bg-white my-6 rounded flex col justify-center items-center bg-green-100 hover:bg-green-300" style="width: 20rem; height: 20rem;">
<h1 class="text-black text-small font-bold">Task</h1>
</div>
</div>
</a>
</div>
</div>
Expand Down
38 changes: 19 additions & 19 deletions resources/views/teacher/class/createquiztest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@
@section('maincontent')
<div class="container">
<div class="my-4 text-black text-3xl font-bold mx-auto pl-12">
<h1> Create new Task :</h1>
<h1> Create new Quiz / Test :</h1>
</div>

<div class="container">
<div class="flex flex-wrap flex-col md:flex-row items-center my-8 pl-12 mx-auto rounded-lg">
<form action="" method="POST">
<form action="{{ route('assignment.create.quiz', $classroom->id) }}" method="POST">
@csrf
<div>
<label for="classname" class="tracking-wide text-gray text-base font-bold pb-4">Title :</label>
<label for="title" class="tracking-wide text-gray text-base font-bold pb-4">Title :</label>
</div>
<div class="mb-4">
<input type="text" name="classname" id="classname" placeholder="Input title for this task"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('classname') border-red-500 @enderror" value="{{ old('classname') }}" style="width: 32rem">
@error('classname')
<input type="text" name="title" id="title" placeholder="Input title for this task"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('title') border-red-500 @enderror" value="{{ old('title') }}" style="width: 32rem">

@error('title')
<div class="text-red-500 mt-2 text-base">
{{ $message }}
</div>
@enderror
</div>

<div>
<label for="mc" class="tracking-wide text-gray text-base font-bold pb-4">Number of Multiple Choice questions :</label>
<label for="number_of_multiple_choice" class="tracking-wide text-gray text-base font-bold pb-4">Number of Multiple Choice questions :</label>
</div>
<div class="mb-4">
<input type="number" name="mc" id="mc" placeholder="maximum: 10"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('mc') border-red-500 @enderror" value="{{ old('mc') }}" style="width: 32rem">
@error('mc')
<input type="number" name="number_of_multiple_choice" id="number_of_multiple_choice" placeholder="maximum: 10"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('number_of_multiple_choice') border-red-500 @enderror" value="{{ old('number_of_multiple_choice') }}" style="width: 32rem">

@error('number_of_multiple_choice')
<div class="text-red-500 mt-2 text-base">
{{ $message }}
</div>
@enderror
</div>

<div>
<label for="essay" class="tracking-wide text-gray text-base font-bold pb-4">Number of Essay questions :</label>
<label for="number_of_essay" class="tracking-wide text-gray text-base font-bold pb-4">Number of Essay questions :</label>
</div>
<div class="mb-4">
<input type="number" name="essay" id="essay" placeholder="maximum: 10"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('essay') border-red-500 @enderror" value="{{ old('essay') }}" style="width: 32rem">
@error('essay')
<input type="number" name="number_of_essay" id="number_of_essay" placeholder="maximum: 10"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('number_of_essay') border-red-500 @enderror" value="{{ old('number_of_essay') }}" style="width: 32rem">

@error('number_of_essay')
<div class="text-red-500 mt-2 text-base">
{{ $message }}
</div>
Expand All @@ -76,7 +76,7 @@ class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('es
<div>
<label for="endtime" class="tracking-wide text-gray text-base font-bold pb-4">End Time :</label>
</div>

<div>
<button type="submit" class="bg-green-400 text-white px-4 py-3 rounded font-medium w-20 hover:bg-green-500">Create</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/teacher/class/inputtask.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h1 class="text-xl font-bold">Input the question:</h1>
</div>
<div class="mx-auto px-6">
<form action="" method="POST">
<form action="{{ route('assignment.input', [$classroom->id, $assignment->id]) }}" method="POST">
@csrf
<div class="mb-4">
<textarea name="question" id="question" cols="70" rows="10" class="bg-gray-50 border-2 border-gray-300 py-4 px-4 rounded-lg @error('question') border-red-500 @enderror" value="{{ old('question') }}">
Expand Down
Loading

0 comments on commit c984061

Please sign in to comment.