Files
citrus/app/Filament/Admin/Resources/Blogs/Tables/BlogsTable.php
T

195 lines
8.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Admin\Resources\Blogs\Tables;
use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Forms\Components\Textarea;
use Filament\Notifications\Notification;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class BlogsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
ImageColumn::make('featured_image')
->label(__('blog.featured_image_field'))
->disk('public')
->square()
->size(60),
TextColumn::make('title')
->label(__('blog.table_title'))
->searchable()
->sortable()
->limit(50),
TextColumn::make('status')
->label(__('blog.table_status'))
->badge()
->color(fn (?string $state): string => match ($state) {
'draft' => 'gray',
'pending' => 'info',
'published' => 'success',
'rejected' => 'danger',
'archived' => 'warning',
default => 'gray',
})
->formatStateUsing(fn (?string $state): string => match ($state) {
'draft' => 'Taslak',
'pending' => 'Onay Bekliyor',
'published' => 'Yayınlandı',
'rejected' => 'Revize İstendi',
'archived' => 'Arşivlendi',
default => $state ?? '-',
}),
TextColumn::make('careerApplication.name')
->label('Stajyer')
->searchable()
->sortable()
->badge()
->color('purple')
->toggleable(),
TextColumn::make('intern_category')
->label('Staj Konusu')
->formatStateUsing(fn (?string $state): string => match ($state) {
'experience' => '1. Staj Tecrübesi',
'technical_challenge' => '2. Teknik Zorluklar',
'product_showcase' => '3. Ürün Tanıtımı',
default => $state ?? '-',
})
->badge()
->toggleable(),
TextColumn::make('author.name')
->label(__('blog.table_author'))
->formatStateUsing(fn ($state, $record) => $record->author_name)
->searchable(query: function ($query, string $search) {
$query->where(function ($q) use ($search) {
$q->whereHas('author', fn ($sub) => $sub->where('name', 'like', "%{$search}%"))
->orWhereHas('careerApplication', fn ($sub) => $sub->where('name', 'like', "%{$search}%"));
});
})
->sortable(),
TextColumn::make('category.name')
->label(__('blog.table_category'))
->searchable()
->sortable(),
TextColumn::make('published_at')
->label(__('blog.table_published_at'))
->dateTime('d.m.Y H:i')
->sortable(),
TextColumn::make('view_count')
->label(__('blog.table_view_count'))
->sortable()
->alignCenter(),
ToggleColumn::make('is_featured')
->label(__('blog.is_featured_field'))
->alignCenter(),
])
->filters([
SelectFilter::make('status')
->label(__('blog.status_field'))
->options([
'draft' => 'Taslak',
'pending' => 'Onay Bekliyor',
'published' => 'Yayınlandı',
'rejected' => 'Revize İstendi',
'archived' => 'Arşivlendi',
]),
SelectFilter::make('intern_category')
->label('Staj Blog Konusu')
->options([
'experience' => '1. Staj Tecrübesi',
'technical_challenge' => '2. Teknik Zorluklar',
'product_showcase' => '3. Ürün Tanıtımı',
]),
TernaryFilter::make('is_intern_blog')
->label('Sadece Stajyer Yazıları')
->queries(
true: fn ($query) => $query->whereNotNull('career_application_id'),
false: fn ($query) => $query->whereNull('career_application_id'),
),
SelectFilter::make('category_id')
->label(__('blog.category_field'))
->relationship('category', 'name'),
])
->recordActions([
Action::make('approve')
->label('Onayla & Yayınla')
->icon('heroicon-o-check-circle')
->color('success')
->visible(fn ($record) => in_array($record->status, ['pending', 'draft', 'rejected']))
->action(function ($record) {
$record->status = 'published';
$record->published_at = now();
$record->admin_feedback = null;
$record->save();
Notification::make()
->title('Yazı Onaylandı')
->body('Blog yazısı başarıyla yayınlandı.')
->success()
->send();
}),
Action::make('reject')
->label('Revize İstə')
->icon('heroicon-o-x-circle')
->color('danger')
->visible(fn ($record) => in_array($record->status, ['pending', 'published']))
->form([
Textarea::make('admin_feedback')
->label('Revizyon Gerekçesi / Stajyere Not')
->required()
->placeholder('Örn: Başlığı ve içerikteki kod bloklarını düzenleyiniz.'),
])
->action(function ($record, array $data) {
$record->status = 'rejected';
$record->admin_feedback = $data['admin_feedback'];
$record->save();
Notification::make()
->title('Revizyon Talebi Gönderildi')
->body('Stajyere revizyon bildirimi iletildi.')
->warning()
->send();
}),
EditAction::make()
->label(__('blog.edit')),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make()
->label(__('blog.delete')),
RestoreBulkAction::make()
->label(__('blog.restore')),
ForceDeleteBulkAction::make()
->label(__('blog.force_delete')),
]),
])
->defaultSort('created_at', 'desc');
}
}