Skip to content

Commit 9a68880

Browse files
Submissions and evaluation working
1 parent b2a86c8 commit 9a68880

File tree

9 files changed

+304
-8
lines changed

9 files changed

+304
-8
lines changed

DigiKaksha/app/Announcement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public function course()
1616
}
1717
public function submissions()
1818
{
19-
return $this->hasMany('App\Announcement');
19+
return $this->hasMany('App\Submission');
2020
}
2121
}

DigiKaksha/app/Http/Controllers/SubmissionsController.php

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function index()
2323
*/
2424
public function create()
2525
{
26-
26+
if(auth()->user()->user_level >= 2) return redirect('home');
27+
$announcement = \App\Announcement::find(\Request::get('announcement'));
28+
if(!$this->isValid($announcement)) return redirect('home');
29+
return view('submissions/create')->with('announcement', $announcement);
2730
}
2831

2932
/**
@@ -34,7 +37,19 @@ public function create()
3437
*/
3538
public function store(Request $request)
3639
{
37-
//
40+
if(auth()->user()->user_level >= 2) return redirect('home');
41+
$announcement = \App\Announcement::find($request->input('announcement'));
42+
if(!$this->isValid($announcement)) return redirect('home');
43+
foreach(auth()->user()->submissions as $submission){
44+
if($submission->announcement->id==$announcement->id)
45+
return redirect()->back()->with('status', 'A submission has already been made');
46+
}
47+
$submission = new \App\Submission();
48+
$submission->announcement_id = $request->input('announcement');
49+
$submission->body = $request->input('body');
50+
$submission->user_id = auth()->user()->id;
51+
$submission->save();
52+
return redirect('/announcements'.'/'.$announcement->id)->with('status', 'Submission done!');
3853
}
3954

4055
/**
@@ -56,7 +71,10 @@ public function show($id)
5671
*/
5772
public function edit($id)
5873
{
59-
//
74+
if(auth()->user()->user_level < 2) return redirect('home');
75+
$submission = \App\Submission::find($id);
76+
if(!$this->checkEditAccess($submission->announcement->course)) return redirect('home');
77+
return view('submissions/edit')->with('submission', $submission);
6078
}
6179

6280
/**
@@ -68,7 +86,13 @@ public function edit($id)
6886
*/
6987
public function update(Request $request, $id)
7088
{
71-
//
89+
if(auth()->user()->user_level < 2) return redirect('home');
90+
$submission = \App\Submission::find($id);
91+
if(!$this->checkEditAccess($submission->announcement->course)) return redirect('home');
92+
$submission->grade = $request->input('grade');
93+
$submission->comment = $request->input('comment');
94+
$submission->save();
95+
return redirect('/announcements'.'/'.$submission->announcement->id)->with('status', 'Submission for '.$submission->user->roll_no.' graded succesfully!');
7296
}
7397

