IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Teacher/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Teacher/ViewOnlyController.php

<?php

namespace App\Http\Controllers\Teacher;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Session;

class ViewOnlyController extends Controller {

    public function viewStudents($id,Request $request){
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        if($request->get('idSection') != null){
            $sections_ids = $request->get('idSection');
            $students = \App\AdmEntry::select('students.firstName', 'students.middleName', 'students.lastName', 'students.idStudent', 'students.ecNo', 'students.idClass', 'students.idSection')->where('idClass', $request->get('idClass'))->whereIn('idSection', $sections_ids)->where('students.idFinancialYear',  Session::get('idFinancialYear'))->where('students.isActive', 'Y')->get();    
        }else if($request->get('idClass') != null){
           $students = \App\AdmEntry::select('students.firstName', 'students.middleName', 'students.lastName', 'students.idStudent', 'students.ecNo', 'students.ecNoidClass', 'students.idSection')->where('idClass', $request->get('idClass'))->where('students.idFinancialYear',  Session::get('idFinancialYear'))->where('students.isActive', 'Y')->get();    
        }else {
            $students = [];
        }
        return view('teachers.view_students', compact('students','school','id'));
    }

    public function fetchAssignSection($id){
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $sections = DB::table('teacher_classes')
        ->join('classes', 'teacher_classes.idClass', '=', 'classes.idClass')
        ->join('sections', 'teacher_classes.idSection', '=', 'sections.idSection')
        ->select('classes.className', 'sections.sectionName', 'classes.idClass', 'sections.idSection', 'teacher_classes.*')
        ->where('teacher_classes.idEmployee', $teacher->idEmployee)
        ->where('classes.idClass', $id)
        ->where('teacher_classes.idSchool', $teacher->idSchool)->get()->pluck('sectionName','idSection')->toArray();
        return json_encode($sections);
    }

    public function markDetails($id,Request $request){
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $student = \App\AdmEntry::where('idStudent', '=', $request->get('student'))->first();
        $exam = \App\MarkExamType::where('idType', $id)->orderBy('idType')->first();
        $type = \App\MarkExams::where('marks_exam.idType', '=', $id)->first();
            $result = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->where('exam_marksheet.idStudent',$student->idStudent)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->get();  
            $examByPerformance = \App\ExamSheet::join('marks_exam_type', 'exam_marksheet.idExam', '=', 'marks_exam_type.idType')->select(DB::raw('SUM(total) as marks'),'name')->where('exam_marksheet.idStudent',$student->idStudent)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->groupBy('idExam')->get();
            $top = \App\ExamSheet::select(DB::raw('SUM(total) as total'),'idStudent as id')->where('exam_marksheet.idClass',$student->idClass)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->groupBy('idStudent')->orderBy('total','DESC')->first();
            $lowest = \App\ExamSheet::select(DB::raw('SUM(total) as total'),'idStudent as id')->where('exam_marksheet.idClass',$student->idClass)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->groupBy('idStudent')->orderBy('total','ASC')->first();
            $topper = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->join('students', 'exam_marksheet.idStudent', '=', 'students.idStudent')->join('classes', 'students.idClass', '=', 'classes.idClass')
            ->join('sections', 'students.idSection', '=', 'sections.idSection')->where('exam_marksheet.idClass',$student->idClass)
            ->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('exam_marksheet.idStudent',$top->id)->where('idExam',$id)->first();
            $topperResult = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->where('exam_marksheet.idStudent',$top->id)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->get();  
            
            $mine = $this->prepareResult($result,$type);
            $top = $this->prepareResult($topperResult,$type);
            if($lowest->total == null) $lowestScore =  0 ;
            else $lowestScore =  $lowest->total;
            return view('teachers.marks.exam_result', compact('examByPerformance','topper','mine','top','exam','lowestScore','school'));
    }

    public function markList(Request $request){
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $classes = DB::table('teacher_classes')
                        ->join('classes', 'teacher_classes.idClass', '=', 'classes.idClass')
                        ->join('sections', 'teacher_classes.idSection', '=', 'sections.idSection')
                        ->select('classes.className', 'sections.sectionName', 'classes.idClass', 'sections.idSection', 'teacher_classes.*')
                        ->where('teacher_classes.idEmployee', $teacher->idEmployee)
                        ->where('teacher_classes.idSchool', $teacher->idSchool)->get()->pluck('className','idClass')->toArray();

        if($request->get('idClass') != null && $request->get('idSection') != null){
            $idExam = \App\MarkExams::where('idClass',$request->get('idClass'))->where('idFinancialYear', Session::get('idFinancialYear'))->whereRaw('idSection IS NULL OR idSection IN  (?)', [$request->get('idSection')])->groupBy('idType')->get()->pluck('idType')->toArray();
            $data = \App\MarkExamType::whereIn('idType', $idExam)
                            ->orderBy('idType')->paginate()->items();
        }else if($request->get('idClass') != null){
            $idExam = \App\MarkExams::where('idClass',$request->get('idClass'))->where('idFinancialYear', Session::get('idFinancialYear'))->groupBy('idType')->get()->pluck('idType')->toArray();
            $data = \App\MarkExamType::whereIn('idType', $idExam)
                            ->orderBy('idType')->paginate()->items();
        }else{
            $data = [];
        }     
        return view('teachers.marks.view_marklist', compact('data','school','classes'));
    }

