fixing search module, and schedule module
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user