add clear cache to edu programs, fix relationships bugs
This commit is contained in:
@@ -7,8 +7,8 @@ use Filament\Support\Contracts\HasColor;
|
||||
|
||||
enum BudgetEducation: int implements HasLabel, HasColor
|
||||
{
|
||||
case budget_quantity_position = 1; // Очная форма обучения
|
||||
case non_budget_quantity_position = 2; // Заочная форма обучения
|
||||
case budget_quantity_position = 1;
|
||||
case non_budget_quantity_position = 2;
|
||||
|
||||
public static function fromName(string $name): ?self {
|
||||
return match ($name) {
|
||||
|
||||
@@ -8,6 +8,9 @@ enum CacheKeys: string {
|
||||
case RECENT_POSTS_PREFIX = 'recent_posts_';
|
||||
case POSTS_PREFIX = 'posts_';
|
||||
case EDUCATION_PROGRAM_PREFIX = 'education_program_';
|
||||
case ADMISSION_CAMPAIGNS_PREFIX = 'admission_campaigns_';
|
||||
case DIRECTION_STUDIES = 'direction_studies_';
|
||||
case ADMISSION_PLANS = 'admission_plans_';
|
||||
case EDUCATION_PROGRAMS_PREFIX = 'education_programs_';
|
||||
case ADDITIONAL_EDUCATIONAL_PROGRAM_PREFIX = 'additional_education_program_';
|
||||
case ADDITIONAL_EDUCATIONAL_PROGRAMS_PREFIX = 'additional_education_programs_';
|
||||
|
||||
@@ -28,11 +28,7 @@ class ClientAdditionalEducationController extends Controller
|
||||
|
||||
public function index(Request $request): \Inertia\Response
|
||||
{
|
||||
$cacheKey = md5(serialize([
|
||||
'direction' => $request->input('direction'),
|
||||
'form' => $request->input('form'),
|
||||
'category' => $request->input('category'),
|
||||
]));
|
||||
$cacheKey = md5(serialize($request->all()));
|
||||
|
||||
// Основные данные (кешируются)
|
||||
$directionAdditionalEducations = Cache::remember(
|
||||
@@ -53,6 +49,7 @@ class ClientAdditionalEducationController extends Controller
|
||||
now()->addDay(),
|
||||
function () use ($request) {
|
||||
$query = AdditionalEducationCategory::query()
|
||||
->has('additionalEducations')
|
||||
->WithActivePrograms()
|
||||
->where('is_active', true)
|
||||
->when($request->direction, function ($q, $direction) use ($request) {
|
||||
|
||||
@@ -6,21 +6,14 @@ use App\Enums\BudgetEducation;
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Enums\FormEducation;
|
||||
use App\Enums\LevelEducational;
|
||||
use App\Http\Resources\CampaignDegreeResource;
|
||||
use App\Http\Resources\ClientNavigationResource;
|
||||
use App\Http\Resources\DirectionStudyResource;
|
||||
use App\Http\Resources\EducationalProgramFullResource;
|
||||
use App\Http\Resources\MainSectionResource;
|
||||
use App\Models\AdmissionCampaign;
|
||||
use App\Models\AdmissionPlan;
|
||||
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;
|
||||
|
||||
@@ -36,7 +29,7 @@ class ClientProgramController extends Controller
|
||||
$cacheKeyBudgets = 'education_budgets_list';
|
||||
$cacheKeySeo = 'education_programs_seo';
|
||||
|
||||
$activeCampaign = Cache::remember('active_admission_campaign', now()->addDay(), function () {
|
||||
$activeCampaign = Cache::remember(CacheKeys::ADMISSION_CAMPAIGNS_PREFIX->value, now()->addDay(), function () {
|
||||
return AdmissionCampaign::where('status', 1)->first();
|
||||
});
|
||||
|
||||
@@ -58,13 +51,14 @@ class ClientProgramController extends Controller
|
||||
$seo = Cache::remember($cacheKeySeo, now()->addDay(), function () {
|
||||
return $this->seoPageProvider->getSeoForCurrentPage();
|
||||
});
|
||||
;
|
||||
|
||||
$naprs = Cache::remember($cacheKey, now()->addHours(1), function () use ($request, $activeCampaign) {
|
||||
$naprs = Cache::remember($cacheKey, now()->addHours(), function () use ($request, $activeCampaign) {
|
||||
return DirectionStudyResource::collection(
|
||||
DirectionStudy::query()
|
||||
->withAdmissionCampaignByYear($activeCampaign->academic_year)
|
||||
->withActivePrograms()
|
||||
->with('programs.admission_plans')
|
||||
// ->with('programs.admission_plans')
|
||||
->when($request->input('level'), fn($q, $level) =>
|
||||
$q->where('lvl_edu', LevelEducational::fromName($level)->value))
|
||||
->when($request->input('form'), fn($q, $form) =>
|
||||
@@ -77,6 +71,7 @@ class ClientProgramController extends Controller
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
$data = [
|
||||
'naprs' => $naprs,
|
||||
'campaignName' => $this->getAdmissionCampaignName(),
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Services\App\Cache\AdmissionCampaignCacheService;
|
||||
|
||||
class AdmissionCampaignObserver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdmissionCampaignCacheService $admissionCampaignCacheService
|
||||
){}
|
||||
|
||||
public function saved(): void
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "updated" event.
|
||||
*/
|
||||
public function updated()
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Очистка кеша при удалении поста.
|
||||
*/
|
||||
public function deleted()
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "restored" event.
|
||||
*/
|
||||
public function restored(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,11 @@ namespace App\Providers;
|
||||
|
||||
use App\Models\AcademicJournal;
|
||||
use App\Models\AdditionalEducation;
|
||||
use App\Models\AdmissionCampaign;
|
||||
use App\Models\AdmissionPlan;
|
||||
use App\Models\ContactWidget;
|
||||
use App\Models\Department;
|
||||
use App\Models\DirectionStudy;
|
||||
use App\Models\Division;
|
||||
use App\Models\EducationalProgram;
|
||||
use App\Models\Event;
|
||||
@@ -21,8 +24,11 @@ use App\Models\SubSection;
|
||||
use App\Models\User;
|
||||
use App\Observers\AcademicJournalObserver;
|
||||
use App\Observers\AdditionalEducationObserver;
|
||||
use App\Observers\AdmissionCampaignObserver;
|
||||
use App\Observers\AdmissionPlanObserver;
|
||||
use App\Observers\ContactWidgetObserver;
|
||||
use App\Observers\DepartmentObserver;
|
||||
use App\Observers\DirectionStudyObserver;
|
||||
use App\Observers\DivisionObserver;
|
||||
use App\Observers\EducationalProgramObserver;
|
||||
use App\Observers\EventObserver;
|
||||
@@ -93,6 +99,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
Schedule::observe(ScheduleObserver::class);
|
||||
ContactWidget::observe(ContactWidgetObserver::class);
|
||||
PageReferenceList::observe(PageReferenceListObserver::class);
|
||||
AdmissionPlan::observe(AdmissionCampaignObserver::class);
|
||||
AdmissionCampaign::observe(AdmissionCampaignObserver::class);
|
||||
DirectionStudy::observe(AdmissionCampaignObserver::class);
|
||||
}
|
||||
|
||||
private static function setLocaleTime() : void {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdmissionCampaignCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
/**
|
||||
* Clear cache for specific post
|
||||
*/
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cache related to posts
|
||||
*/
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::ADMISSION_CAMPAIGNS_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::DIRECTION_STUDIES->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::ADMISSION_PLANS->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::EDUCATION_PROGRAM_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix('education_'.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
class EducationForm {
|
||||
static BUDGET_QUANTITY_POSITION = { value: 1, label: 'Бюджетные места', color: 'info', name: 'BUDGET_QUANTITY_POSITION' };
|
||||
static NON_BUDGET_QUANTITY_POSITION = { value: 2, label: 'С оплатой обучения', color: 'primary', name: 'NON_BUDGET_QUANTITY_POSITION' };
|
||||
|
||||
// Метод для получения статуса по имени
|
||||
static fromName(name) {
|
||||
return this[name] || null;
|
||||
}
|
||||
|
||||
static fromValue(value) {
|
||||
return Object.values(this).find(item => item.value == value) || null;
|
||||
}
|
||||
|
||||
|
||||
// Метод для получения имени
|
||||
getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
export default EducationForm;
|
||||
@@ -9,7 +9,7 @@ class EducationForm {
|
||||
}
|
||||
|
||||
static fromValue(value) {
|
||||
return Object.values(this).find(item => item.value === value) || null;
|
||||
return Object.values(this).find(item => item.value == value) || null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -102,9 +102,9 @@ export default {
|
||||
<div class="flex items-center gap-x-2">
|
||||
<ProgramLevelEduFilter :levels="levelsEducational" :level_filter="filters.level_filter" />
|
||||
<BasicListFilter>
|
||||
<BudgetFilter :budget_filter="filters.budget_filter" :types_budget="budgetEdu" />
|
||||
<BudgetFilter :budget_filter="filters.budget_filter" :budgets="budgetEdu" />
|
||||
<DirectionFilter :direction_studies="direction_studies" :direction_filter="filters.direction_filter" />
|
||||
<FormEducationalFilter :formEdu_filter="filters.formEdu_filter" :forms_educational="formsEdu" />
|
||||
<FormEducationalFilter :formEdu_filter="filters.formEdu_filter" :forms="formsEdu" />
|
||||
</BasicListFilter>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,7 @@ import MetaTags from "@/componentss/shared/SEO/MetaTags.vue";
|
||||
import BasicTitle from "@/componentss/ui/titles/BasicTitle.vue";
|
||||
import ProgramItemBreadcrumbs from "@/componentss/features/educationalPrograms/components/ProgramItemBreadcrumbs.vue";
|
||||
import ProgramTitle from "@/componentss/features/educationalPrograms/components/ProgramTitle.vue";
|
||||
import BudgetEducation from "@/Enum/BudgetEducation.js";
|
||||
|
||||
|
||||
export default {
|
||||
@@ -16,6 +17,9 @@ export default {
|
||||
computed: {
|
||||
EducationForm() {
|
||||
return EducationForm
|
||||
},
|
||||
BudgetForm() {
|
||||
return BudgetEducation
|
||||
}
|
||||
},
|
||||
components: {
|
||||
@@ -112,8 +116,9 @@ export default {
|
||||
<template v-for="admissionPlan in program.data.admissionPlans">
|
||||
<template v-for="contest in admissionPlan.contests">
|
||||
<div class="border rounded my-2 py-1">
|
||||
<span class="text-gray-500 text-[14px]">{{ EducationForm.fromValue(parseInt(contest.form_education)).label }}</span>
|
||||
<p class="mt-1 text-gray-600">{{ contest.position_count }} мест <span class="text-gray-400 text-[12px]">{{ formsEdu[contest.financing_source] }}</span></p>
|
||||
<span class="text-gray-500 text-[14px]">{{ EducationForm.fromValue(contest.form_education).label }}</span>
|
||||
<p v-for="place in contest.places" class="mt-1 text-gray-600"> {{ place.count }} мест <span class="text-gray-400 text-[12px]">{{ BudgetForm.fromValue(place.form_budget).label }}</span></p>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user