<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\StudentProposal;
use App\Models\Department;
use App\Models\ReferUser;
use App\Models\University;
use App\Institution;
use App\Workexperience;
use Auth;

class TeacherHomeController extends Controller
{
    public function __construct()
   {
       $this->middleware('teacher');
   } 
    public function teacher_profile(Request $request)
    {   $user = Auth::guard('teacher')->user(); 
        $students = StudentProposal::where(
            'teacher_id',$user->id
        )->where(
            'proposal_submit_status',1
        )->get(); 
        $departments =Department::where('status',1)->orderBy('name','ASC')->get();
       // $refer_users =ReferUser::where('teacher_id',$user->id)->orderBy('id','DESC')->get();
        $refer_users =User::where(
            'wishlist_teacher_id',$user->id
        )->whereIn(
            'register_type',[3,4] // 3=q_form; 4= wishlist
        )->orderBy('id','DESC')->get();
        
        $universities =University::orderBy('name','ASC')->get();
        return view('teacher_profile',compact('students','user','departments','refer_users','universities'));
    }

    public function student_proposal_details($id){
        $user = Auth::guard('teacher')->user();
        $proposal_details = StudentProposal::find($id);
        $education_history =Institution::where(
            'student_id',$proposal_details->student_id
        )->orderBy('id','desc')->get();

        $experience =Workexperience::where(
            'student_id',$proposal_details->student_id
        )->get(); 

        if(isset($experience)){ 
            $work_experince =[]; 
            foreach($experience as $key=>$row){ 
                array_push($work_experince,$row->start_date);
                array_push($work_experince,$row->end_date); 
            } 

            $start_date = current($work_experince); 
            $end_date = end($work_experince);   
        } 
        
        return view('teacher.student_proposal_details',compact('proposal_details','education_history','start_date','end_date'));
    }

    

}
