Changes
This commit is contained in:
@@ -3,10 +3,127 @@
|
||||
namespace App\Filament\Resources\EducationalProgramResource\Pages;
|
||||
|
||||
use App\Filament\Resources\EducationalProgramResource;
|
||||
use App\Filament\Resources\PostResource;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateEducationalProgram extends CreateRecord
|
||||
{
|
||||
protected static string $resource = EducationalProgramResource::class;
|
||||
|
||||
protected array $seoData;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['content']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$this->record->seo()->create($this->seoData);
|
||||
}
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getBlockBySeoActiveState('paragraph', $data['content']);
|
||||
if ($rowData === null) {
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['content']);
|
||||
}
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
} $image = ($data['preview'] !== null) ? $data['preview'] : null;
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
'image' => $image,
|
||||
];
|
||||
}
|
||||
|
||||
private function generateSearchData(array $data) : string
|
||||
{
|
||||
$result = "";
|
||||
foreach ($data as $block) {
|
||||
$result .= $this->getDataFromBlocks($block);
|
||||
}
|
||||
// Удаляем лишние пробелы и переносы строк
|
||||
$result = preg_replace('/\s+/', ' ', $result);
|
||||
$result = trim($result);
|
||||
|
||||
return strtolower($result);
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
{
|
||||
$data = null;
|
||||
foreach ($content as $block) {
|
||||
$data = ($block['type'] === $name) ? $block : null;
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getBlockBySeoActiveState(string $name, array $content) : array|null
|
||||
{
|
||||
$data = [];
|
||||
foreach ($content as $block) {
|
||||
if ($block['type'] === $name) {
|
||||
$data[] = $block;
|
||||
}
|
||||
}
|
||||
$block = null;
|
||||
foreach ($data as $item) {
|
||||
if ($item['data']['seo_active'] === true) {
|
||||
$block = $item;
|
||||
}
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
{
|
||||
$data = "";
|
||||
switch ($block['type']) {
|
||||
case 'paragraph':
|
||||
$data .= strip_tags($block['data']['content']) . " ";
|
||||
break;
|
||||
case 'heading':
|
||||
$data .= strip_tags($block['data']['content']) . " ";
|
||||
break;
|
||||
case 'files':
|
||||
foreach ($block['data']['file'] as $file) {
|
||||
$data .= $file['title'] . " ";
|
||||
}
|
||||
break;
|
||||
case 'person':
|
||||
$data .= $block['data']['name'] . " ";
|
||||
break;
|
||||
case 'stepper':
|
||||
$data .= $block['data']['step_name'] . " ";
|
||||
foreach ($block['data']['steps'] as $step) {
|
||||
$data .= $step['title'] . " ";
|
||||
$data .= strip_tags($step['content']) . " ";
|
||||
}
|
||||
break;
|
||||
case 'tabs':
|
||||
foreach ($block['data']['tab'] as $item) {
|
||||
foreach ($item['content'] as $block) {
|
||||
$data .= $this->getDataFromBlocks($block);
|
||||
};
|
||||
};
|
||||
break;
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,133 @@
|
||||
|
||||
namespace App\Filament\Resources\EducationalProgramResource\Pages;
|
||||
|
||||
use App\Enums\PostStatus;
|
||||
use App\Filament\Resources\EducationalProgramResource;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EditEducationalProgram extends EditRecord
|
||||
{
|
||||
protected static string $resource = EducationalProgramResource::class;
|
||||
|
||||
|
||||
protected array $seoData;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['content']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->record->seo()->update($this->seoData);
|
||||
}
|
||||
|
||||
|
||||
private function getBlockBySeoActiveState(string $name, array $content) : array|null
|
||||
{
|
||||
$data = [];
|
||||
foreach ($content as $block) {
|
||||
if ($block['type'] === $name) {
|
||||
$data[] = $block;
|
||||
}
|
||||
}
|
||||
$block = null;
|
||||
foreach ($data as $item) {
|
||||
if ($item['data']['seo_active'] === true) {
|
||||
$block = $item;
|
||||
}
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getBlockBySeoActiveState('paragraph', $data['content']);
|
||||
if ($rowData === null) {
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['content']);
|
||||
}
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
$image = ($this->record->preview !== null) ? $this->record->preview : null;
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
'image' => $image,
|
||||
];
|
||||
}
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
{
|
||||
$data = "";
|
||||
switch ($block['type']) {
|
||||
case 'paragraph':
|
||||
$data .= strip_tags($block['data']['content']) . " ";
|
||||
break;
|
||||
case 'heading':
|
||||
$data .= strip_tags($block['data']['content']) . " ";
|
||||
break;
|
||||
case 'files':
|
||||
foreach ($block['data']['file'] as $file) {
|
||||
$data .= $file['title'] . " ";
|
||||
}
|
||||
break;
|
||||
case 'person':
|
||||
$data .= $block['data']['name'] . " ";
|
||||
break;
|
||||
case 'stepper':
|
||||
$data .= $block['data']['step_name'] . " ";
|
||||
foreach ($block['data']['steps'] as $step) {
|
||||
$data .= $step['title'] . " ";
|
||||
$data .= strip_tags($step['content']) . " ";
|
||||
}
|
||||
break;
|
||||
case 'tabs':
|
||||
foreach ($block['data']['tab'] as $item) {
|
||||
foreach ($item['content'] as $block) {
|
||||
$data .= $this->getDataFromBlocks($block);
|
||||
};
|
||||
};
|
||||
break;
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function generateSearchData(array $data) : string
|
||||
{
|
||||
$result = "";
|
||||
foreach ($data as $block) {
|
||||
$result .= $this->getDataFromBlocks($block);
|
||||
}
|
||||
// Удаляем лишние пробелы и переносы строк
|
||||
$result = preg_replace('/\s+/', ' ', $result);
|
||||
$result = trim($result);
|
||||
|
||||
return strtolower($result);
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
{
|
||||
$data = null;
|
||||
foreach ($content as $block) {
|
||||
$data = ($block['type'] === $name) ? $block : null;
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -50,7 +50,7 @@ class CreatePage extends CreateRecord
|
||||
}
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit($description, 160),
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
|
||||
@@ -36,7 +36,7 @@ class EditPage extends EditRecord
|
||||
}
|
||||
}
|
||||
|
||||
$this->record->seo()->create($this->seoData);
|
||||
$this->record->seo()->update($this->seoData);
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class EditPage extends EditRecord
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit($description, 160),
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
|
||||
@@ -69,7 +69,7 @@ class CreatePost extends CreateRecord
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit($description, 160),
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
'image' => $image,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class EditPost extends EditRecord
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit($description, 160),
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
'image' => $image,
|
||||
];
|
||||
}
|
||||
@@ -200,7 +200,6 @@ class EditPost extends EditRecord
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function postToSocialMedia($settings, $content, $title, $publish_date) : void
|
||||
{
|
||||
if ($this->record->status === PostStatus::PUBLISHED) {
|
||||
|
||||
@@ -66,7 +66,9 @@ class ClientEventController extends Controller
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
|
||||
return Inertia::render('Client/Events/Show', compact('event', 'breadcrumbs'));
|
||||
$seo = $event->seo;
|
||||
|
||||
return Inertia::render('Client/Events/Show', compact('event', 'breadcrumbs', 'seo'));
|
||||
}
|
||||
|
||||
private function getCurrentDate(Request $request): array
|
||||
|
||||
@@ -142,7 +142,10 @@ class ClientPostController extends Controller
|
||||
} else {
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
return Inertia::render('Client/Posts/Show', compact('post', 'breadcrumbs'));
|
||||
|
||||
$seo = $post->seo;
|
||||
|
||||
return Inertia::render('Client/Posts/Show', compact('post', 'breadcrumbs', 'seo'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ use App\Models\EducationalProgram;
|
||||
use App\Models\Event;
|
||||
use App\Models\MainSection;
|
||||
use App\Models\MainSlider;
|
||||
use App\Models\Page;
|
||||
use App\Models\Post;
|
||||
use App\Services\Filament\Icon\ArrayToCollectionService;
|
||||
use App\Services\Vicon\EducationalProgram\EducationalProgramService;
|
||||
@@ -32,12 +33,26 @@ use Inertia\Inertia;
|
||||
|
||||
class MainController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$info = AdmissionCampaign::get()->first()->info ?? [];
|
||||
$admissionCampaign = $this->getAdmissionCampaign();
|
||||
$educations = $this->getEducationsData();
|
||||
$sliders = $this->getActiveSliders();
|
||||
$posts = $this->getRecentPosts();
|
||||
$events = $this->getUpcomingEvents();
|
||||
|
||||
$admissionCampaign = collect($info)->reduce(function ($carry, $a) {
|
||||
$path = route('index', null, false);
|
||||
$page = Page::where('path', $path)->first();
|
||||
$seo = $page->seo;
|
||||
|
||||
return Inertia::render('Main', compact('posts', 'events', 'sliders', 'educations', 'seo'));
|
||||
}
|
||||
|
||||
private function getAdmissionCampaign()
|
||||
{
|
||||
$info = AdmissionCampaign::first()->info ?? [];
|
||||
|
||||
return collect($info)->reduce(function ($carry, $a) {
|
||||
$lvl = LevelEducational::from((int)$a['edu_name'])->name;
|
||||
$carry[$lvl] = [
|
||||
'total_programs' => $a['total_programs'],
|
||||
@@ -50,29 +65,51 @@ class MainController extends Controller
|
||||
];
|
||||
return $carry;
|
||||
}, []);
|
||||
}
|
||||
|
||||
$educations = [
|
||||
'admission_campaign' => $admissionCampaign,
|
||||
private function getEducationsData()
|
||||
{
|
||||
return [
|
||||
'admission_campaign' => $this->getAdmissionCampaign(),
|
||||
'additional_education' => [
|
||||
'educations_count' => AdditionalEducation::where('is_active', true)->count(),
|
||||
'categories_count' => AdditionalEducationCategory::where('is_active', true)->count()
|
||||
'categories_count' => AdditionalEducationCategory::where('is_active', true)->count(),
|
||||
],
|
||||
|
||||
];
|
||||
$today = new DateTime();
|
||||
$event_date_start = $today->format('Y-m-d');
|
||||
$sliders = ClientMainSliderResource::collection(MainSlider::query()->where('is_active', true)->orderBy('sort', 'asc')->get());
|
||||
$posts = PostThumbnailResource::collection(Post::query()
|
||||
->select('title', 'slug', 'authors', 'preview_text', 'category_id', 'preview', 'search_data', 'publish_at', 'created_at')
|
||||
->with('category')
|
||||
->where('publish_at', '<', Carbon::now())
|
||||
->where('status', '=', PostStatus::PUBLISHED)
|
||||
->orderBy('publish_at', 'desc')->limit(3)
|
||||
->get());
|
||||
$events = EventThumbnailResource::collection(Event::query()
|
||||
->select('title', 'slug', 'event_date_start', 'address', 'is_online', 'category_id')
|
||||
->where('event_date_start', '>=', $event_date_start)
|
||||
->orderBy('event_date_start', 'asc')->limit(3)->get());
|
||||
return Inertia::render('Main', compact('posts', 'events', 'sliders', 'educations'));
|
||||
}
|
||||
|
||||
private function getActiveSliders()
|
||||
{
|
||||
return ClientMainSliderResource::collection(
|
||||
MainSlider::where('is_active', true)
|
||||
->orderBy('sort', 'asc')
|
||||
->get()
|
||||
);
|
||||
}
|
||||
|
||||
private function getRecentPosts()
|
||||
{
|
||||
return PostThumbnailResource::collection(
|
||||
Post::select('title', 'slug', 'authors', 'preview_text', 'category_id', 'preview', 'search_data', 'publish_at', 'created_at')
|
||||
->with('category')
|
||||
->where('publish_at', '<', Carbon::now())
|
||||
->where('status', '=', PostStatus::PUBLISHED)
|
||||
->orderBy('publish_at', 'desc')
|
||||
->limit(3)
|
||||
->get()
|
||||
);
|
||||
}
|
||||
|
||||
private function getUpcomingEvents()
|
||||
{
|
||||
$event_date_start = (new DateTime())->format('Y-m-d');
|
||||
|
||||
return EventThumbnailResource::collection(
|
||||
Event::select('title', 'slug', 'event_date_start', 'address', 'is_online', 'category_id')
|
||||
->where('event_date_start', '>=', $event_date_start)
|
||||
->orderBy('event_date_start', 'asc')
|
||||
->limit(3)
|
||||
->get()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,23 +21,6 @@ use Inertia\Inertia;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function getRegisteredPages()
|
||||
{
|
||||
$pages = PageResource::collection(Page::query()
|
||||
->when(request()->input('search'), function ($query, $search) {
|
||||
$query->where('title', 'like', "%{$search}%");
|
||||
})
|
||||
->where('is_registered', true)
|
||||
->where('is_visible', true)
|
||||
->orderBy('id', 'desc')
|
||||
->paginate(request()->input('perPage', 9))
|
||||
->withQueryString());
|
||||
$filters = [
|
||||
'search' => request()->input('search'),
|
||||
];
|
||||
return Inertia::render('AdminPanel/Pages/Registered', compact('pages', 'filters'));
|
||||
}
|
||||
|
||||
public function render($path)
|
||||
{
|
||||
$page = Page::where('path', '=', $path)->with('section.pages.section', 'section.mainSection')->first();
|
||||
@@ -57,11 +40,11 @@ class PageController extends Controller
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
|
||||
$seo = $page->seo;
|
||||
|
||||
|
||||
$page = new PageResource($page);
|
||||
|
||||
|
||||
|
||||
$error = $page->code;
|
||||
|
||||
|
||||
@@ -70,9 +53,27 @@ class PageController extends Controller
|
||||
abort($error);
|
||||
}
|
||||
|
||||
return Inertia::render($page->template, compact('page', 'subSectionPages', 'breadcrumbs'));
|
||||
return Inertia::render($page->template, compact('page', 'subSectionPages', 'breadcrumbs', 'seo'));
|
||||
}
|
||||
|
||||
public function getRegisteredPages()
|
||||
{
|
||||
$pages = PageResource::collection(Page::query()
|
||||
->when(request()->input('search'), function ($query, $search) {
|
||||
$query->where('title', 'like', "%{$search}%");
|
||||
})
|
||||
->where('is_registered', true)
|
||||
->where('is_visible', true)
|
||||
->orderBy('id', 'desc')
|
||||
->paginate(request()->input('perPage', 9))
|
||||
->withQueryString());
|
||||
$filters = [
|
||||
'search' => request()->input('search'),
|
||||
];
|
||||
return Inertia::render('AdminPanel/Pages/Registered', compact('pages', 'filters'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user