Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Laravel 10 #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Console/Kernel.php
Expand Up @@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
51 changes: 33 additions & 18 deletions app/Helpers/Mk.php
Expand Up @@ -23,13 +23,16 @@ public static function getRemarks()
/** ADD ORDINAL SUFFIX TO POSITION **/
public static function getSuffix($number)
{
if($number < 1){ return NULL;}
if ($number < 1) {
return null;
}

$ends = array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');
if ((($number % 100) >= 11) && (($number % 100) <= 13))
return $number . '<sup>th</sup>';
else
return $number . '<sup>' . $ends[$number % 10] . '</sup>';
$ends = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
if ((($number % 100) >= 11) && (($number % 100) <= 13)) {
return $number.'<sup>th</sup>';
} else {
return $number.'<sup>'.$ends[$number % 10].'</sup>';
}
}

/*Get Subject Total Per Term*/
Expand All @@ -39,50 +42,56 @@ public static function getSubTotalTerm($st_id, $sub_id, $term, $class_id, $year)

$tex = 'tex'.$term;
$sub_total = Mark::where($d)->select($tex)->get()->where($tex, '>', 0);

return $sub_total->count() > 0 ? $sub_total->first()->$tex : '-';
}

public static function countDistinctions(Collection $marks)
{
$gradeIDS = Grade::where('name', 'LIKE', 'A%')->orWhere('name', 'LIKE', 'B%')->get()->pluck('id')->toArray();

return self::markGradeFilter($marks, $gradeIDS);
}

public static function countPasses(Collection $marks)
{
$gradeIDS = Grade::where('name', 'LIKE', 'D%')->orWhere('name', 'LIKE', 'E%')->get()->pluck('id')->toArray();

return self::markGradeFilter($marks, $gradeIDS);
}

public static function countCredits(Collection $marks)
{
$gradeIDS = Grade::where('name', 'LIKE', 'C%')->get()->pluck('id')->toArray();

return self::markGradeFilter($marks, $gradeIDS);
}

public static function countFailures(Collection $marks)
{
$gradeIDS = Grade::where('name', 'LIKE', 'F%')->get()->pluck('id')->toArray();

return self::markGradeFilter($marks, $gradeIDS);
}

public static function countStudents($exam_id, $class_id, $section_id, $year)
{
$d = ['exam_id' => $exam_id, 'my_class_id' => $class_id, 'section_id' => $section_id, 'year' => $year];

return Mark::where($d)->select('student_id')->distinct()->get()->count();
}