7498
/**
@@ -81,4 +105,30 @@ public function destroy($id)
81105
{
82106
//
83107
}
108+
109+
public function isValid($announcement)
110+
{
111+
$flag = false;
112+
$course = $announcement->course;
113+
foreach(auth()->user()->groups as $group) {
114+
foreach($group->courses as $course1){
115+
if($course1->id==$course->id){
116+
$flag = true;
117+
break;
118+
}
119+
}
120+
}
121+
return $flag;
122+
}
123+
public function checkEditAccess($course)
124+
{
125+
$flag = false;
126+
foreach($course->users as $user) {
127+
if($user->id==auth()->user()->id or auth()->user()->user_level == 3){
128+
$flag = true;
129+
break;
130+
}
131+
}
132+
return $flag;
133+
}
84134
}

DigiKaksha/app/User.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ public function submissions()
5454
{
5555
return $this->hasMany('App\Submission');
5656
}
57+
public function hasSubmission($announcement){
58+
foreach($this->submissions as $submission) if($submission->announcement_id == $announcement->id) return true;
59+
return false;
60+
}
5761
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddMaxGradeAndComponentFieldToAnnouncementsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('announcements', function (Blueprint $table) {
17+
$table->integer('max_grade')->nullable();
18+
$table->string('component')->nullable();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('announcements', function (Blueprint $table) {
30+
$table->dropColumn('max_grade');
31+
$table->dropColumn('component');
32+
});
33+
}
34+
}

DigiKaksha/resources/views/announcements/show.blade.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,82 @@
1919
@endif
2020
<p>{{$announcement->body}}</p>
2121
</div>
22+
</div>
2223
@if($announcement->graded==1)
23-
<div class="card-footer">
24+
<div class="card">
2425
@if(Auth::user()->user_level==1)
26+
<div class="card-header">
27+
@if(Auth::user()->hasSubmission($announcement))
28+
@foreach(Auth::user()->submissions as $submission)
29+
@if($submission->announcement_id==$announcement->id)
30+
31+
<p><strong>Submission:</strong> <small>{{$submission->body}}</small></p>
32+
<p class="strong"><strong>Grade:</strong>
33+
@if($submission->grade)
34+
{{$submission->grade}}
35+
@else
36+
<small> No grade awarded yet</small>
37+
@endif
38+
</p>
39+
<p class="strong"><strong>Comments:</strong>
40+
@if($submission->comment)
41+
{{$submission->comment}}
42+
@else
43+
<small>No commments</small>
44+
@endif
45+
</p>
46+
@break
47+
@endif
48+
@endforeach
49+
@else
2550
@foreach(Auth::user()->groups as $group)
2651
@foreach($group->courses as $course)
2752
@if($course->id==$announcement->course->id)
28-
<a href="#!" class="btn btn-sm btn-primary">Add Submission</a>
53+
<a href="/submissions/create?announcement={{$announcement->id}}" class="btn btn-sm btn-primary">Add Submission</a>
2954
@break
3055
@endif
3156
@endforeach
3257
@endforeach
58+
@endif
59+
</div>
3360
@elseif(Auth::user()->user_level==3)
34-
<a href="#!" class="btn btn-sm btn-primary">View Submissions</a>
61+
<div class="card-header">
62+
Submissions
63+
</div>
64+
<div class="card-body">
65+
<div class="table-responsive">
66+
<table class="table align-items-center table-flush">
67+
<thead class="thead-light">
68+
<tr>
69+
<th scope="col" class="sort" data-sort="name">Roll No</th>
70+
<th scope="col" class="sort" data-sort="budget">Name</th>
71+
<th scope="col" class="sort" data-sort="completion"></th>
72+
</tr>
73+
</thead>
74+
<tbody class="list">
75+
@foreach($announcement->submissions as $submission)
76+
<tr>
77+
<th scope="row">
78+
<div class="media align-items-center">
79+
<div class="media-body">
80+
<span class="name mb-0 text-sm"><a>{{$submission->user->roll_no}}</a></span>
81+
</div>
82+
</div>
83+
</th>
84+
<td class="budget">
85+
{{$submission->user->name}}
86+
</td>
87+
<td>
88+
<div class="d-flex align-items-center">
89+
<a href="/submissions/{{$submission->id}}/edit" class="btn btn-sm btn-primary">View Submission</a>
90+
</div>
91+
</td>
92+
</tr>
93+
@endforeach
94+
</tbody>
95+
</table>
96+
</div>
97+
</div>
3598
@else
3699
@foreach(Auth::user()->courses as $course)
37100
@if($course->id==$announcement->course->id)

DigiKaksha/resources/views/layouts/app.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<link rel="stylesheet" href="../../assets/vendor/quill/dist/quill.core.css">
3131
<!-- Argon CSS -->
3232
<link rel="stylesheet" href="../../assets/css/argon.min5438.css?v=1.2.0" type="text/css">
33+
<script src="../../assets/vendor/dropzone/dist/min/dropzone.min.js"></script>
3334
<!-- Google Tag Manager -->
3435
<script>
3536
(function(w, d, s, l, i) {
@@ -108,5 +109,6 @@
108109
@yield('content')
109110
</main>
110111
</div>
112+
111113
</body>
112114
</html>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row justify-content-center">
6+
<div class="col-md-12">
7+
<div class="card">
8+
<div class="card-header">{{ __('Make Submission') }}</div>
9+
10+
<div class="card-body">
11+
@if (session('status'))
12+
<div class="alert alert-success">
13+
{{ session('status') }}
14+
</div>
15+
@endif
16+
<form method="POST" action="/submissions">
17+
@csrf
18+
19+
<div class="form-group row">
20+
<label for="announce" class="col-md-4 col-form-label text-md-right">{{ __('Announcement') }}</label>
21+
22+
<div class="col-md-8">
23+
<input id="announce" type="text" class="form-control @error('announce') is-invalid @enderror" name="announce" value="{{ $announcement->title }}" required autocomplete="announce" disabled>
24+
25+
@error('announce')
26+
<span class="invalid-feedback" role="alert">
27+
<strong>{{ $message }}</strong>
28+
</span>
29+
@enderror
30+
</div>
31+
</div>
32+
<div class="form-group row">
33+
<label for="body" class="col-md-4 col-form-label text-md-right">{{ __('Body') }}</label>
34+
35+
<div class="col-md-8">
36+
<textarea id="body" style="height:200px" type="text" class="form-control @error('body') is-invalid @enderror" name="body" value="{{ old('body') }}" required autocomplete="body"></textarea>
37+
38+
@error('body')
39+
<span class="invalid-feedback" role="alert">
40+
<strong>{{ $message }}</strong>
41+
</span>
42+
@enderror
43+
</div>
44+
</div>
45+
<input type="hidden" name="announcement" value="{{ $announcement->id }}">
46+
47+
{{-- <div class="dropzone dropzone-single form-group row" data-toggle="dropzone" data-dropzone-url="http://">
48+
<div class="fallback">
49+
<div class="custom-file">
50+
<input type="file" class="custom-file-input" id="dropzoneBasicUpload" name="file">
51+
<label class="custom-file-label" for="dropzoneBasicUpload">Choose file</label>
52+
</div>
53+
</div>
54+
</div> --}}
55+
<div class="form-group row mb-0">
56+
<div class="col-md-6 offset-md-4">
57+
<button type="submit" class="btn btn-primary">
58+
{{ __('Submit!') }}
59+
</button>
60+
</div>
61+
</div>
62+
</form>
63+
</div>
64+
</div>
65+
</div>
66+
</div>
67+
</div>
68+
@endsection
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row justify-content-center">
6+
<div class="col-md-12">
7+
<div class="card">
8+
<div class="card-header">{{ __('View Submission') }}</div>
9+
10+
<div class="card-body">
11+
@if (session('status'))
12+
<div class="alert alert-success">
13+
{{ session('status') }}
14+
</div>
15+
@endif
16+
<h5 class="display-4">{{$submission->announcement->title}}</h5>
17+
<small>by {{$submission->user->roll_no}}</small>
18+
<br><br>
19+
<p><strong>Submission: </strong>{{$submission->body}}</p>
20+
21+
<br>
22+
<form method="POST" action="/submissions/{{$submission->id}}">
23+
@csrf
24+
25+
<div class="form-group row">
26+
<label for="grade" class="col-md-2 col-form-label text-md-right">{{ __('Grade') }}</label>
27+
28+
<div class="col-md-8">
29+
<input id="grade" type="number" class="form-control @error('grade') is-invalid @enderror" name="grade" value="{{ $submission->grade }}" required autocomplete="grade" autofocus>
30+
31+
@error('grade')
32+
<span class="invalid-feedback" role="alert">
33+
<strong>{{ $message }}</strong>
34+
</span>
35+
@enderror
36+
</div>
37+
</div>
38+
<div class="form-group row">
39+
<label for="comment" class="col-md-2 col-form-label text-md-right">{{ __('Comment') }}</label>
40+
41+
<div class="col-md-8">
42+
<textarea id="comment" style="height:200px" type="text" class="form-control @error('comment') is-invalid @enderror" name="comment" value="{{ $submission->body }}" required autocomplete="comment"></textarea>
43+
44+
@error('comment')
45+
<span class="invalid-feedback" role="alert">
46+
<strong>{{ $message }}</strong>
47+
</span>
48+
@enderror
49+
</div>
50+
</div>
51+
<input type="hidden" name="_method" value="put">
52+
53+
{{-- <div class="dropzone dropzone-single form-group row" data-toggle="dropzone" data-dropzone-url="http://">
54+
<div class="fallback">
55+
<div class="custom-file">
56+
<input type="file" class="custom-file-input" id="dropzoneBasicUpload" name="file">
57+
<label class="custom-file-label" for="dropzoneBasicUpload">Choose file</label>
58+
</div>
59+
</div>
60+
</div> --}}
61+
<div class="form-group row mb-0">
62+
<div class="col-md-8 offset-md-5">
63+
<button type="submit" class="btn btn-primary">
64+
{{ __('Submit!') }}
65+
</button>
66+
</div>
67+
</div>
68+
</form>
69+
</div>
70+
</div>
71+
</div>
72+
</div>
73+
</div>
74+
@endsection

DigiKaksha/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
Route::resource('teachers', 'TeachersController');
3232
Route::resource('admins', 'AdminsController');
3333
Route::resource('announcements', 'AnnouncementsController');
34+
Route::resource('submissions', 'SubmissionsController');
3435

0 commit comments

Comments
 (0)