<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use \App\Helpers\PageSL;
use App\Models\University;
use App\Models\MarketCountry;
use App\Models\Department;
use App\Models\ResearchInterest;
use App\Models\Requirement;
use App\StudentProposal;
use App\User;
use Auth;

class SubContentController extends Controller
{
    public function get(Request $req, $name){


		$carbon=new \Carbon\Carbon;

		$data=[
			'carbon'=>$carbon,
			'name'=>$name
		];

		if($name=="load_market_countries"){
			$user=Auth::guard('admin')->user();
			$data['market_countries'] = MarketCountry::where(
                'status', 1
            )->select(
                'market_countries.*', \DB::raw('(SELECT name FROM countries WHERE market_countries.country_id = countries.id ) as sort')
            )->orderBy('sort')->get();

		}elseif($name=='country_wise_university'){
			$user=Auth::guard('admin')->user();
			$data['universities'] =University::orderBy('name','ASC')->get();

		}elseif($name=="load_profile_info"){
			$tuser=Auth::guard('teacher')->user();
			$data['tuser'] =$tuser;
			$data['students'] = StudentProposal::where('teacher_id',$tuser->id)->get();

		}elseif($name=="load_department"){
			$data['departments'] =Department::where('status',1)->orderBy('name','ASC')->get();

		}elseif($name=="load_research_interest"){
			$tuser=Auth::guard('teacher')->user();
			$data['resarch'] =ResearchInterest::where('teacher_id',$tuser->id)->orderBy('id','DESC')->get();
		}elseif($name=="edit_university_load"){
			$user=Auth::guard('admin')->user();
			$data['edit_data'] =University::find($req->edit_id);
			$data['market_countries'] = MarketCountry::where(
                'status', 1
            )->select(
                'market_countries.*', \DB::raw('(SELECT name FROM countries WHERE market_countries.country_id = countries.id ) as sort')
            )->orderBy('sort')->get();

		}elseif($name=="edit_department_form"){
			$data['edit_dept'] =Department::find($req->dep_id);

		}elseif($name=="load_ref_no_available_info"){

            if($req->teacher_ref_no){
                $data['teacher'] =User::where(
                    'ref_no',$req->teacher_ref_no
                )->where(
                    'is_available',1
                )->first();
            }

        }elseif($name=="document_required_load"){
			$proposal_details = StudentProposal::find($req->id);
			$data['proposal_details'] =$proposal_details;
			$data['requirements'] = Requirement::where('std_proposal_id',$proposal_details->id)->get();
		}elseif($name=="upload_document_required"){
			$data['requirements'] = Requirement::find($req->req_id);
			$std_pro_id =$data['requirements'];
			$data['proposal_details'] = StudentProposal::where('id',$std_pro_id->std_proposal_id)->first();
		}else $name='default';
		//$data['page_sl']=new PageSL($data['chapter_details']);
		return view("admin.sub_contents.{$name}", $data);

	}
}