protected static function markGradeFilter(Collection $marks, $gradeIDS)
{
return $marks->filter(function($mks) use ($gradeIDS){
return $marks->filter(function ($mks) use ($gradeIDS) {
return in_array($mks->grade_id, $gradeIDS);
})->count();
}

public static function countSubjectsOffered(Collection $mark)
{
return $mark->filter(function($mk) {
return ($mk->tca + $mk->exm) > 0 ;
return $mark->filter(function ($mk) {
return ($mk->tca + $mk->exm) > 0;
})->count();
}

Expand All @@ -92,14 +101,16 @@ public static function getTermAverage($st_id, $term, $year)
$exam = self::getExamByTerm($term, $year);
$d = ['exam_id' => $exam->id, 'student_id' => $st_id, 'year' => $year];

if($term < 3){
if ($term < 3) {
$exr = ExamRecord::where($d);
$avg = $exr->first()->ave ?: NULL;
$avg = $exr->first()->ave ?: null;

return $avg > 0 ? round($avg, 1) : $avg;
}

$mk = Mark::where($d)->whereNotNull('tex3');
$avg = $mk->select('tex3')->avg('tex3');

return round($avg, 1);
}

Expand All @@ -108,50 +119,54 @@ public static function getTermTotal($st_id, $term, $year)
$exam = self::getExamByTerm($term, $year);
$d = ['exam_id' => $exam->id, 'student_id' => $st_id, 'year' => $year];

if($term < 3){
return ExamRecord::where($d)->first()->total ?? NULL;
if ($term < 3) {
return ExamRecord::where($d)->first()->total ?? null;
}

$mk = Mark::where($d)->whereNotNull('tex3');

return $mk->select('tex3')->sum('tex3');
}

public static function getExamByTerm($term, $year)
{
$d = ['term' => $term, 'year' => $year];

return Exam::where($d)->first();
}

public static function getGradeList($class_type_id)
{
$grades = Grade::where(['class_type_id' => $class_type_id])->orderBy('name')->get();

if($grades->count() < 1){
if ($grades->count() < 1) {
$grades = Grade::whereNull('class_type_id')->orderBy('name')->get();
}

return $grades;
}

/**
* If Class/Section is Changed in Same Year,
* Delete Marks/ExamRecord of Previous Class/Section
*
* @param int $st_id
* @param int $class_id
* @param int $st_id
* @param int $class_id
* @return bool
*
* @static
*/
public static function deleteOldRecord($st_id, $class_id)
{
$d = ['student_id' => $st_id, 'year' => self::getCurrentSession()];

$marks = Mark::where('my_class_id', '<>', $class_id)->where($d);
if($marks->get()->count() > 0){
if ($marks->get()->count() > 0) {
$exr = ExamRecord::where('my_class_id', '<>', $class_id)->where($d);
$marks->delete();
$exr->delete();
}

return true;
}

}
2 changes: 1 addition & 1 deletion app/Helpers/Pay.php
Expand Up @@ -15,4 +15,4 @@ public static function genRefCode()
{
return date('Y').'/'.mt_rand(10000, 999999);
}
}
}
50 changes: 30 additions & 20 deletions app/Helpers/Qs.php
Expand Up @@ -15,6 +15,7 @@ public static function displayError($errors)
foreach ($errors as $err) {
$data[] = $err;
}

return '
<div class="alert alert-danger alert-styled-left alert-dismissible">
<button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
Expand Down Expand Up @@ -82,6 +83,7 @@ public static function hash($id)
{
$date = date('dMY').'CJ';
$hash = new Hashids($date, 14);

return $hash->encode($id);
}

Expand All @@ -94,7 +96,7 @@ public static function getUserRecord($remove = [])

public static function getStaffRecord($remove = [])
{
$data = ['emp_date',];
$data = ['emp_date'];

return $remove ? array_values(array_diff($data, $remove)) : $data;
}
Expand All @@ -112,6 +114,7 @@ public static function decodeHash($str, $toString = true)
$date = date('dMY').'CJ';
$hash = new Hashids($date, 14);
$decoded = $hash->decode($str);

return $toString ? implode(',', $decoded) : $decoded;
}

Expand Down Expand Up @@ -175,15 +178,17 @@ public static function userIsStaff()
return in_array(Auth::user()->user_type, self::getStaff());
}

public static function getStaff($remove=[])
public static function getStaff($remove = [])
{
$data = ['super_admin', 'admin', 'teacher', 'accountant', 'librarian'];
$data = ['super_admin', 'admin', 'teacher', 'accountant', 'librarian'];

return $remove ? array_values(array_diff($data, $remove)) : $data;
}

public static function getAllUserTypes($remove=[])
public static function getAllUserTypes($remove = [])
{
$data = ['super_admin', 'admin', 'teacher', 'accountant', 'librarian', 'student', 'parent'];
$data = ['super_admin', 'admin', 'teacher', 'accountant', 'librarian', 'student', 'parent'];

return $remove ? array_values(array_diff($data, $remove)) : $data;
}

Expand All @@ -200,7 +205,8 @@ public static function userIsPTA()

public static function userIsMyChild($student_id, $parent_id)
{
$data = ['user_id' => $student_id, 'my_parent_id' =>$parent_id];
$data = ['user_id' => $student_id, 'my_parent_id' => $parent_id];

return StudentRecord::where($data)->exists();
}

Expand Down Expand Up @@ -240,6 +246,7 @@ public static function getFileMetaData($file)
$dataFile['ext'] = $file->getClientOriginalExtension();
$dataFile['type'] = $file->getClientMimeType();
$dataFile['size'] = self::formatBytes($file->getSize());

return $dataFile;
}

Expand All @@ -251,9 +258,9 @@ public static function generateUserCode()
public static function formatBytes($size, $precision = 2)
{
$base = log($size, 1024);
$suffixes = array('B', 'KB', 'MB', 'GB', 'TB');
$suffixes = ['B', 'KB', 'MB', 'GB', 'TB'];

return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)];
}

