- Updated course finder form to use HTML helper methods for cleaner syntax. - Enhanced form structure with better class management and attributes. - Implemented AJAX pagination for course listings to improve user experience. - Cleaned up resource template code for consistency and readability. - Ensured proper indentation and spacing for better maintainability. - Added missing target="_blank" attribute for external links in resource documents.
263 lines
8.6 KiB
PHP
263 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\CourseFinder\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Modules\CCMS\Models\Country;
|
|
use Modules\CCMS\Models\Institution;
|
|
use Modules\CCMS\Models\Test;
|
|
use Modules\CourseFinder\Imports\ProgramImport;
|
|
use Modules\CourseFinder\Models\Coop;
|
|
use Modules\CourseFinder\Models\Program;
|
|
use Modules\CourseFinder\Models\ProgramLevel;
|
|
use Modules\CourseFinder\Models\RequiredDocument;
|
|
use Modules\CourseFinder\Services\ProgramService;
|
|
|
|
class ProgramController extends Controller
|
|
{
|
|
protected $programService;
|
|
|
|
public function __construct(ProgramService $programService)
|
|
{
|
|
$this->programService = $programService;
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$data['title'] = 'Program List';
|
|
$data['programs'] = $this->programService->findAll($request);
|
|
$data['countryOptions'] = Country::where('status', 1)->pluck('title', 'id');
|
|
|
|
$data['institutionOptions'] = Institution::query()
|
|
->when($request->filled('country_id'), function ($query) use ($request) {
|
|
$query->where('country_id', $request->country_id);
|
|
})
|
|
->pluck('title', 'id');
|
|
|
|
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
|
$data['intakeOptions'] = Program::INTAKE;
|
|
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
|
|
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
|
$data['statusOptions'] = config('constants.page_status_options');
|
|
|
|
return view('coursefinder::program.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$data['title'] = 'Program Create';
|
|
$data['editable'] = false;
|
|
$data['intakeOptions'] = Program::INTAKE;
|
|
$data['institutionOptions'] = Institution::where('status', 1)->pluck('title', 'id');
|
|
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
|
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
|
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
|
|
$data['requiredDocumentOptions'] = RequiredDocument::where('status', 1)->pluck('title', 'id');
|
|
|
|
return view('coursefinder::program.create', $data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
$request->validate([
|
|
'title' => 'required',
|
|
]);
|
|
|
|
$input = $request->except(['prof_test_accepted']);
|
|
|
|
DB::transaction(function () use ($input, $request) {
|
|
|
|
$program = Program::create($input);
|
|
|
|
$attachData = [];
|
|
|
|
foreach ($request->prof_test_accepted as $item) {
|
|
$attachData[$item['test_id']] = [
|
|
'min_score' => $item['min_score'],
|
|
'band_score' => $item['band_score'],
|
|
];
|
|
}
|
|
|
|
$program->tests()->sync($attachData);
|
|
|
|
flash()->success('Program has been created!');
|
|
});
|
|
|
|
return redirect()->route('program.index');
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$data['title'] = 'View Program';
|
|
$data['program'] = Program::findOrFail($id);
|
|
$data['intakeOptions'] = Program::INTAKE;
|
|
return view('coursefinder::program.show', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$data['title'] = 'Edit Program';
|
|
$data['editable'] = true;
|
|
$data['program'] = Program::findOrFail($id);
|
|
$data['intakeOptions'] = Program::INTAKE;
|
|
$data['institutionOptions'] = Institution::where('status', 1)->pluck('title', 'id');
|
|
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
|
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
|
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
|
|
$data['requiredDocumentOptions'] = RequiredDocument::where('status', 1)->pluck('title', 'id');
|
|
return view('coursefinder::program.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$input = $request->except(['prof_test_accepted']);
|
|
|
|
DB::transaction(function () use ($input, $request, $id) {
|
|
$program = Program::findOrFail($id);
|
|
$program->update($input);
|
|
|
|
$attachData = [];
|
|
|
|
foreach ($request->prof_test_accepted as $item) {
|
|
$attachData[$item['test_id']] = [
|
|
'min_score' => $item['min_score'],
|
|
'band_score' => $item['band_score'],
|
|
];
|
|
}
|
|
|
|
$program->tests()->sync($attachData);
|
|
});
|
|
|
|
flash()->success('program has been updated!');
|
|
|
|
return redirect()->route('program.index')->withSuccess('Program has been updated!');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
$program = Program::findOrFail($id);
|
|
$program->delete();
|
|
|
|
flash()->success('Program has been deleted!');
|
|
} catch (\Throwable $th) {
|
|
flash()->error($th->getMessage());
|
|
}
|
|
return response()->json(['status' => 200, 'message' => 'Program has been deleted!'], 200);
|
|
}
|
|
|
|
public function getProgramByInstitution(Request $request)
|
|
{
|
|
try {
|
|
$program = Program::where(['institution_id' => $request->institution_id])
|
|
->select('id', 'title')
|
|
->get();
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $program,
|
|
'msg' => 'Fetch',
|
|
], 200);
|
|
} catch (\Throwable $th) {
|
|
return response()->json([
|
|
'status' => false,
|
|
'msg' => $th->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function import(Request $request)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
Excel::import(new ProgramImport(), $request->file('file')->store('temp'));
|
|
DB::commit();
|
|
return redirect()->back()->with('success', "Upload Succesfully");
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
return redirect()->back()->with('error', $th->getMessage());
|
|
}
|
|
}
|
|
|
|
public function getCoursesList(Request $request)
|
|
{
|
|
$data['intakes'] = Program::INTAKE;
|
|
|
|
$query = Program::query();
|
|
|
|
if ($request->filled('countries_id')) {
|
|
$query->whereRelation('institution', 'countries_id', $request->countries_id);
|
|
}
|
|
|
|
if ($request->filled('institution_id')) {
|
|
$query->where('institutions_id', $request->institution_id);
|
|
}
|
|
|
|
if ($request->filled('search')) {
|
|
$query->where(function ($q) use ($request) {
|
|
$q->where('keywords', 'like', "%{$request->search}%")
|
|
->orWhere('title', 'like', "%{$request->search}%");
|
|
});
|
|
}
|
|
|
|
if ($request->filled('programlevels_id')) {
|
|
$query->where('programlevels_id', $request->programlevels_id);
|
|
}
|
|
|
|
if ($request->filled('intake_id')) {
|
|
$query->whereJsonContains('intakes', $request->intake_id);
|
|
}
|
|
|
|
if ($request->filled('preffered_location')) {
|
|
$query->where('location', 'like', "%{$request->preffered_location}%");
|
|
}
|
|
|
|
if ($request->filled('service_id')) {
|
|
$query->whereRelation('services', 'service_id', '=', $request->service_id);
|
|
|
|
if ($request->filled('min_score')) {
|
|
$query->whereRelation('services', 'min_score', '<=', $request->min_score);
|
|
}
|
|
|
|
if ($request->filled('max_score')) {
|
|
$query->whereRelation('services', 'band_score', '<=', $request->max_score);
|
|
}
|
|
}
|
|
|
|
$data['courses'] = $query
|
|
->orderBy('title', 'asc')
|
|
->paginate(10)
|
|
->withQueryString();
|
|
|
|
$queryCount = $data['courses']->total();
|
|
|
|
if ($request->ajax()) {
|
|
$view = view('client.raffles.pages.course.list', $data)->render();
|
|
return response()->json(['html' => $view, 'queryCount' => $queryCount]);
|
|
}
|
|
}
|
|
}
|