Skip to content

Commit

Permalink
saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Omkar Rajaram Gaikwad committed Apr 6, 2021
1 parent b52fa0f commit 0599e73
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:ApTlbDSyUHqEMVHgnjcypIT9iN53oyspYLRORJFqReg=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://127.0.0.1:8000

LOG_CHANNEL=stack
LOG_LEVEL=debug
Expand Down
28 changes: 8 additions & 20 deletions app/Http/Controllers/CollegeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use SebastianBergmann\Environment\Console;

class CollegeController extends Controller
{
Expand All @@ -32,14 +30,12 @@ public function update(Request $request)
$college = College::find($college_id);

$stamp = $request->file('stamp');
$stamp_extension = $stamp->getClientOriginalExtension();
$logo = $request->file('logo');
$logo_extension = $logo->getClientOriginalExtension();
$logo_hash = strval(Hash::make($request->file('logo')->getClientOriginalName()));

$stamp_hash = strval(Hash::make($request->file('stamp')->getClientOriginalName()));
Storage::disk('public')->put($logo_hash. '.' . $stamp_extension, File::get($stamp));
Storage::disk('public')->put($stamp_hash. '.' . $logo_extension, File::get($logo));
$logo_hash = strval(Carbon::now()->toTimeString().'_'.$logo->getClientOriginalName());
$stamp_hash = strval(Carbon::now()->toTimeString().'_'.$stamp->getClientOriginalName());
// storing file in storage
Storage::disk('public')->put($logo_hash, File::get($stamp));
Storage::disk('public')->put($stamp_hash, File::get($logo));

$college->address = $request->address;
$college->logo = $logo_hash;
Expand All @@ -56,19 +52,11 @@ public function show(Request $request){

$college_id = $request->user()->colleges->sortByDesc('updated_id')->first()->id;
$college = College::find($college_id);
$name = $college->name;
$logo = $college->logo;
$stamp = $college->stamp;
$address = $college->address;
$logoPath = Storage::disk('public')->get($logo.'.png');
$stampPath = Storage::disk('public')->get($stamp.'.png');

$response_college = [];

$response_college["address"] = $address;
$response_college["logo"] = $logoPath;
$response_college["stamp"] = $stampPath;

$response_college["logo"] = asset('storage/'.$college->logo);
$response_college["stamp"] = asset('storage/'.$college->stamp);
$response_college["address"] = $college->address;
return response()->json($response_college);

}
Expand Down
117 changes: 38 additions & 79 deletions app/Http/Controllers/ResultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Exam;
use App\Models\Mark;
use App\Models\Result;
use App\Models\Subject;
use Illuminate\Http\Request;
use PDF;

Expand All @@ -13,96 +14,54 @@ class ResultController extends Controller
//
public function create(Request $request)
{
$student = $request->student;

//store all Subjects details with Obtained Marks
$obtainedMarks = [];
$weightages = [];
$passingInEach = [];
$data = $this->addToMarks($request, $passingInEach, $weightages, $obtainedMarks);
return sizeof($request->$obtainedMarks);
$passingInEach = $data[0];
$weightages = $data[1];
$obtainedMarks = $data[2];

$exam = Exam::where("name", $request->exam)->get();
if ($exam->count() == 0)
$examid = $this->addExam($request);
else
$examid = $exam[0]->id;

//variales to create final result
$totalObtained = 0;
$totalWeightage = 0;
$totalPassing = 0;
$result = true;

for ($i = 0; $i < sizeOf($obtainedMarks); $i++) {
$totalObtained += $obtainedMarks[$i];
$totalWeightage += $weightages[$i];
$totalPassing += $passingInEach[$i];

if ($obtainedMarks[$i] < $weightages[$i])
$result = false;
$marksheets = [];
$total_obtained= 0 ;
$total_weightage=0;
$result_status = true;
collect($request->subjects)->map(function($subject) use
($marksheets,$request,$total_obtained,$total_weightage)
{
$marksheets[] = [
'student_id'=>$request->student,
'subject_id'=>$subject["id"],
'obtainedMarks'=>$subject["obtained"],
'total'=>$subject["total"]
];

$total_obtained+=$subject["obtained"];
$total_weightage+=$subject["total"];
if($subject["obtained"] < $subject["passing"]){
$this->result_status = false;
}

}
);

Mark::insert($marksheets);

if(!Exam::where('name',$request->exam)->exists())
{
Exam::create([
'name' => $request->exam,
'year' => $request->year
]);
}

//calculate result
$percentage = ($totalObtained / $totalWeightage) * 100;
if ($request) {
if ($totalObtained < $totalPassing)
$result = false;
else
$request = true;
}
$percentage = ($total_obtained/$total_weightage)*100;

$exam = Exam::where('name',$request->exam)->first();

Result::create([
'student_id' => $student,
'exam_id' => $examid,
'status' => $result,
'student_id' => $request->student,
'exam_id' => $exam->id,
'status' => $result_status,
'percentage' => $percentage
]);


return response()->json(["message" => "Result Created Successfully"]);
}

public function addExam(Request $request)
{
$exam = new Exam();
$exam->name = $request->exam;
$exam->year = $request->year;
$exam->save();
return $exam->id;
}

public function addToMarks(Request $request, $passingInEach, $weightages, $obtainedMarks)
{
$dataSet = [];
$subjects = $request->subjects;
foreach ($subjects as $subject) {

$mark = $subject["obtained"];
$passing = $subject["passing"];
$weightage = $subject["total"];

//pushing data in array to create result
array_push($passingInEach, $passing);
array_push($weightages, $weightage);
array_push($obtainedMarks, $mark);

// adding record to marks table
Mark::create([
'student_id' => $request->student,
'subject_id' => $subject["id"],
'obtabinedMarks' => $mark,
'total' => $weightage
]);
}
array_push($dataSet, $passingInEach);
array_push($dataSet, $weightages);
array_push($dataSet, $obtainedMarks);
return $dataSet;
}

public function createMarksheetPDF()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/StudentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function store(Request $request)
}
else {
$user->delete();
return response()->json(["message" => "Collge and Courses details does not exists"],400);
return response()->json(["message" => "Collge and Courses does not exists"],400);
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions app/Http/Controllers/SubjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Subject;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SubjectController extends Controller
{
Expand All @@ -15,12 +16,15 @@ public function store(Request $request)
{
//
$user = $request->user();
$course = $user->courses()->latest('updated_at')->first();
$college_id = $user->colleges()->latest()->first()->id;
$course = $user->courses()->latest()->first();
if($this->addSubject($request))
{
$added_subject = Subject::where('name',$request->name)->first();
//inserting into course_subject
$course->subjects()->attach($added_subject->id);
// ['college_id'=>$college_id]
DB::update(DB::raw("UPDATE course_subject SET college_id={$college_id} where subject_id=$added_subject->id"));
return response()->json($added_subject,201);
}
return response()->json(["message"=>"Subject Already Exists"],400);
Expand All @@ -43,7 +47,20 @@ public function addSubject(Request $request)
public function index(Request $request)
{
$user = User::findOrFail($request->user()->id);
return $user->courses->sortByDesc('updated_at')->first()->subjects;
$college_id = $user->colleges()->latest()->first()->id;
$course_id = $user->courses()->latest()->first()->id;
//fetching subjects in head course
$subjects = DB::select(DB::raw("select course_subject.subject_id from course_subject where course_subject.course_id = $course_id and course_subject.college_id= $college_id"));
$computed_subjects = array_map(function($subject){

return Subject::find($subject->subject_id);

},$subjects);

return $computed_subjects;

// return $user->courses->sortByDesc('updated_at')->first()->subjects;

}

public function course(Request $request)
Expand Down
25 changes: 21 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ public function register(Request $request)

// return response()->json($user, 201);;

if (User::where('phone', $request->phone)->orWhere('email', $request->email)->exists())
return response()->json(["message" => "You are already registered"])->setStatusCode(422);
if (
User::where('phone', $request->phone)
->orWhere('email', $request->email)
->exists()
)
return response()
->json(["message" => "You are already registered"])
->setStatusCode(422);
else {

if ($this->headExists($request))
Expand Down Expand Up @@ -145,6 +151,17 @@ public function createRole(Request $request)

public function addingToCollege(Request $request)
{

$college = College::firstOrCreate([
'name' => $request->college
], [
"name" => $request->college,
"logo" => "",
"address" => "",
"stamp" => ""
]);
return $college;

if (!College::where('name', $request->college)->exists()) {
$college = new College(
[
Expand All @@ -157,7 +174,7 @@ public function addingToCollege(Request $request)
$college->save();
return $college;
} else
return College::where('name', $request->college)->get()[0];
return College::where('name', $request->college)->first();
}


Expand All @@ -174,6 +191,6 @@ public function addToCourse(Request $request)
$course->save();
return $course;
}
return Course::where("name", $request->course)->get()[0];
return Course::where("name", $request->course)->first();
}
}
1 change: 1 addition & 0 deletions app/Models/College.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public function courses()
{
return $this->belongsToMany(Course::class, 'college_course');
}

}
1 change: 1 addition & 0 deletions app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
class Exam extends Model
{
use HasFactory;
protected $fillable=['name','year'];
}
7 changes: 6 additions & 1 deletion app/Models/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Subject extends Model

public function courses()
{
return $this->belongsToMany(Course::class, 'course_subject');
return $this->belongsToMany(Course::class, 'course_id');
}

// public function college(){
// return $this->belongsTo(College::class, 'college_id');
// }

}
11 changes: 11 additions & 0 deletions app/Services/PaintService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Services;

class PaintService
{
public function handle()
{
echo "Paiting";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

class AddCollegeIdInCourseSubject extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('course_subject', function (Blueprint $table) {
$table->unsignedBigInteger('college_id')->nullable(true);
$table->foreign('college_id')->references('id')->on("colleges")->onDelete("cascade");
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('course_subject', function (Blueprint $table) {
//
});
}
}
Loading

0 comments on commit 0599e73

Please sign in to comment.