public static function getSetting($type)
Expand All @@ -270,6 +277,7 @@ public static function getNextSession()
{
$oy = self::getCurrentSession();
$old_yr = explode('-', $oy);

return ++$old_yr[0].'-'.++$old_yr[1];
}

Expand All @@ -295,18 +303,19 @@ public static function findStudentRecord($user_id)

public static function getMarkType($class_type)
{
switch($class_type){
case 'J' : return 'junior';
case 'S' : return 'senior';
case 'N' : return 'nursery';
case 'P' : return 'primary';
case 'PN' : return 'pre_nursery';
case 'C' : return 'creche';
}
switch ($class_type) {
case 'J': return 'junior';
case 'S': return 'senior';
case 'N': return 'nursery';
case 'P': return 'primary';
case 'PN': return 'pre_nursery';
case 'C': return 'creche';
}

return $class_type;
}

public static function json($msg, $ok = TRUE, $arr = [])
public static function json($msg, $ok = true, $arr = [])
{
return $arr ? response()->json($arr) : response()->json(['ok' => $ok, 'msg' => $msg]);
}
Expand Down Expand Up @@ -340,16 +349,18 @@ public static function goToRoute($goto, $status = 302, $headers = [], $secure =
{
$data = [];
$to = (is_array($goto) ? $goto[0] : $goto) ?: 'dashboard';
if(is_array($goto)){
if (is_array($goto)) {
array_shift($goto);
$data = $goto;
}

return app('redirect')->to(route($to, $data), $status, $headers, $secure);
}

public static function goWithDanger($to = 'dashboard', $msg = NULL)
public static function goWithDanger($to = 'dashboard', $msg = null)
{
$msg = $msg ? $msg : __('msg.rnf');

return self::goToRoute($to)->with('flash_danger', $msg);
}

Expand All @@ -362,5 +373,4 @@ public static function getDaysOfTheWeek()
{
return ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
}

}
21 changes: 12 additions & 9 deletions app/Http/Controllers/AjaxController.php
Expand Up @@ -9,7 +9,9 @@

class AjaxController extends Controller
{
protected $loc, $my_class;
protected $loc;

protected $my_class;

public function __construct(LocationRepo $loc, MyClassRepo $my_class)
{
Expand All @@ -19,19 +21,21 @@ public function __construct(LocationRepo $loc, MyClassRepo $my_class)

public function get_lga($state_id)
{
// $state_id = Qs::decodeHash($state_id);
// return ['id' => Qs::hash($q->id), 'name' => $q->name];
// $state_id = Qs::decodeHash($state_id);
// return ['id' => Qs::hash($q->id), 'name' => $q->name];

$lgas = $this->loc->getLGAs($state_id);
return $data = $lgas->map(function($q){

return $data = $lgas->map(function ($q) {
return ['id' => $q->id, 'name' => $q->name];
})->all();
}

public function get_class_sections($class_id)
{
$sections = $this->my_class->getClassSections($class_id);
return $sections = $sections->map(function($q){

return $sections = $sections->map(function ($q) {
return ['id' => $q->id, 'name' => $q->name];
})->all();
}
Expand All @@ -41,18 +45,17 @@ public function get_class_subjects($class_id)
$sections = $this->my_class->getClassSections($class_id);
$subjects = $this->my_class->findSubjectByClass($class_id);

if(Qs::userIsTeacher()){
if (Qs::userIsTeacher()) {
$subjects = $this->my_class->findSubjectByTeacher(Auth::user()->id)->where('my_class_id', $class_id);
}

$d['sections'] = $sections->map(function($q){
$d['sections'] = $sections->map(function ($q) {
return ['id' => $q->id, 'name' => $q->name];
})->all();
$d['subjects'] = $subjects->map(function($q){
$d['subjects'] = $subjects->map(function ($q) {
return ['id' => $q->id, 'name' => $q->name];
})->all();

return $d;
}

}
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/LoginController.php
Expand Up @@ -45,6 +45,7 @@ public function username()
$identity = request()->identity;
$field = filter_var($identity, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
request()->merge([$field => $identity]);

return $field;
}
}