    private function prepareResult($result,$type){
        $totalMarks = json_decode($type->marks,true);
        $gradesRange = json_decode($type->grades,true);
        $resultArr = array();
        $overMinelTotal = 0;
        $overTotal = 0;
            foreach($result as $marks){
                $temp = array(
                    "subject" => $marks->subjectName,
                    "full_marks" => 0,
                    "status" => $marks->attendance,
                    "theory" => $marks->marks,
                    "practical" => $marks->pratical,
                    "total" => $marks->marks + $marks->pratical,
                    "grade" => "",
                    "percentage" => ""
                );
                $overMinelTotal = $overMinelTotal + $temp["total"];
                foreach($totalMarks as $total){
                    if($total["id"] == $marks->idSubject)
                    {
                        if($total["pratical"] == "nil")
                        {
                            $temp["full_marks"] = $total["theory"];
                            $temp["practical"] = "NA";
                        }
                        else
                        $temp["full_marks"] = $total["theory"] + $total["pratical"];
                        $overTotal = $overTotal + $temp["full_marks"];

                        if($temp["full_marks"] != 0 )
                        {
                            $temp["percentage"] = ($temp["total"] / $temp["full_marks"]) * 100;
                            $temp["percentage"] =  number_format((float)$temp["percentage"], 2, '.', '');
                        }
                    }
                    
                }
                foreach($gradesRange as $range){
                    $total = $temp["total"];
                    if($range["from"] <= $total  &&  $total <= $range["to"] ){
                        $temp["grade"] = $range["name"];
                    }
                }
                array_push($resultArr,$temp);
            }
            $grade = '';
            foreach($gradesRange as $range){
                if($overTotal > 0){
                    $total = ($overMinelTotal / $overTotal) * 100;
                    if($range["from"] <= $total  &&  $total <= $range["to"] ){
                        $grade = $range["name"];
                    }
                }
            }
       return array(
                "result" => $resultArr,
                "total" => $overMinelTotal,
                "totalMarks" => $overTotal,
                "grade" => $grade,
            );    
    }

    public function viewTimetable(Request $request) {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $classes = DB::table('teacher_classes')
                        ->join('classes', 'teacher_classes.idClass', '=', 'classes.idClass')
                        ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                        ->where('idEmployee', '=', $teacher->idEmployee)
                        ->orderBy('classes.idClass')->get()->pluck('className', 'idClass')->toArray();
        $classes = ['' => '--Select Class --'] + $classes;
        $periods = \App\Period::where('idSchool', '=', $teacher->idSchool)
                        ->where('idClass', '=', $request->idClass)
                        ->where('idSection', '=', $request->idSection)->get();
        return view('teachers.viewtimetable', compact('classes', 'periods', 'school'));
    }

    public function viewCalender() {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $holidays = \App\Holiday::where('idSchool', '=', $teacher->idSchool)->where('idFinancialYear', '=', Session::get('idFinancialYear'))->get();
        return view('teachers.viewholiday', compact('holidays', 'school'));
    }

    public function viewNewsLetter() {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $newsletters = \App\NewsLetter::where('idSchool', '=', $teacher->idSchool)
                        ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                        ->orderBy('idNewsletter', 'desc')->get();
        return view('teachers.viewnewsletters', compact('newsletters', 'school'));
    }

    public function viewShortStories() {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $stories = \App\ShortStory::where('idSchool', '=', $teacher->idSchool)
                        ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                        ->orderBy('idStory', 'desc')->get();
        return view('teachers.viewshstories', compact('stories', 'school'));
    }

    public function viewAttendance(Request $request) {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
        $now = \Carbon\Carbon::now();
        $month_name = $now->format('M');
        if($request->get('month') != null){
            $month = \App\Month::where('idMonth',$request->get('month'))->first();
        }else
        $month = \App\Month::where('monthName', 'like', '%' . $month_name . '%')->first();
        return view('teachers.view_attendance', compact('teacher', 'school', 'month'));
    }

}

Copyright © 2021 - 2025 IMMREX7