Rework frontend
This commit is contained in:
@@ -12,6 +12,7 @@ use App\Http\Resources\ClientNavigationResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventCategory;
|
||||
use App\Models\Page;
|
||||
use App\Services\App\Breadcrumb\BreadcrumbService;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -19,58 +20,48 @@ use Inertia\Inertia;
|
||||
|
||||
class ClientEventController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
public function __construct(private readonly BreadcrumbService $breadcrumbService){}
|
||||
|
||||
|
||||
public function index(Request $request): \Inertia\Response
|
||||
{
|
||||
$currentDate = $this->getCurrentDate($request);
|
||||
$filters = $this->getFilters();
|
||||
$eventDates = $this->getEventDates($filters); // Передаем фильтры
|
||||
$eventDates = $this->getEventDates($filters);
|
||||
|
||||
$events = $this->getEvents($currentDate);
|
||||
$categories = ClientEventCategoryResource::collection(EventCategory::has('events')->get());
|
||||
|
||||
$routeUrl = route('client.event.index');
|
||||
$path = ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
$breadcrumbs = $this->breadcrumbService->generateBreadcrumbs('client.event.index');
|
||||
|
||||
$page = Page::where('path', '=', $path)->with('section.pages.section', 'section.mainSection')->first();
|
||||
|
||||
if (isset($page->section)) {
|
||||
$breadcrumbs = [
|
||||
'mainSection' => new ClientBreadcrumbSection($page->section->mainSection),
|
||||
'subSection' => new ClientBreadcrumbSubSection($page->section),
|
||||
'page' => new ClientBreadcrumbPage($page),
|
||||
];
|
||||
} else {
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
|
||||
return Inertia::render('Client/Events/Index', compact('eventDates', 'events', 'currentDate', 'filters', 'categories', 'breadcrumbs'));
|
||||
}
|
||||
|
||||
public function show(string $slug)
|
||||
public function show(string $slug): \Inertia\Response
|
||||
{
|
||||
$event = new ClientEventFullResource(Event::where('slug', '=', $slug)->with('category')->first());
|
||||
|
||||
|
||||
$routeUrl = route('client.event.index');
|
||||
$path = ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
|
||||
$page = Page::where('path', '=', $path)->with('section.pages.section', 'section.mainSection')->first();
|
||||
|
||||
if (isset($page->section)) {
|
||||
$breadcrumbs = [
|
||||
'mainSection' => new ClientBreadcrumbSection($page->section->mainSection),
|
||||
'subSection' => new ClientBreadcrumbSubSection($page->section),
|
||||
'page' => new ClientBreadcrumbPage($page),
|
||||
];
|
||||
} else {
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
$breadcrumbs = $this->breadcrumbService->generateBreadcrumbs('client.event.index');
|
||||
|
||||
$seo = $event->seo ?? null;
|
||||
|
||||
return Inertia::render('Client/Events/Show', compact('event', 'breadcrumbs', 'seo'));
|
||||
}
|
||||
|
||||
public function archive(Request $request): \Inertia\Response
|
||||
{
|
||||
$filters = $this->getFilters();
|
||||
|
||||
$events = $this->getEventsArchive();
|
||||
$categories = ClientEventCategoryResource::collection(EventCategory::has('events')->get());
|
||||
|
||||
$breadcrumbs = $this->breadcrumbService->generateBreadcrumbs('client.event.archive');
|
||||
|
||||
|
||||
return Inertia::render('Client/Events/Archive', compact('events', 'filters', 'categories', 'breadcrumbs'));
|
||||
}
|
||||
|
||||
private function getCurrentDate(Request $request): array
|
||||
{
|
||||
$dateInput = $request->input('date');
|
||||
@@ -107,6 +98,9 @@ class ClientEventController extends Controller
|
||||
->when(request()->input('is_online'), function ($query, $value) {
|
||||
$this->applyOnlineFilter($query, $value);
|
||||
})
|
||||
->when(request()->input('search'), function ($query, $search) {
|
||||
$query->whereRaw('LOWER(title) like ?', ["%".strtolower($search)."%"]);
|
||||
})
|
||||
->when(request()->input('category'), function ($query) {
|
||||
$slugs = request()->input('category');
|
||||
if (is_array($slugs)) {
|
||||
@@ -119,6 +113,33 @@ class ClientEventController extends Controller
|
||||
->get());
|
||||
}
|
||||
|
||||
private function getEventsArchive()
|
||||
{
|
||||
return ClientEventResource::collection(Event::select('title', 'slug', 'event_date_start', 'event_time_start', 'address', 'is_online', 'category_id')
|
||||
->whereDate('event_date_start', '<', now())
|
||||
->with('category')
|
||||
->when(request()->input('is_online'), function ($query, $value) {
|
||||
$this->applyOnlineFilter($query, $value);
|
||||
})
|
||||
->when(request()->input('search'), function ($query, $search) {
|
||||
$query->whereRaw('LOWER(title) like ?', ["%".strtolower($search)."%"]);
|
||||
})
|
||||
->when(request()->input('category'), function ($query) {
|
||||
$slugs = request()->input('category');
|
||||
if (is_array($slugs)) {
|
||||
$query->whereHas('category', function ($query) use ($slugs) {
|
||||
$query->whereIn('slug', $slugs);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(request()->input('sort', 'desc'), function ($query, $sort) {
|
||||
$query->orderBy('event_date_start', $sort);
|
||||
})
|
||||
->orderBy('event_time_start', 'asc')
|
||||
->paginate(6)
|
||||
->withQueryString());
|
||||
}
|
||||
|
||||
private function getEventDates(array $filters): \Illuminate\Support\Collection
|
||||
{
|
||||
// Получаем события с учетом фильтров
|
||||
@@ -163,6 +184,8 @@ class ClientEventController extends Controller
|
||||
->sortKeys() // Сортируем ключи по возрастанию
|
||||
->values(); // Получаем массив без ключей
|
||||
|
||||
|
||||
|
||||
// Извлекаем уникальные даты из событий
|
||||
return $mappingDates;
|
||||
}
|
||||
@@ -177,6 +200,11 @@ class ClientEventController extends Controller
|
||||
}
|
||||
|
||||
return [
|
||||
'search_filter' => [
|
||||
'type' => 'search',
|
||||
'value' => request()->input('search'),
|
||||
'param' => 'search'
|
||||
],
|
||||
'category_filter' => [
|
||||
'type' => 'category',
|
||||
'value' => request()->input('category'),
|
||||
@@ -231,7 +259,7 @@ class ClientEventController extends Controller
|
||||
return $russianMonths[$month] ?? '';
|
||||
}
|
||||
|
||||
private function applyOnlineFilter($query, $isOnline)
|
||||
private function applyOnlineFilter($query, $isOnline): void
|
||||
{
|
||||
if ($isOnline === 'online') {
|
||||
$query->where('is_online', true);
|
||||
|
||||
@@ -17,6 +17,7 @@ use App\Models\MainSection;
|
||||
use App\Models\Page;
|
||||
use App\Models\Post;
|
||||
use App\Models\Tag;
|
||||
use App\Services\App\Breadcrumb\BreadcrumbService;
|
||||
use Carbon\Carbon;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -26,6 +27,8 @@ use Inertia\Inertia;
|
||||
|
||||
class ClientPostController extends Controller
|
||||
{
|
||||
public function __construct(private readonly BreadcrumbService $breadcrumbService){}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Кешируем список тегов
|
||||
@@ -129,23 +132,9 @@ class ClientPostController extends Controller
|
||||
],
|
||||
];
|
||||
|
||||
$routeUrl = route('client.post.index');
|
||||
$path = ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
$breadcrumbs = $this->breadcrumbService->generateBreadcrumbs('client.post.index');
|
||||
|
||||
// Кешируем страницу
|
||||
$page = Cache::remember('page_' . $path, now()->addHours(1), function () use ($path) {
|
||||
return Page::where('path', '=', $path)->with('section.pages.section', 'section.mainSection')->first();
|
||||
});
|
||||
|
||||
if (isset($page->section)) {
|
||||
$breadcrumbs = [
|
||||
'mainSection' => new ClientBreadcrumbSection($page->section->mainSection),
|
||||
'subSection' => new ClientBreadcrumbSubSection($page->section),
|
||||
'page' => new ClientBreadcrumbPage($page),
|
||||
];
|
||||
} else {
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
|
||||
return Inertia::render('Client/Posts/Index', compact('filters', 'posts', 'categories', 'tags', 'breadcrumbs'));
|
||||
}
|
||||
@@ -165,24 +154,7 @@ class ClientPostController extends Controller
|
||||
// Преобразуем пост в ресурс
|
||||
$postResource = new PostResource($post);
|
||||
|
||||
// Получаем путь для страницы
|
||||
$routeUrl = route('client.post.index');
|
||||
$path = ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
|
||||
// Получаем данные страницы
|
||||
$page = Page::where('path', '=', $path)
|
||||
->with('section.pages.section', 'section.mainSection')
|
||||
->first();
|
||||
|
||||
// Формируем хлебные крошки
|
||||
$breadcrumbs = null;
|
||||
if (isset($page->section)) {
|
||||
$breadcrumbs = [
|
||||
'mainSection' => new ClientBreadcrumbSection($page->section->mainSection),
|
||||
'subSection' => new ClientBreadcrumbSubSection($page->section),
|
||||
'page' => new ClientBreadcrumbPage($page),
|
||||
];
|
||||
}
|
||||
$breadcrumbs = $this->breadcrumbService->generateBreadcrumbs('client.post.index');
|
||||
|
||||
// SEO-данные
|
||||
$seo = $post->seo ?? null;
|
||||
|
||||
@@ -45,6 +45,7 @@ class ClientProgramController extends Controller
|
||||
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);
|
||||
})
|
||||
@@ -149,12 +150,13 @@ class ClientProgramController extends Controller
|
||||
{
|
||||
$budgetValue = Str::of(BudgetEducation::fromName($budget)->value)->toString();
|
||||
|
||||
|
||||
$query->whereHas('programs.admission_plans', function ($query) use ($budgetValue) {
|
||||
$query->whereJsonContains('contests', [['places' => ['form_budget' => $budgetValue]]]);
|
||||
$query->whereJsonContains('contests', ['financing_source' => $budgetValue]);
|
||||
})
|
||||
->with(['programs' => function ($query) use ($budgetValue) {
|
||||
$query->whereHas('admission_plans', function ($query) use ($budgetValue) {
|
||||
$query->whereJsonContains('contests', [['places' => ['form_budget' => $budgetValue]]]);
|
||||
$query->whereJsonContains('contests', ['financing_source' => $budgetValue]);
|
||||
});
|
||||
}]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Slider;
|
||||
|
||||
class ClientWidgetSliderController extends Controller
|
||||
{
|
||||
public function show(string $slug): ?object
|
||||
{
|
||||
$cacheKey = 'slider_' . $slug;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHour(), function () use ($slug) {
|
||||
$slider = Slider::query()
|
||||
->where('slug', $slug)
|
||||
->where('is_active', true)
|
||||
->with('slides')
|
||||
->first();
|
||||
|
||||
return $slider ?: null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -43,21 +43,21 @@ class MainController extends Controller
|
||||
// return $this->getAdmissionCampaign();
|
||||
// });
|
||||
|
||||
$educations = Cache::remember('educations_data', now()->addHour(), function () {
|
||||
return $this->getEducationsData();
|
||||
});
|
||||
// $educations = Cache::remember('educations_data', now()->addHour(), function () {
|
||||
// return $this->getEducationsData();
|
||||
// });
|
||||
|
||||
$sliders = Cache::remember('active_sliders', now()->addHour(), function () {
|
||||
return $this->getActiveSliders();
|
||||
});
|
||||
$educations = $this->getEducationsData();
|
||||
|
||||
$posts = Cache::remember('recent_posts', now()->addHour(), function () {
|
||||
return $this->getRecentPosts();
|
||||
});
|
||||
|
||||
$events = Cache::remember('upcoming_events', now()->addHour(), function () {
|
||||
return $this->getUpcomingEvents();
|
||||
});
|
||||
// $events = Cache::remember('upcoming_events', now()->addHour(), function () {
|
||||
// return $this->getUpcomingEvents();
|
||||
// });
|
||||
|
||||
$events = $this->getUpcomingEvents();
|
||||
|
||||
$path = route('index', null, false);
|
||||
$page = Cache::remember('page_' . $path, now()->addHour(), function () use ($path) {
|
||||
@@ -66,7 +66,7 @@ class MainController extends Controller
|
||||
|
||||
$seo = $page->seo ?? null;
|
||||
|
||||
return Inertia::render('Main', compact('posts', 'events', 'sliders', 'educations', 'seo'));
|
||||
return Inertia::render('Main', compact('posts', 'events', 'educations', 'seo'));
|
||||
}
|
||||
|
||||
private function getAdmissionCampaign()
|
||||
@@ -99,13 +99,6 @@ class MainController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
private function getActiveSliders()
|
||||
{
|
||||
return (ClientMainSliderResource::collection(
|
||||
MainSlider::where('is_active', true)
|
||||
->orderBy('sort', 'asc')
|
||||
->get()));
|
||||
}
|
||||
|
||||
private function getRecentPosts()
|
||||
{
|
||||
|
||||
@@ -7,9 +7,7 @@ use App\Http\Resources\EducationalProgramSearchResource;
|
||||
use App\Http\Resources\EducationGroupSearchResource;
|
||||
use App\Http\Resources\EventSearchResource;
|
||||
use App\Http\Resources\FacultySearchResource;
|
||||
use App\Http\Resources\PageResource;
|
||||
use App\Http\Resources\PageSearchResource;
|
||||
use App\Http\Resources\PostResource;
|
||||
use App\Http\Resources\PostSearchResource;
|
||||
use App\Http\Resources\UserSearchResource;
|
||||
use App\Models\AdditionalEducation;
|
||||
|
||||
Reference in New Issue
Block a user