app/Http/Controllers/Admin/TutorReportsController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index()
    {
        $tutors = Role::find(config('global.TUTOR_ROLE_ID'))->users()->get();
        $tutor_reports = Array();
        foreach($tutors as $tutor)
        {
            $sessions = Session::whereHas('assignments', function($assignment) use ($tutor){
                return $assignment->where('tutor_id', $tutor->id);
            })->get();
            $students_tutored = (float)count($sessions);
            $sessions = Session::whereHas('assignments', function($assignment) use ($tutor){
                return $assignment->where('tutor_id', $tutor->id);
            })->get('session_duration')->pluck('session_duration')->toArray();
            $hours_tutored = (float)array_sum($sessions);
            if ($students_tutored != 0) {
                $avg_hours = (float)($hours_tutored / $students_tutored);
            } else $avg_hours = "NAN";
            $session_dates = Session::whereHas('assignments', function($assignment) use ($tutor){
                return $assignment->where('tutor_id', $tutor->id);
            })->get('session_date')->pluck('session_date')->toArray();
            if ($students_tutored != 0){
                $avg_duration = $this->get_durations($session_dates) / $students_tutored;
            } else $avg_duration = "NAN";
            $tutor_reports[] = array("Id"=>$tutor['id'], "Tutor Name" => $tutor['fname'] . ' ' . $tutor['lname']
            , 'Email'=>$tutor['email'], 'Students Tutored'=>$students_tutored, 
            'Hours Tutored'=>$hours_tutored, 'Avg Hours Per Student' =>$avg_hours
            , 'Average Duration Per Student'=>$avg_duration);
        }
        return view('admin.tutorreports.index')->with('reports', $tutor_reports);
    }
public function index ( ) { $ tutors = Role :: find ( config ( 'global.TUTOR_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ tutor_reports = Array ( ) ; foreach ( $ tutors as $ tutor ) { $ sessions = Session :: whereHas ( 'assignments' , function ( $ assignment ) use ( $ tutor ) { return $ assignment -> where ( 'tutor_id' , $ tutor -> id ) ; } ) -> get ( ) ; $ students_tutored = ( float ) count ( $ sessions ) ; $ sessions = Session :: whereHas ( 'assignments' , function ( $ assignment ) use ( $ tutor ) { return $ assignment -> where ( 'tutor_id' , $ tutor -> id ) ; } ) -> get ( 'session_duration' ) -> pluck ( 'session_duration' ) -> toArray ( ) ; $ hours_tutored = ( float ) array_sum ( $ sessions ) ; if ( $ students_tutored != 0 ) { $ avg_hours = ( float ) ( $ hours_tutored / $ students_tutored ) ; } else $ avg_hours = " NAN " ; $ session_dates = Session :: whereHas ( 'assignments' , function ( $ assignment ) use ( $ tutor ) { return $ assignment -> where ( 'tutor_id' , $ tutor -> id ) ; } ) -> get ( 'session_date' ) -> pluck ( 'session_date' ) -> toArray ( ) ; if ( $ students_tutored != 0 ) { $ avg_duration = $ this -> get_durations ( $ session_dates ) / $ students_tutored ; } else $ avg_duration = " NAN " ; $ tutor_reports [ ] = array ( " Id " => $ tutor [ 'id' ] , " Tutor Name " => $ tutor [ 'fname' ] . ' ' . $ tutor [ 'lname' ] , 'Email' => $ tutor [ 'email' ] , 'Students Tutored' => $ students_tutored , 'Hours Tutored' => $ hours_tutored , 'Avg Hours Per Student' => $ avg_hours , 'Average Duration Per Student' => $ avg_duration ) ; } return view ( 'admin.tutorreports.index' ) -> with ( 'reports' , $ tutor_reports ) ; }
Display a listing of the resource.
Display a listing of the resource .
//Get Total Students Tutored Count per tutor //Get Total Hours Tutored per tutor //Get Average Hours Per Student with each tutor //Get Total Hours Tutored per tutor