Skip to content

Commit c53998e

Browse files
2 parents 9a68880 + 2d74949 commit c53998e

File tree

7 files changed

+181
-212
lines changed

7 files changed

+181
-212
lines changed

DigiKaksha/app/Http/Controllers/CoursesController.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use App\User;
55
use App\Group;
66
use App\Course;
7+
use App\attendance;
78
use Illuminate\Http\Request;
89

910
class CoursesController extends Controller
@@ -96,7 +97,46 @@ public function store(Request $request)
9697
public function show($id)
9798
{
9899
$course = Course::find($id);
100+
if(auth()->user()->user_level > 1){
99101
return view('courses/show')->with('course', $course);
102+
}
103+
else{
104+
$classId = 0;
105+
$flag=0;
106+
$groups= auth()->user()->groups;
107+
foreach($groups as $group){
108+
if($flag==1)
109+
break;
110+
foreach($group->courses as $co)
111+
{
112+
if($co->id == $id){
113+
$classId = $group->id;
114+
$flag=1;
115+
break;
116+
}
117+
}
118+
}
119+
$roll=auth()->user()->roll_no;
120+
$attendances = attendance::where('course_id', $id)->where('group_id',$classId)->get();
121+
$markedAttendances = [];
122+
$present =0;
123+
$total=0;
124+
foreach($attendances as $att){
125+
$total++;
126+
$thisAtt = new \stdClass;
127+
$thisAtt->date = $att->date;
128+
$thisAtt->taker= $att->taker;
129+
$presentStudents = explode(" ", $att->present);
130+
if(array_search($roll,$presentStudents) === false){
131+
$thisAtt->present = false;
132+
}else{
133+
$present++;
134+
$thisAtt->present = true;
135+
}
136+
array_push($markedAttendances,$thisAtt);
137+
}
138+
return view('courses/show',compact('course','markedAttendances','present','total'));
139+
}
100140
}
101141

102142
/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use App\User;
5+
use App\Group;
6+
use App\Course;
7+
use App\attendance;
8+
use Illuminate\Http\Request;
9+
10+
class attendanceController extends Controller
11+
{
12+
public function processRequest(Request $request,$cid){
13+
if(auth()->user()->user_level == 1) return redirect('home');
14+
$red = "/attendance/mark/".$cid."/".$request->input("class");
15+
return redirect($red);
16+
}
17+
public function showForm(Request $request,$cid,$gid){
18+
if(auth()->user()->user_level == 1) return redirect('home');
19+
$group = Group::find($gid);
20+
return view('attendance/markAttendance',compact('group','cid','gid'));
21+
}
22+
23+
public function markAttendance(Request $request,$cid,$gid){
24+
$att = new attendance;
25+
$att->date= $request->input('date');
26+
$att->course_id= $cid;
27+
$att->group_id =$gid;
28+
$att->taker= auth()->user()->name;
29+
$group = Group::find($gid);
30+
$str="";
31+
foreach ($group->users as $student)
32+
{
33+
if($request->input($student->roll_no)){
34+
$str.=$student->roll_no." ";
35+
}
36+
}
37+
$att->present = $str;
38+
$att->save();
39+
$red = "courses/".$cid;
40+
return redirect($red)->with('status', 'Attendance Marked');
41+
}
42+
}

DigiKaksha/app/attendance.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class attendance extends Model
8+
{
9+
//
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateAttendanceTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('attendances', function (Blueprint $table) {
17+
$table->id();
18+
$table->integer('course_id');
19+
$table->integer('group_id');
20+
$table->string('present');
21+
$table->string('taker');
22+
$table->string('date');
23+
$table->timestamps();
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::dropIfExists('attendances');
35+
}
36+
}

0 commit comments

Comments
 (0)