added a new component for breadcrumbs and reworked the component for getting icons using sprites
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Containers\AppStructure\Models\Page;
|
||||
use App\Containers\Article\Models\Post;
|
||||
use App\Containers\Event\Models\Event;
|
||||
use App\Containers\Widget\Models\PageReferenceList;
|
||||
use App\Filament\Resources\PageReferenceListResource\Pages;
|
||||
use Filament\Forms;
|
||||
@@ -17,6 +20,7 @@ use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use TomatoPHP\FilamentIcons\Components\IconPicker;
|
||||
|
||||
class PageReferenceListResource extends Resource
|
||||
{
|
||||
@@ -177,17 +181,42 @@ class PageReferenceListResource extends Resource
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
FileUpload::make('image')
|
||||
->label('Изображение предпросмотра')
|
||||
->helperText('Рекомендуемый формат: PNG, JPEG, JPG')
|
||||
->image()
|
||||
->optimize('webp')
|
||||
->resize(50)
|
||||
->disk('public')
|
||||
->directory('images')
|
||||
->imageEditor()
|
||||
->downloadable()
|
||||
->openable(),
|
||||
// Новый блок для выбора между изображением и иконкой
|
||||
Forms\Components\Section::make('Графическое представление')
|
||||
->description('Выберите тип графического представления')
|
||||
->collapsible()
|
||||
->schema([
|
||||
Forms\Components\Radio::make('visual_type')
|
||||
->label('Тип представления')
|
||||
->options([
|
||||
'image' => 'Изображение',
|
||||
'icon' => 'Иконка',
|
||||
])
|
||||
->default('image')
|
||||
->dehydrated(false)
|
||||
->live()
|
||||
->inline(),
|
||||
|
||||
FileUpload::make('image')
|
||||
->label('Изображение предпросмотра')
|
||||
->helperText('Рекомендуемый формат: PNG, JPEG, JPG')
|
||||
->image()
|
||||
->optimize('webp')
|
||||
->resize(50)
|
||||
->disk('public')
|
||||
->directory('images')
|
||||
->imageEditor()
|
||||
->downloadable()
|
||||
->openable()
|
||||
->visible(fn (Forms\Get $get): bool => $get('visual_type') === 'image'),
|
||||
|
||||
IconPicker::make('icon')
|
||||
->label('Иконка')
|
||||
->default('heroicon-o-academic-cap')
|
||||
->helperText('Выберите иконку для отображения')
|
||||
->columns(6)
|
||||
->visible(fn (Forms\Get $get): bool => $get('visual_type') === 'icon'),
|
||||
]),
|
||||
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
@@ -213,7 +242,6 @@ class PageReferenceListResource extends Resource
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources;
|
||||
use App\Containers\Schedule\Models\EducationalGroup;
|
||||
use App\Containers\Schedule\Models\Schedule;
|
||||
use App\Filament\Resources\ScheduleResource\Pages;
|
||||
use App\Ship\Enums\Education\FormEducation;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Grid;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Containers\Article\Models\Post;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -14,7 +15,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
class ImportApiDataPost implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, SeoGenerate;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@@ -83,26 +84,31 @@ class ImportApiDataPost implements ShouldQueue
|
||||
// Генерация уникального slug
|
||||
$slug = $this->generateSlug($post->NAME);
|
||||
|
||||
$author = $this->extractAuthor($post->DETAIL_TEXT ?? '');
|
||||
$authors = $author ? [$author] : ($post->AUTHORS ?? ['Без автора']);
|
||||
|
||||
// Создание нового поста
|
||||
Post::firstOrCreate(
|
||||
$createdPost = Post::firstOrCreate(
|
||||
['id' => $post->ID], // Условие поиска по ID
|
||||
[
|
||||
'title' => $post->NAME,
|
||||
'slug' => $slug,
|
||||
'preview_text' => strip_tags($post->PREVIEW_TEXT),
|
||||
'authors' => ['Без автора'],
|
||||
'authors' => $authors,
|
||||
'content' => $contentData, // Преобразуем в JSON
|
||||
'status' => 'published',
|
||||
'images' => $imagePaths, // Сохраняем пути к изображениям
|
||||
'preview' => $imagePaths[0],
|
||||
'preview' => $imagePaths[0] ?? null,
|
||||
'search_data' => strip_tags($content), // Преобразуем в JSON
|
||||
'reading_time' => $readingTime,
|
||||
'user_id' => 1,
|
||||
'user_id' => 2,
|
||||
'publish_at' => $post->DATE_CREATE,
|
||||
'created_at' => $post->DATE_CREATE,
|
||||
'updated_at' => $post->DATE_CREATE,
|
||||
]
|
||||
);
|
||||
|
||||
$this->createSeo($createdPost);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error importing post ID: ' . $post->ID . ' - ' . $e->getMessage());
|
||||
}
|
||||
@@ -134,4 +140,19 @@ class ImportApiDataPost implements ShouldQueue
|
||||
return max(1, round($wordCount / $wordsPerMinute));
|
||||
}
|
||||
|
||||
protected function extractAuthor(string $detailText): ?string
|
||||
{
|
||||
// Ищем последний div с text-align: right
|
||||
if (preg_match('/<div\s+style="[^"]*text-align:\s*right[^"]*"[^>]*>(.*?)<\/div>/', $detailText, $matches)) {
|
||||
$author = trim(strip_tags($matches[1]));
|
||||
|
||||
// Удаляем возможные префиксы типа "Автор:", если они есть
|
||||
$author = preg_replace('/^(Автор|Фото|Источник):\s*/ui', '', $author);
|
||||
|
||||
return $author ?: null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user