79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\CourseFinder\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\CourseFinder\Models\Coop;
|
|
use Modules\CourseFinder\Models\Program;
|
|
|
|
class ProgramService
|
|
{
|
|
public function findAll($request)
|
|
{
|
|
return Program::when($request, function ($query) use ($request) {
|
|
if ($request->filled('country_id')) {
|
|
$query->whereRelation('institution', 'country_id', $request->country_id);
|
|
}
|
|
|
|
if ($request->filled('institution_id')) {
|
|
$query->where("institution_id", $request->institution_id);
|
|
}
|
|
|
|
if ($request->filled('programlevel_id')) {
|
|
$query->where("programlevel_id", $request->programlevel_id);
|
|
}
|
|
|
|
if ($request->filled('intake_id')) {
|
|
$intakeId = $request->intake_id;
|
|
$query->whereJsonContains('intake', $intakeId);
|
|
}
|
|
|
|
if ($request->filled('status')) {
|
|
$query->where('status', $request->status);
|
|
}
|
|
|
|
if ($request->filled('search')) {
|
|
$search = $request->search;
|
|
$query->where('keywords', 'like', "%{$search}%");
|
|
}
|
|
|
|
if ($request->filled('location')) {
|
|
$location = $request->location;
|
|
$query->where('location', 'like', "%{$location}%");
|
|
}
|
|
|
|
})->latest()->paginate(10)->withQueryString();
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
return Program::count();
|
|
}
|
|
|
|
public function where($filters)
|
|
{
|
|
return Program::where($filters);
|
|
}
|
|
|
|
public function getCoursesByStudentPreference($req)
|
|
{
|
|
$arr_Country = [];
|
|
$arr_institution = [];
|
|
$array_institution_unique = [];
|
|
foreach ($req as $request) {
|
|
array_push($arr_institution, $request['institution_id']);
|
|
}
|
|
$array_institution_unique = array_unique($arr_institution);
|
|
$course = Program::whereIn('institution_id', $array_institution_unique)->paginate(10);
|
|
return $course ?? null;
|
|
}
|
|
public function pluck(callable $query = null)
|
|
{
|
|
$baseQuery = Program::query();
|
|
if (is_callable($query)) {
|
|
$query($baseQuery);
|
|
}
|
|
return $baseQuery->pluck('title', 'id');
|
|
}
|
|
}
|