Skip to content

Commit

Permalink
Update to Laravel 8.4 with PHP v8 Support & Reduced Marksheet Complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
4jean committed May 30, 2021
1 parent 85d7072 commit 12dcfaf
Show file tree
Hide file tree
Showing 31 changed files with 3,157 additions and 1,195 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ important
_ide_helper.php
storage
.phpstorm.meta.php
.editorconfig
2 changes: 1 addition & 1 deletion app/Helpers/Qs.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function displayError($errors)

public static function getAppCode()
{
return 'QS';
return self::getSetting('system_title') ?: 'CJ';
}

public static function getDefaultUserImage()
Expand Down
69 changes: 28 additions & 41 deletions app/Http/Controllers/SupportTeam/MarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ public function show($student_id, $year)
$d['my_class'] = $mc = $this->my_class->getMC(['id' => $exr->first()->my_class_id])->first();
$d['class_type'] = $this->my_class->findTypeByClass($mc->id);
$d['subjects'] = $this->my_class->findSubjectByClass($mc->id);

$d['ct'] = $ct = $d['class_type']->code;
$d['year'] = $year;
$d['student_id'] = $student_id;

$d['skills'] = in_array($ct, ['J', 'S']) ? $this->exam->getSkillByClassType($ct) : NULL;

$d['mark_type'] = Qs::getMarkType($d['ct']);
$d['skills'] = $this->exam->getSkillByClassType() ?: NULL;
//$d['ct'] = $d['class_type']->code;
//$d['mark_type'] = Qs::getMarkType($d['ct']);

return view('pages.support_team.marks.show.index', $d);
}
Expand Down Expand Up @@ -120,6 +117,7 @@ public function print_view($student_id, $exam_id, $year)
$d['my_class'] = $mc = $this->my_class->find($exr->my_class_id);
$d['section_id'] = $exr->section_id;
$d['ex'] = $exam = $this->exam->find($exam_id);
$d['tex'] = 'tex'.$exam->term;
$d['sr'] = $sr =$this->student->getRecord(['user_id' => $student_id])->first();
$d['class_type'] = $this->my_class->findTypeByClass($mc->id);
$d['subjects'] = $this->my_class->findSubjectByClass($mc->id);
Expand All @@ -129,12 +127,12 @@ public function print_view($student_id, $exam_id, $year)
$d['student_id'] = $student_id;
$d['exam_id'] = $exam_id;

$d['skills'] = in_array($ct, ['J', 'S']) ? $this->exam->getSkillByClassType($ct) : NULL;
$d['skills'] = $this->exam->getSkillByClassType() ?: NULL;
$d['s'] = Setting::all()->flatMap(function($s){
return [$s->type => $s->description];
});

$d['mark_type'] = Qs::getMarkType($ct);
//$d['mark_type'] = Qs::getMarkType($ct);

