Files
fotospiel-app/app/Filament/Resources/PackageResource.php
Codex Agent 48a2974152 Marketing packages now use localized name/description data plus seeded placeholder-
driven breakdown tables, with frontend/cards/dialog updated accordingly (database/
  migrations/2025_10_17_000001_add_description_table_to_packages.php, database/
  migrations/2025_10_17_000002_add_translation_columns_to_packages.php, database/seeders/PackageSeeder.php, app/
  Http/Controllers/MarketingController.php, resources/js/pages/marketing/Packages.tsx).
  Filament Package resource gains locale tabs, markdown editor, numeric/toggle inputs, and simplified feature
  management (app/Filament/Resources/PackageResource.php, app/Filament/Resources/PackageResource/Pages/
  CreatePackage.php, .../EditPackage.php).
  Legal pages now render markdown-backed content inside the main layout via a new controller/view route setup and
  updated footer links (app/Http/Controllers/LegalPageController.php, routes/web.php, resources/views/partials/
  footer.blade.php, resources/js/pages/legal/Show.tsx, remove old static pages).
  Translation files and shared assets updated to cover new marketing/legal strings and styling tweaks (public/
  lang/*/marketing.json, resources/lang/*/marketing.php, resources/css/app.css, resources/js/admin/components/
  LanguageSwitcher.tsx).
2025-10-17 21:20:54 +02:00

257 lines
9.4 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PackageResource\Pages;
use App\Models\Package;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ViewAction;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Repeater;
use Filament\Schemas\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Tabs as SchemaTabs;
use Filament\Schemas\Components\Tabs\Tab as SchemaTab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use UnitEnum;
use BackedEnum;
class PackageResource extends Resource
{
protected static ?string $model = Package::class;
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cube';
protected static string|UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 5;
public static function form(Schema $schema): Schema
{
$featureOptions = static::featureLabelMap();
return $schema->schema([
SchemaTabs::make('translations')
->columnSpanFull()
->tabs([
SchemaTab::make('Deutsch')
->schema([
TextInput::make('name_translations.de')
->label('Name (DE)')
->required()
->maxLength(255),
MarkdownEditor::make('description_translations.de')
->label('Beschreibung (DE)')
->required()
->columnSpanFull(),
]),
SchemaTab::make('English')
->schema([
TextInput::make('name_translations.en')
->label('Name (EN)')
->required()
->maxLength(255),
MarkdownEditor::make('description_translations.en')
->label('Description (EN)')
->required()
->columnSpanFull(),
]),
]),
Section::make('Allgemeine Einstellungen')
->columns(3)
->schema([
TextInput::make('slug')
->label('Slug')
->required()
->maxLength(191)
->unique(ignoreRecord: true),
Select::make('type')
->label('Paket-Typ')
->options([
'endcustomer' => 'Endkunde',
'reseller' => 'Reseller',
])
->required(),
TextInput::make('price')
->label('Preis')
->numeric()
->step(0.01)
->prefix('€')
->required(),
TextInput::make('max_photos')
->label('Max. Fotos')
->numeric()
->minValue(0)
->nullable(),
TextInput::make('max_guests')
->label('Max. Gäste')
->numeric()
->minValue(0)
->nullable(),
TextInput::make('gallery_days')
->label('Galeriedauer (Tage)')
->numeric()
->minValue(0)
->nullable(),
TextInput::make('max_tasks')
->label('Max. Fotoaufgaben')
->numeric()
->minValue(0)
->nullable(),
TextInput::make('max_events_per_year')
->label('Events pro Jahr')
->numeric()
->minValue(0)
->nullable()
->visible(fn ($get) => $get('type') === 'reseller'),
Toggle::make('watermark_allowed')
->label('Wasserzeichen erlaubt')
->default(true),
Toggle::make('branding_allowed')
->label('Eigenes Branding erlaubt')
->default(false),
]),
Section::make('Features & Kennzahlen')
->columns(1)
->schema([
CheckboxList::make('features')
->label('Aktive Features')
->options($featureOptions)
->columns(2)
->default([]),
Repeater::make('description_table')
->label('Kenndaten')
->schema([
TextInput::make('title')
->label('Titel')
->maxLength(255),
TextInput::make('value')
->label('Wert / Beschreibung')
->maxLength(255),
])
->addActionLabel('Eintrag hinzufügen')
->reorderable()
->columnSpanFull()
->default([]),
]),
]);
}
public static function formatFeaturesForDisplay(mixed $features): string
{
if (is_string($features)) {
$decoded = json_decode($features, true);
if (json_last_error() === JSON_ERROR_NONE) {
$features = $decoded;
}
}
if (! is_array($features)) {
return '';
}
$labels = static::featureLabelMap();
if (array_is_list($features)) {
return collect($features)
->filter(fn ($value) => is_string($value) && $value !== '')
->map(fn ($value) => $labels[$value] ?? $value)
->implode(', ');
}
return collect($features)
->filter(fn ($value) => (bool) $value)
->keys()
->map(fn ($value) => $labels[$value] ?? $value)
->implode(', ');
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name_translations.de')
->label('Name (DE)')
->searchable()
->sortable(),
TextColumn::make('name_translations.en')
->label('Name (EN)')
->toggleable(isToggledHiddenByDefault: true),
BadgeColumn::make('type')
->label('Typ')
->colors([
'info' => 'endcustomer',
'warning' => 'reseller',
]),
TextColumn::make('price')
->label('Preis')
->money('EUR')
->sortable(),
TextColumn::make('max_photos')
->label('Fotos')
->sortable(),
TextColumn::make('max_guests')
->label('Gäste')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('features')
->label('Features')
->wrap()
->formatStateUsing(fn ($state) => static::formatFeaturesForDisplay($state)),
])
->filters([
Tables\Filters\SelectFilter::make('type')
->label('Typ')
->options([
'endcustomer' => 'Endkunde',
'reseller' => 'Reseller',
]),
])
->actions([
ViewAction::make(),
EditAction::make(),
DeleteAction::make(),
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListPackages::route('/'),
'create' => Pages\CreatePackage::route('/create'),
'edit' => Pages\EditPackage::route('/{record}/edit'),
];
}
protected static function featureLabelMap(): array
{
return [
'basic_uploads' => 'Basis-Uploads',
'unlimited_sharing' => 'Unbegrenztes Teilen',
'no_watermark' => 'Kein Wasserzeichen',
'custom_branding' => 'Eigenes Branding',
'custom_tasks' => 'Eigene Aufgaben',
'advanced_analytics' => 'Erweiterte Analytics',
'advanced_reporting' => 'Erweiterte Reports',
'live_slideshow' => 'Live-Slideshow',
'priority_support' => 'Priorisierter Support',
];
}
}