fixing search module, and schedule module

This commit is contained in:
F4ilji
2025-04-14 19:24:18 +05:00
parent c27c1c36c1
commit cac319fa81
25 changed files with 470 additions and 257 deletions
@@ -65,6 +65,11 @@ class EducationalGroupResource extends Resource
]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with('faculty');
}
public static function table(Table $table): Table
{
return $table
@@ -81,14 +86,11 @@ class EducationalGroupResource extends Resource
->searchable()
->description(fn ($record) => $record->faculty->title ?? ''),
BadgeColumn::make('education_form_id')
TextColumn::make('education_form_id')
->label('Форма обучения')
->formatStateUsing(fn ($state) => FormEducation::tryFrom($state)?->label())
->color(fn ($state) => match($state) {
FormEducation::FULL_TIME->value => 'success',
FormEducation::PART_TIME->value => 'warning',
default => 'gray',
})
->badge()
->formatStateUsing(fn ($state) => FormEducation::tryFrom($state)?->getLabel())
->color(fn ($state) => FormEducation::tryFrom($state)?->getColor())
->sortable(),
TextColumn::make('created_at')
@@ -97,6 +99,7 @@ class EducationalGroupResource extends Resource
->sortable()
->toggleable(),
])
->filters([
Tables\Filters\SelectFilter::make('faculty_id')
->label('Факультет')
@@ -30,7 +30,7 @@ class EditPost extends EditRecord
protected function mutateFormDataBeforeFill(array $data): array
{
$post = Post::query()->with(['seo', 'slide'])->find($data['id']);
$data['slide'] = $post->slide->toArray() ?? null;
$data['slide'] = $post->slide ? $post->slide->toArray() : null;
return $data;
}
+13 -24
View File
@@ -2,6 +2,7 @@
namespace App\Filament\Resources;
use App\Enums\FormEducation;
use App\Filament\Resources\ScheduleResource\Pages;
use App\Models\EducationalGroup;
use App\Models\Schedule;
@@ -48,16 +49,6 @@ class ScheduleResource extends Resource
->required()
->live()
->helperText('Выберите группу для которой создается расписание'),
Toggle::make('is_zaoch')
->label('Форма обучения')
->inline(false)
->onColor('success')
->offColor('primary')
->helperText('Очная | Заочная')
->afterStateHydrated(function (Toggle $component, $state) {
$component->state((bool) $state);
}),
]),
]),
@@ -91,10 +82,11 @@ class ScheduleResource extends Resource
fn (TemporaryUploadedFile $file): string =>
str(Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '-' . Carbon::now()->timestamp) . '.' . $file->getClientOriginalExtension()
)
->afterStateUpdated(function ($set, $state) {
$set('title', pathinfo($state?->getClientOriginalName(), PATHINFO_FILENAME));
})
->visibility('public')),
)
->afterStateUpdated(function ($set, $state) {
$set('title', pathinfo($state?->getClientOriginalName(), PATHINFO_FILENAME));
})
->visibility('public'),
])
->itemLabel(fn (array $state): ?string => $state['title'] ?? 'Новый файл')
->collapsible()
@@ -108,7 +100,7 @@ class ScheduleResource extends Resource
{
return $table
->columns([
TextColumn::make('educational_group.title')
TextColumn::make('educationalGroup.title')
->label('Учебная группа')
->sortable()
->searchable(),
@@ -118,13 +110,11 @@ class ScheduleResource extends Resource
->getStateUsing(fn ($record) => count($record->file ?? []))
->badge(),
IconColumn::make('is_zaoch')
->label('Форма обучения')
->boolean()
->trueIcon('heroicon-o-academic-cap')
->falseIcon('heroicon-o-building-office')
->trueColor('success')
->falseColor('primary'),
TextColumn::make('educationalGroup.education_form_id')
->formatStateUsing(fn ($state) => FormEducation::tryFrom($state)->getLabel())
->color(fn ($state) => FormEducation::tryFrom($state)?->getColor())
->badge()
->label('Форма обучения'),
TextColumn::make('updated_at')
->label('Обновлено')
@@ -163,8 +153,7 @@ class ScheduleResource extends Resource
->emptyStateActions([
Tables\Actions\CreateAction::make()
->label('Добавить расписание'),
])
->defaultSort('educational_group.title');
]);
}
public static function getRelations(): array
@@ -9,6 +9,7 @@ use App\Enums\LevelEducational;
use App\Http\Resources\DirectionStudyResource;
use App\Http\Resources\EducationalProgramFullResource;
use App\Models\AdmissionCampaign;
use App\Models\AdmissionPlan;
use App\Models\DirectionStudy;
use App\Models\EducationalProgram;
use App\Services\App\Seo\SeoPageProvider;
@@ -39,19 +40,33 @@ class ClientProgramController extends Controller
});
$formsEdu = Cache::remember($cacheKeyForms, now()->addDay(), function () {
return collect(FormEducation::cases())
->mapWithKeys(fn($form) => [$form->name => $form->getLabel()]);
return AdmissionPlan::distinct()
->pluck('contests')
->flatten(1)
->filter(fn ($item) => isset($item['form_education']))
->pluck('form_education')
->unique()
->map(fn ($item) => FormEducation::tryFrom((int)$item))
->filter()
->mapWithKeys(fn ($form) => [$form->name => $form->getLabel()]);
});
$budgetEdu = Cache::remember($cacheKeyBudgets, now()->addDay(), function () {
return collect(BudgetEducation::cases())
->mapWithKeys(fn($type) => [$type->name => $type->getLabel()]);
return AdmissionPlan::distinct()
->pluck('contests')
->flatten(1)
->filter(fn ($item) => isset($item['places']['form_budget']))
->pluck('places.form_budget')
->unique()
->map(fn ($item) => BudgetEducation::tryFrom($item))
->filter()
->mapWithKeys(fn ($form) => [$form->name => $form->getLabel()]);
});
$seo = Cache::remember($cacheKeySeo, now()->addDay(), function () {
return $this->seoPageProvider->getSeoForCurrentPage();
});
;
$naprs = Cache::remember($cacheKey, now()->addHours(), function () use ($request, $activeCampaign) {
return DirectionStudyResource::collection(
@@ -144,16 +159,16 @@ class ClientProgramController extends Controller
}]);
}
private function applyBudgetFilter($query, $budget)
private function applyBudgetFilter($query, $budget): void
{
$budgetValue = Str::of(BudgetEducation::fromName($budget)->value)->toString();
$query->whereHas('programs.admission_plans', function ($query) use ($budgetValue) {
$query->whereJsonContains('contests', ['financing_source' => $budgetValue]);
$query->where('contests', 'like', '%"form_budget":"'.$budgetValue.'"%');
})
->with(['programs' => function ($query) use ($budgetValue) {
$query->whereHas('admission_plans', function ($query) use ($budgetValue) {
$query->whereJsonContains('contests', ['financing_source' => $budgetValue]);
$query->where('contests', 'like', '%"form_budget":"'.$budgetValue.'"%');
});
}]);
}
@@ -39,14 +39,11 @@ class ClientScheduleController extends Controller
->get());
$schedulesByFaculty = $educationalGroups->groupBy(function ($group) {
return $group->faculty->title; // Предполагаем, что у факультета есть поле 'name'
return $group->faculty->title;
});
$schedulesByFaculty = $schedulesByFaculty->toArray();
if ($request->has('favorite') && empty($request->input('favorite'))) {
$schedulesByFaculty = [];
}
$forms_education = [];
@@ -55,11 +52,6 @@ class ClientScheduleController extends Controller
}
$filters = [
'direction_filter' => [
'type' => 'direction',
'value' => request()->input('direction'),
'param' => 'direction'
],
'form_education_filter' => [
'type' => 'form',
'value' => request()->input('form'),
+17 -7
View File
@@ -77,7 +77,7 @@ class SearchController extends Controller
$resources = $this->sortResourcesByCategory($resources, $request->query('category'));
}
$paginate_data = $this->createPaginate($resources, $request, 10);
$paginate_data = $this->createPaginate($resources, $request, 7);
$sortedData = $this->sortByType($paginate_data['paginator'], $req);
@@ -114,14 +114,24 @@ class SearchController extends Controller
private function getMatches(string $haystack, string $needle): array
{
$matches = [];
// while (($offset = mb_strpos($haystack, $needle, $offset, 'UTF-8')) !== false) {
// $left = max(0, $offset - 50);
// $right = min(mb_strlen($haystack, 'UTF-8'), $offset + 100);
// $excerpt = mb_substr($haystack, $left, $right - $left, 'UTF-8');
// $matches[] = $excerpt;
// $offset += mb_strlen($needle, 'UTF-8');
// }
$offset = 0;
while (($offset = mb_strpos($haystack, $needle, $offset, 'UTF-8')) !== false) {
$left = max(0, $offset - 50);
$right = min(mb_strlen($haystack, 'UTF-8'), $offset + 100);
$excerpt = mb_substr($haystack, $left, $right - $left, 'UTF-8');
$matches[] = $excerpt;
$offset += mb_strlen($needle, 'UTF-8');
if (($offset = mb_strpos($haystack, $needle, $offset, 'UTF-8')) !== false) {
for ($i = 0; 1 > count($matches); $i++) {
$left = max(0, $offset - 50);
$right = min(mb_strlen($haystack, 'UTF-8'), $offset + 100);
$excerpt = mb_substr($haystack, $left, $right - $left, 'UTF-8');
$matches[] = $excerpt;
}
}
return $matches;
}
+5 -5
View File
@@ -15,15 +15,15 @@ class Schedule extends Model
'file' => 'array',
];
public function subSchedules()
{
return $this->hasMany(SubSchedule::class);
}
public function faculty()
{
return $this->belongsTo(Faculty::class);
}
public function educationalGroup(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(EducationalGroup::class);
}
}