Rework admin panel and other
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\BudgetEducation;
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Enums\FormEducation;
|
||||
use App\Enums\LevelEducational;
|
||||
use App\Http\Resources\CampaignDegreeResource;
|
||||
@@ -16,121 +17,150 @@ use App\Models\CampaignDegree;
|
||||
use App\Models\DirectionStudy;
|
||||
use App\Models\EducationalProgram;
|
||||
use App\Models\MainSection;
|
||||
use App\Services\App\Seo\SeoPageProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ClientProgramController extends Controller
|
||||
{
|
||||
public function __construct(readonly SeoPageProvider $seoPageProvider){}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$activeCampaign = AdmissionCampaign::query()->where('status', 1)->first();
|
||||
$cacheKey = CacheKeys::EDUCATION_PROGRAMS_PREFIX->value . md5(serialize($request->all()));
|
||||
|
||||
$uniqueValues = EducationalProgram::distinct()->pluck('lvl_edu');
|
||||
$levelsEducational = $uniqueValues->mapWithKeys(function ($level) {
|
||||
return [$level->name => $level->getLabel()];
|
||||
});
|
||||
$data = Cache::remember($cacheKey, now()->addHours(1), function () use ($request) {
|
||||
$activeCampaign = AdmissionCampaign::query()->where('status', 1)->first();
|
||||
|
||||
$direction_studies = DirectionStudy::query()
|
||||
->withAdmissionCampaignByYear($activeCampaign->academic_year)
|
||||
->withActivePrograms()
|
||||
->get();
|
||||
$uniqueValues = EducationalProgram::distinct()->pluck('lvl_edu');
|
||||
$levelsEducational = $uniqueValues->mapWithKeys(function ($level) {
|
||||
return [$level->name => $level->getLabel()];
|
||||
});
|
||||
|
||||
$level = request()->input('level');
|
||||
$form = request()->input('form');
|
||||
$budget = request()->input('budget');
|
||||
|
||||
$naprs = DirectionStudyResource::collection(
|
||||
DirectionStudy::query()
|
||||
$direction_studies = DirectionStudy::query()
|
||||
->withAdmissionCampaignByYear($activeCampaign->academic_year)
|
||||
->withActivePrograms()
|
||||
->with('programs.admission_plans')
|
||||
->when($level, function ($query) use ($level) {
|
||||
$query->where('lvl_edu', LevelEducational::fromName($level)->value);
|
||||
})
|
||||
->when($form, function ($query) use ($form) {
|
||||
$this->applyFormFilter($query, $form);
|
||||
})
|
||||
->when($budget, function ($query) use ($budget) {
|
||||
$this->applyBudgetFilter($query, $budget);
|
||||
})
|
||||
->when(request()->input('direction'), function ($query) {
|
||||
$slugs = request()->input('direction');
|
||||
if (is_array($slugs)) {
|
||||
$query->whereIn('slug', $slugs);
|
||||
}
|
||||
})
|
||||
->get()
|
||||
);
|
||||
->get();
|
||||
|
||||
$level = request()->input('level');
|
||||
$form = request()->input('form');
|
||||
$budget = request()->input('budget');
|
||||
|
||||
$naprs = DirectionStudyResource::collection(
|
||||
DirectionStudy::query()
|
||||
->withAdmissionCampaignByYear($activeCampaign->academic_year)
|
||||
->withActivePrograms()
|
||||
->with('programs.admission_plans')
|
||||
->when($level, function ($query) use ($level) {
|
||||
$query->where('lvl_edu', LevelEducational::fromName($level)->value);
|
||||
})
|
||||
->when($form, function ($query) use ($form) {
|
||||
$this->applyFormFilter($query, $form);
|
||||
})
|
||||
->when($budget, function ($query) use ($budget) {
|
||||
$this->applyBudgetFilter($query, $budget);
|
||||
})
|
||||
->when(request()->input('direction'), function ($query) {
|
||||
$slugs = request()->input('direction');
|
||||
if (is_array($slugs)) {
|
||||
$query->whereIn('slug', $slugs);
|
||||
}
|
||||
})
|
||||
->get()
|
||||
);
|
||||
|
||||
$campaignName = $this->getAdmissionCampaignName();
|
||||
$formsEducational = FormEducation::cases();
|
||||
$formsEducational = collect($formsEducational);
|
||||
$formsEdu = $formsEducational->mapWithKeys(function ($formEducational) {
|
||||
return [$formEducational->name => $formEducational->getLabel()];
|
||||
});
|
||||
$typesBudget = BudgetEducation::cases();
|
||||
$typesBudget = collect($typesBudget);
|
||||
$budgetEdu = $typesBudget->mapWithKeys(function ($typeBudget) {
|
||||
return [$typeBudget->name => $typeBudget->getLabel()];
|
||||
});
|
||||
|
||||
$filters = [
|
||||
'level_filter' => [
|
||||
'type' => 'level',
|
||||
'value' => request()->input('level'),
|
||||
'param' => 'level'
|
||||
],
|
||||
'budget_filter' => [
|
||||
'type' => 'budget',
|
||||
'value' => request()->input('budget'),
|
||||
'param' => 'budget'
|
||||
],
|
||||
'formEdu_filter' => [
|
||||
'type' => 'form',
|
||||
'value' => request()->input('form'),
|
||||
'param' => 'form'
|
||||
],
|
||||
'direction_filter' => [
|
||||
'type' => 'direction',
|
||||
'value' => request()->input('direction'),
|
||||
'param' => 'direction'
|
||||
],
|
||||
];
|
||||
|
||||
$seo = $this->seoPageProvider->getSeoForCurrentPage();
|
||||
|
||||
|
||||
$campaignName = $this->getAdmissionCampaignName();
|
||||
$formsEducational = FormEducation::cases();
|
||||
$formsEducational = collect($formsEducational);
|
||||
$formsEdu = $formsEducational->mapWithKeys(function ($formEducational) {
|
||||
return [$formEducational->name => $formEducational->getLabel()];
|
||||
});
|
||||
$typesBudget = BudgetEducation::cases();
|
||||
$typesBudget = collect($typesBudget);
|
||||
$budgetEdu = $typesBudget->mapWithKeys(function ($typeBudget) {
|
||||
return [$typeBudget->name => $typeBudget->getLabel()];
|
||||
});
|
||||
|
||||
$filters = [
|
||||
'level_filter' => [
|
||||
'type' => 'level',
|
||||
'value' => request()->input('level'),
|
||||
'param' => 'level'
|
||||
],
|
||||
'budget_filter' => [
|
||||
'type' => 'budget',
|
||||
'value' => request()->input('budget'),
|
||||
'param' => 'budget'
|
||||
],
|
||||
'formEdu_filter' => [
|
||||
'type' => 'form',
|
||||
'value' => request()->input('form'),
|
||||
'param' => 'form'
|
||||
],
|
||||
'direction_filter' => [
|
||||
'type' => 'direction',
|
||||
'value' => request()->input('direction'),
|
||||
'param' => 'direction'
|
||||
],
|
||||
];
|
||||
|
||||
return Inertia::render('Client/Programs/Index',
|
||||
compact(
|
||||
return compact(
|
||||
'naprs',
|
||||
'campaignName',
|
||||
'levelsEducational',
|
||||
'filters',
|
||||
'formsEdu',
|
||||
'budgetEdu',
|
||||
'direction_studies'
|
||||
));
|
||||
'direction_studies',
|
||||
'seo'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
return Inertia::render('Client/Programs/Index', $data);
|
||||
}
|
||||
|
||||
public function show(string $slug)
|
||||
{
|
||||
$program = new EducationalProgramFullResource(EducationalProgram::query()->where('slug', $slug)->with(['admission_plans', 'directionStudy'])->firstOrFail());
|
||||
$formsEducational = BudgetEducation::cases();
|
||||
$formsEducational = collect($formsEducational);
|
||||
$formsEdu = $formsEducational->mapWithKeys(function ($formEducational) {
|
||||
return [$formEducational->value => $formEducational->getLabel()];
|
||||
$cacheKey = CacheKeys::EDUCATION_PROGRAM_PREFIX->value . md5($slug);
|
||||
|
||||
$data = Cache::remember($cacheKey, now()->addHours(1), function () use ($slug) {
|
||||
$program = new EducationalProgramFullResource(
|
||||
$programModel = EducationalProgram::query()
|
||||
->where('slug', $slug)
|
||||
->with(['admission_plans', 'directionStudy', 'seo'])
|
||||
->firstOrFail()
|
||||
);
|
||||
|
||||
$formsEducational = BudgetEducation::cases();
|
||||
$formsEducational = collect($formsEducational);
|
||||
$formsEdu = $formsEducational->mapWithKeys(function ($formEducational) {
|
||||
return [$formEducational->value => $formEducational->getLabel()];
|
||||
});
|
||||
|
||||
$seo = $this->seoPageProvider->getSeoForModel($programModel);
|
||||
|
||||
return compact('program', 'formsEdu', 'seo');
|
||||
});
|
||||
|
||||
$seo = $program->seo ?? null;
|
||||
return Inertia::render('Client/Programs/Show', compact('program', 'formsEdu', 'seo'));
|
||||
return Inertia::render('Client/Programs/Show', $data);
|
||||
}
|
||||
|
||||
private function getAdmissionCampaignName() : string
|
||||
private function getAdmissionCampaignName(): string
|
||||
{
|
||||
$campaign = AdmissionCampaign::query()->where('status', 1)->first();
|
||||
return $campaign->name;
|
||||
}
|
||||
$cacheKey = CacheKeys::EDUCATION_PROGRAM_PREFIX->value . 'active_campaign_name';
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHours(1), function () {
|
||||
$campaign = AdmissionCampaign::query()->where('status', 1)->first();
|
||||
return $campaign->name;
|
||||
});
|
||||
}
|
||||
|
||||
private function applyFormFilter($query, $form)
|
||||
{
|
||||
@@ -150,7 +180,6 @@ class ClientProgramController extends Controller
|
||||
{
|
||||
$budgetValue = Str::of(BudgetEducation::fromName($budget)->value)->toString();
|
||||
|
||||
|
||||
$query->whereHas('programs.admission_plans', function ($query) use ($budgetValue) {
|
||||
$query->whereJsonContains('contests', ['financing_source' => $budgetValue]);
|
||||
})
|
||||
@@ -160,5 +189,4 @@ class ClientProgramController extends Controller
|
||||
});
|
||||
}]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user