return view('pages.support_team.marks.print.index', $d);
}
Expand Down Expand Up @@ -187,7 +185,7 @@ public function update(Request $req, $exam_id, $class_id, $section_id, $subject_
{
$p = ['exam_id' => $exam_id, 'my_class_id' => $class_id, 'section_id' => $section_id, 'subject_id' => $subject_id, 'year' => $this->year];

$d = $all_st_ids = []; $tca = $exm = $grade = NULL;
$d = $d3 = $all_st_ids = [];

$exam = $this->exam->find($exam_id);
$marks = $this->exam->getMark($p);
Expand All @@ -196,21 +194,15 @@ public function update(Request $req, $exam_id, $class_id, $section_id, $subject_
$mks = $req->all();

/** Test, Exam, Grade **/
foreach($marks->sortBy('user.name') as $mk){
$st_id = $all_st_ids[] = $mk->student_id;
foreach($marks->sortBy('user.name') as $mk)
{
$all_st_ids[] = $mk->student_id;

if(in_array($class_type->code, ['J', 'P', 'S']) ){
$d['t1'] = $t1 = $mks['t1_'.$mk->id];
$d['t2'] = $t2 = $mks['t2_'.$mk->id];
$d['t3'] = $t3 = $mks['t3_'.$mk->id];
$d['tca'] = $tca = $t1 + $t2 + $t3;
$d['tca'] = $tca = $t1 + $t2;
$d['exm'] = $exm = $mks['exm_'.$mk->id];
}

if($class_type->code == 'N'){
$d['t1'] = $tca = $d['tca'] = $mks['t1_'.$mk->id];
$d['exm'] = $exm = $mks['exm_'.$mk->id];
}

/** SubTotal Grade, Remark, Cum, CumAvg**/

Expand All @@ -220,24 +212,25 @@ public function update(Request $req, $exam_id, $class_id, $section_id, $subject_
$d['tex'.$exam->term] = $d['t1'] = $d['t2'] = $d['t3'] = $d['t4'] = $d['tca'] = $d['exm'] = NULL;
}

if($exam->term < 3){
/* if($exam->term < 3){
$grade = $this->mark->getGrade($total, $class_type->id);
}
if($exam->term == 3){
$d['cum'] = $this->mark->getSubCumTotal($total, $st_id, $subject_id, $class_id, $this->year);
$d['cum_ave'] = $cav = $this->mark->getSubCumAvg($total, $st_id, $subject_id, $class_id, $this->year);
$grade = $this->mark->getGrade(round($cav), $class_type->id);
}

}*/
$grade = $this->mark->getGrade($total, $class_type->id);
$d['grade_id'] = $grade ? $grade->id : NULL;

$this->exam->updateMark($mk->id, $d);
}

/** Sub Position Begin **/

foreach($marks->sortBy('user.name') as $mk){
foreach($marks->sortBy('user.name') as $mk)
{

$d2['sub_pos'] = $this->mark->getSubPos($mk->student_id, $exam, $class_id, $subject_id, $this->year);

Expand All @@ -248,18 +241,18 @@ public function update(Request $req, $exam_id, $class_id, $section_id, $subject_

/* Exam Record Update */

$w = $p; unset( $w['subject_id'] );
unset( $p['subject_id'] );

foreach ($all_st_ids as $st_id) {

$p['student_id'] =$st_id;
$d3['total'] = $this->mark->getExamTotalTerm($exam, $st_id, $class_id, $this->year);
$d3['ave'] = $this->mark->getExamAvgTerm($exam, $st_id, $class_id, $section_id, $this->year);
$d3['class_ave'] = $this->mark->getClassAvg($exam, $class_id, $this->year);
$d3['pos'] = $this->mark->getPos($st_id, $exam, $class_id, $section_id, $this->year);

$this->exam->updateRecord($w, $d3);
$this->exam->updateRecord($p, $d3);
}

/*Exam Record End*/

return Qs::jsonUpdateOk();
Expand All @@ -275,7 +268,7 @@ public function batch_fix()
return view('pages.support_team.marks.batch_fix', $d);
}

public function batch_update(Request $req)
public function batch_update(Request $req): \Illuminate\Http\JsonResponse
{
$exam_id = $req->exam_id;
$class_id = $req->my_class_id;
Expand All @@ -289,30 +282,24 @@ public function batch_update(Request $req)

/** Marks Fix Begin **/

$grade = NULL;
$class_type = $this->my_class->findTypeByClass($class_id);
$tex = 'tex'.$exam->term;

foreach($marks as $mk){

$total = $mk->$tex;
$d['grade_id'] = $this->mark->getGrade($total, $class_type->id);

if($exam->term < 3){
$grade = $this->mark->getGrade($total, $class_type->id);
}

if($exam->term == 3){
$d['cum'] = $this->mark->getSubCumTotal($total, $mk->student_id, $mk->subject_id, $class_id, $this->year);
$d['cum_ave'] = $cav = $this->mark->getSubCumAvg($total, $mk->student_id, $mk->subject_id, $class_id, $this->year);
$grade = $this->mark->getGrade(round($mk->cum_ave), $class_type->id);
}

$d['grade_id'] = $grade ? $grade->id : NULL;
/* if($exam->term == 3){
$d['cum'] = $this->mark->getSubCumTotal($total, $mk->student_id, $mk->subject_id, $class_id, $this->year);
$d['cum_ave'] = $cav = $this->mark->getSubCumAvg($total, $mk->student_id, $mk->subject_id, $class_id, $this->year);
$grade = $this->mark->getGrade(round($mk->cum_ave), $class_type->id);
}*/

$this->exam->updateMark($mk->id, $d);
}

/*Marks Fix End*/
/* Marks Fix End*/

/** Exam Record Update **/
foreach($exrs as $exr){
Expand All @@ -326,8 +313,8 @@ public function batch_update(Request $req)

$this->exam->updateRecord(['id' => $exr->id], $d3);
}
/** END Exam Record Update END **/

/** END Exam Record Update END **/

return Qs::jsonUpdateOk();
}
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/SupportTeam/StudentRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ public function store(StudentRecordCreate $req)
$sr = $req->only(Qs::getStudentData());

$ct = $this->my_class->findTypeByClass($req->my_class_id)->code;
$ct = ($ct == 'J') ? 'JSS' : $ct;
$ct = ($ct == 'S') ? 'SS' : $ct;
/* $ct = ($ct == 'J') ? 'JSS' : $ct;
$ct = ($ct == 'S') ? 'SS' : $ct;*/

$data['user_type'] = 'student';
$data['name'] = ucwords($req->name);
$data['code'] = strtoupper(Str::random(10));
$data['password'] = Hash::make('student');
$data['photo'] = Qs::getDefaultUserImage();
$data['username'] = Qs::getAppCode().'/'.$ct.'/'.$sr['year_admitted'].'/'.mt_rand(1000, 9999);
$adm_no = $req->adm_no;
$data['username'] = strtoupper(Qs::getAppCode().'/'.$ct.'/'.$sr['year_admitted'].'/'.($adm_no ?: mt_rand(1000, 99999)));

if($req->hasFile('photo')) {
$photo = $req->file('photo');
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Student/StudentRecordCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function rules()
{
return [
'name' => 'required|string|min:6|max:150',
'adm_no' => 'sometimes|nullable|alpha_num|min:3|max:150|unique:student_records',
'gender' => 'required|string',
'year_admitted' => 'required|string',
'phone' => 'sometimes|nullable|string|min:6|max:20',
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/ExamRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public function getSkill($where)
return Skill::where($where)->orderBy('name')->get();
}

public function getSkillByClassType($class_type, $skill_type = NULL)
public function getSkillByClassType($class_type = NULL, $skill_type = NULL)
{
return $skill_type
return ($skill_type)
? $this->getSkill(['class_type' => $class_type, 'skill_type' => $skill_type])
: $this->getSkill(['class_type' => $class_type]);
}
Expand Down
32 changes: 14 additions & 18 deletions app/Repositories/MarkRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,29 @@ public function getExamTotalTerm($exam, $st_id, $class_id, $year)
{
$d = ['student_id' => $st_id, 'exam_id' => $exam->id, 'my_class_id' => $class_id, 'year' => $year];

$term = $exam->term; $tex = 'tex'.$term;
if($term < 3){
$mk =Mark::where($d);
return $mk->select($tex)->sum($tex);
}
$tex = 'tex'.$exam->term;
$mk =Mark::where($d);
return $mk->select($tex)->sum($tex);

unset($d['exam_id']);
/* unset($d['exam_id']);
$mk =Mark::where($d);
$t1 = $mk->select('tex1')->sum('tex1');
$t2 = $mk->select('tex2')->sum('tex2');
$t3 = $mk->select('tex3')->sum('tex3');
return $t1 + $t2 + $t3;
return $t1 + $t2 + $t3;*/
}

public function getExamAvgTerm($exam, $st_id, $class_id, $sec_id, $year)
{
$d = ['student_id' => $st_id, 'exam_id' => $exam->id, 'my_class_id' => $class_id, 'section_id' => $sec_id, 'year' => $year];

$term = $exam->term; $tex = 'tex'.$term;
$tex = 'tex'.$exam->term;

if($term < 3){
$mk = Mark::where($d)->where($tex, '>', 0);
$avg = $mk->select($tex)->avg($tex);
return round($avg, 1);
}
$mk = Mark::where($d)->where($tex, '>', 0);
$avg = $mk->select($tex)->avg($tex);
return round($avg, 1);

unset($d['exam_id']);
/*unset($d['exam_id']);
$mk = Mark::where($d); $count = 0;
$t1 = $mk->select('tex1')->avg('tex1');
Expand All @@ -82,7 +78,7 @@ public function getExamAvgTerm($exam, $st_id, $class_id, $sec_id, $year)
$count = $t3 ? $count + 1 : $count;
$avg = $t1 + $t2 + $t3;
return ($avg > 0) ? round($avg/$count, 1) : 0;
return ($avg > 0) ? round($avg/$count, 1) : 0;*/
}

public function getSubCumTotal($tex3, $st_id, $sub_id, $class_id, $year)
Expand Down Expand Up @@ -150,9 +146,9 @@ public function getPos($st_id, $exam, $class_id, $sec_id, $year)

$my_mk = Mark::where($d)->select($tex)->sum($tex);

if($exam->term == 3){
/*if($exam->term == 3){
$my_mk = Mark::where($d)->select('cum')->sum('cum');
}
}*/

unset($d['student_id']);
$mk = Mark::where($d);
Expand All @@ -174,4 +170,4 @@ public function getStudentIDs($data)
return Mark::distinct()->select('student_id')->where($data)->get()->pluck('student_id');
}

}
}
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^7.3",
"php": "^7.2||^8.0",
"barryvdh/laravel-dompdf": "^0.8.3",
"fideloper/proxy": "^4.2",
"fakerphp/faker": "^1.14",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"hashids/hashids": "^3.0",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0",
"hashids/hashids": "^4.1.0",
"laravel/framework": "^8.40",
"laravel/tinker": "^2.5",
"laravel/ui": "^3.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.8",
"facade/ignition": "^2.3.6",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"facade/ignition": "^2.5",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 12dcfaf

Please sign in to comment.