Skip to content

Commit

Permalink
WIP for showing assignments and review placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 3, 2020
1 parent 372f7f4 commit ac373b5
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 51 deletions.
39 changes: 35 additions & 4 deletions app/Http/Controllers/SubjectMatterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@ class SubjectMatterController extends Controller
public function index(Classroom $classroom) {
$subjects = SubjectMatter::where('classroom_id', $classroom->id)->get();

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

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

public function show(Classroom $classroom, SubjectMatter $subject) {
return "a single subjectmatter: {$subject->title}";
if (auth('student')->check()) {
$view = 'student.class.subjectmatter';
} else {
$view = 'teacher.class.subjectmatter';
}

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

public function create(Classroom $classroom) {
Expand All @@ -30,16 +45,32 @@ public function create(Classroom $classroom) {
public function store(Classroom $classroom, Request $request) {
$this->validate($request, [
'title' => 'required|max:255',
'link' => 'url',
'videolink' => 'url',
'content' => 'required'
]);

$videolink = $this->getYoutubeEmbedUrl($request->videolink);

$classroom->subjectMatters()->create([
'title' => $request->title,
'link' => $request->link,
'url' => $videolink,
'content' => $request->content
]);

return redirect()->route('teacher.subjectmatter', $classroom->id);
}

private function getYoutubeEmbedUrl($url) {
$shortUrlRegex = '/youtu.be\/([a-zA-Z0-9_-]+)\??/i';
$longUrlRegex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))([a-zA-Z0-9_-]+)/i';

if (preg_match($longUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}

if (preg_match($shortUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
return 'https://www.youtube.com/embed/' . $youtube_id ;
}
}
20 changes: 13 additions & 7 deletions resources/views/layouts/class.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@
<div class="container mx-auto flex justify-between">
<ul class="flex items-center">
<li>
<a href="{{ route('teacher.subjectmatter', [$classroom->id]) }}" class="text-gray-400 hover:text-black">
Back to Class
</a>
@if (auth('student')->check())
<a href="#" class="text-gray-400 hover:text-black">
Back to Class
</a>
@else
<a href="{{ route('teacher.subjectmatter', [$classroom->id]) }}" class="text-gray-400 hover:text-black">
Back to Class
</a>
@endif
</li>
</ul>
<ul class="flex items-center">
@if (auth('student')->check())
<li>
<a href="/" class="p-3 mr-4 text-base text-black">{{ auth('student')->user()->name }}</a>
<a href="{{ route('student.dashboard') }}" class="p-3 mr-4 text-base text-black">{{ auth('student')->user()->name }}</a>
</li>
<li>
<form action="/" method="post" class="inline p-3 text-white bg-red-500 rounded hover:bg-red-700">
<form action="{{ route('logout.student') }}" method="post" class="inline p-3 text-white bg-red-500 rounded hover:bg-red-700">
@csrf
<button type="submit">Logout</button>
</form>
</li>
@elseif (auth('teacher')->check())
<li>
<a href="/" class="p-3 mr-4 text-base text-black">{{ auth('teacher')->user()->name }}</a>
<a href="{{ route('teacher.dashboard') }}" class="p-3 mr-4 text-base text-black">{{ auth('teacher')->user()->name }}</a>
</li>
<li>
<form action="/" method="post" class="inline p-3 text-white bg-red-500 rounded hover:bg-red-700">
<form action="{{ route('logout.teacher') }}" method="post" class="inline p-3 text-white bg-red-500 rounded hover:bg-red-700">
@csrf
<button type="submit">Logout</button>
</form>
Expand Down
16 changes: 7 additions & 9 deletions resources/views/student/class/subjectmatter.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@extends('layouts.class')

@section('maincontent')

<div class="flex flex-col container w-4/6 mx-auto my-4 py-8 px-16 border-4 border-gray-100">
<h1 class="text-4xl font-bold mx-auto mb-12">Test</h1>
<iframe class="mx-auto mb-16" width="720" height="405" src="https://www.youtube.com/embed/gGGPTskb7c8">
</iframe>
<div class="mx-auto" style="width: 720px;">
<p class="text-xl">Lorem ipsum dolor sit amet</p>
<div class="flex flex-col container w-4/6 mx-auto my-4 py-8 px-16 border-4 border-gray-100">
<h1 class="text-4xl font-bold mx-auto mb-12">{{ $subject->title }}</h1>
<iframe class="mx-auto mb-16" width="720" height="405" src="{{ $subject->url }}">
</iframe>
<div class="mx-auto" style="width: 720px;">
<p class="text-xl">Lorem ipsum dolor sit amet</p>
</div>
</div>
</div>

@endsection
31 changes: 20 additions & 11 deletions resources/views/student/course/subjectmatter.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 border-r-2 border-blue-500">
<button class="py-1 px-9 bg-white text-black 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">
<button class="py-1 px-9 bg-white text-gray-300 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,24 +22,33 @@
<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')}}">
</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>

<a href="#">
<div class="bg-white w-9/12 mx-auto px-4 py-4 my-6 rounded border-2 hover:border-gray-600">
<h1 class="text-black text-base italic">Test</h1>
</div>
</a>
@foreach ($subjects as $subject)
<a href="{{ route('student.subjectmatter.show', [$classroom->id, $subject->id]) }}">
<div class="bg-white w-9/12 mx-auto px-4 py-4 my-6 rounded border-2 hover:border-gray-600">
<h1 class="text-black text-base italic">{{ $subject->title }}</h1>
</div>
</a>
@endforeach
</div>
</div>
@endsection
2 changes: 1 addition & 1 deletion resources/views/student/home/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="container w-full">
@if ($classrooms->count())
@foreach ($classrooms as $classroom)
<a href="#">
<a href="{{ route('student.subjectmatter', $classroom->id) }}">
<div class="flex flex-wrap flex-col md:flex-row items-center bg-white my-8 w-9/12 mx-auto rounded-lg border-2 hover:border-gray-600">
<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">{{ $classroom->class_name }}</h1>
Expand Down
12 changes: 12 additions & 0 deletions resources/views/teacher/class/subjectmatter.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@extends('layouts.class')

@section('maincontent')
<div class="flex flex-col container w-4/6 mx-auto my-4 py-8 px-16 border-4 border-gray-100">
<h1 class="text-4xl font-bold mx-auto mb-12">{{ $subject->title }}</h1>
<iframe class="mx-auto mb-16" width="720" height="405" src="{{ $subject->url }}">
</iframe>
<div class="mx-auto" style="width: 720px;">
<p class="text-xl">Lorem ipsum dolor sit amet</p>
</div>
</div>
@endsection
4 changes: 2 additions & 2 deletions resources/views/teacher/course/assignment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<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">{{ $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>
<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 Down
4 changes: 2 additions & 2 deletions resources/views/teacher/course/subjectmatter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<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">{{ $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>
<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 Down
19 changes: 4 additions & 15 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,10 @@
Route::get('/student/classroom/{classroom}/subject-matter', [SubjectMatterController::class, 'index'])->name('student.subjectmatter');
Route::get('/student/classroom/{classroom}/subject-matter/{subject}', [SubjectMatterController::class, 'show'])->name('student.subjectmatter.show');

Route::get('/student/subjectmatter', function () {
return view('student.course.subjectmatter');
});
Route::get('/student/subjectmatter/Test', function () {
return view('student.class.subjectmatter');
});
Route::get('/student/assignment', function () {
return view('student.course.assignment');
});
Route::get('/student/assignment/Task1', function () {
return view('student.class.task');
});
Route::get('/student/review', function () {
return view('student.course.review');
});
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}/review', [ReviewController::class, 'index'])->name('student.review');
});

Route::middleware('auth.teacher')->group(function () {
Expand Down

0 comments on commit ac373b5

Please sign in to comment.