123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Http;
- use App\Http\Controllers\Controller;
- use App\Models\Admin;
- use App\Models\Course;
- use App\Models\Destination;
- use App\Models\Level;
- use App\Models\Institute;
- use App\Traits\CourseSearch;
- use Auth;
- use Mail;
- use Session;
- use DB;
- class CourseController extends Controller
- {
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
-
- }
- public function filters()
- {
- $destinations = model('Destination')::select('id','name','name as label','sams_id as refId')->orderBy('name')->get();
- $levels = model('Level')::select('id','name','name as label','sams_id as refId')->orderBy('name')->get();
- return [
- 'destinations' => $destinations,
- 'levels' => $levels
- ];
- }
- /**
- * Show the application dashboard.
- *
- * @return \Illuminate\Http\Response
- */
- public function search(Request $request)
- {
- $courseIds = CourseSearch::searchByRequest($request);
- return [
- 'search_results' => $this->getCourseDetails($courseIds),
- 'filter_data' => $this->filterData($request)
- ];
- }
- function getCourseDetails($courseIds){
- $data = [];
- $result_ids = model('Course')::whereIn('id',$courseIds)->select('courses.*', \DB::raw('(SELECT name FROM institutes WHERE courses.institute_id = institutes.id ) as sort'))->orderBy('sort')->pluck('id')->toArray();
- foreach($result_ids as $id){
- $course = model('Course')::find($id);
- $campuses = model('CourseCampus')::where('course_id', $course->id)->pluck('campus_id')->toArray();
- $intakes = model('CourseIntake')::where('course_id', $course->id)->pluck('intake')->toArray();
- $intakeMonths = [];
- foreach($intakes as $intake){
- array_push($intakeMonths, date("M", mktime(0, 0, 0, $intake, 1)));
- }
- $data[] = [
- 'destination' => $course->destination->name,
- 'flag' => flag_url($course->destination->short_code),
- 'institute' => $course->institute->name,
- 'university_link' => $course->institute->website_link,
- 'campuses' => model('Campus')::whereIn('id', $campuses)->pluck('name')->toArray(),
- 'level' => $course->level->name,
- 'courseName' => $course->name,
- 'length' => $course->length.' months',
- 'tution_fee' => $course->tution_fee == 0?'-':$course->destination->currency.number_format($course->tution_fee, 0),
- 'intakes' => count($intakeMonths) > 0?$intakeMonths:'-',
- 'ielts' => $course->ielts?$course->ielts:'-',
- 'toefl' => $course->toefl?$course->toefl:'-',
- 'pte' => $course->pte?$course->pte:'-',
- 'duolingo' => $course->duolingo?$course->duolingo:'-',
- 'scholarship' => $course->scholarship?$course->scholarship:'-',
- 'deposit_required' => $course->deposit_required,
- //'min_gpa' => $course->min_gpa,
- //'ucas_fee' => $course->ucas_fee,
- 'sop' => $course->sop,
- 'cv' => $course->cv,
- 'reference' => $course->reference,
- 'entry_requirements' => $course->entry_requirement
- ];
- }
- return $data;
- }
- function filterData($request){
- $intakes = model('CourseIntake')::select('intake')->distinct()->orderBy('intake')->pluck('intake')->toArray();
- foreach($intakes as $intake){
- $intakeList[] = [
- 'id' => $intake,
- 'label' => date("F", mktime(0, 0, 0, $intake, 1))
- ];
- }
- $english_tests = ['IELTS', 'TOEFL', 'PTE', 'Duolingo'];
- foreach($english_tests as $test){
- $english_testsList[] = [
- 'id' => strtolower($test),
- 'label' => $test
- ];
- }
- $durations = [1,2,3,4];
- foreach($durations as $duration){
- $durationsList[] = [
- 'id' => (12 * $duration),
- 'label' => $duration==1?$duration.' Year':$duration.' Years'
- ];
- }
- return [
- 'institutes' => model('Institute')::where('destination_id', $request->destination_id)->select('id','name','name as label','sams_id as refId')->orderBy('name')->get(),
- 'intakes' => $intakeList,
- 'english_tests' => $english_testsList,
- 'durations' => $durationsList
- ];
- }
- }
|