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).
This commit is contained in:
@@ -4,22 +4,26 @@ namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\PackageResource\Pages;
|
||||
use App\Models\Package;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
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;
|
||||
|
||||
@@ -35,190 +39,141 @@ class PackageResource extends Resource
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$featureOptions = static::featureLabelMap();
|
||||
|
||||
return $schema->schema([
|
||||
TextInput::make('name')
|
||||
->label('Name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('type')
|
||||
->label('Type')
|
||||
->options([
|
||||
'endcustomer' => 'Endcustomer',
|
||||
'reseller' => 'Reseller',
|
||||
])
|
||||
->required(),
|
||||
TextInput::make('price')
|
||||
->label('Price')
|
||||
->prefix('€')
|
||||
->numeric()
|
||||
->step(0.01)
|
||||
->required()
|
||||
->default(0),
|
||||
TextInput::make('max_photos')
|
||||
->label('Max Photos')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
TextInput::make('max_guests')
|
||||
->label('Max Guests')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
TextInput::make('gallery_days')
|
||||
->label('Gallery Days')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
TextInput::make('max_tasks')
|
||||
->label('Max Tasks')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
Toggle::make('watermark_allowed')
|
||||
->label('Watermark Allowed')
|
||||
->default(true),
|
||||
Toggle::make('branding_allowed')
|
||||
->label('Branding Allowed')
|
||||
->default(false),
|
||||
TextInput::make('max_events_per_year')
|
||||
->label('Max Events per Year')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
Repeater::make('features')
|
||||
->label('Features')
|
||||
->schema([
|
||||
TextInput::make('key')
|
||||
->label('Feature Key'),
|
||||
TextInput::make('value')
|
||||
->label('Feature Value'),
|
||||
])
|
||||
->columns(2)
|
||||
->defaultItems(0),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public static function featuresToRepeaterItems(mixed $features): array
|
||||
{
|
||||
if (is_string($features)) {
|
||||
$decoded = json_decode($features, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
$features = json_last_error() === JSON_ERROR_NONE ? $decoded : null;
|
||||
}
|
||||
|
||||
if ($features === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($features)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! array_is_list($features)) {
|
||||
return collect($features)
|
||||
->map(function ($value, $key) {
|
||||
return [
|
||||
'key' => (string) $key,
|
||||
'value' => is_bool($value) ? ($value ? 'true' : 'false') : (string) $value,
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
return collect($features)
|
||||
->map(function ($item) {
|
||||
if (is_array($item)) {
|
||||
return [
|
||||
'key' => (string) ($item['key'] ?? ''),
|
||||
'value' => (string) ($item['value'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'key' => (string) $item,
|
||||
'value' => 'true',
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public static function featuresFromRepeaterItems(mixed $items): array
|
||||
{
|
||||
if (! is_array($items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$features = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (! is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = isset($item['key']) ? trim((string) $item['key']) : '';
|
||||
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $item['value'] ?? true;
|
||||
|
||||
if (is_string($value)) {
|
||||
$normalized = strtolower(trim($value));
|
||||
|
||||
if (in_array($normalized, ['1', 'true', 'yes', 'on'], true)) {
|
||||
$value = true;
|
||||
} elseif (in_array($normalized, ['0', 'false', 'no', 'off'], true)) {
|
||||
$value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $value['value'] ?? $value['enabled'] ?? true;
|
||||
}
|
||||
|
||||
$features[$key] = (bool) $value;
|
||||
}
|
||||
|
||||
return $features;
|
||||
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
|
||||
{
|
||||
$map = $features;
|
||||
|
||||
if (! is_array($map)) {
|
||||
if (is_string($map)) {
|
||||
$decoded = json_decode($map, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
$map = json_last_error() === JSON_ERROR_NONE ? $decoded : [];
|
||||
} else {
|
||||
$map = [];
|
||||
if (is_string($features)) {
|
||||
$decoded = json_decode($features, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$features = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
if (! array_is_list($map)) {
|
||||
return collect($map)
|
||||
->filter(fn ($value) => (bool) $value)
|
||||
->keys()
|
||||
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($map)
|
||||
->map(function ($item) {
|
||||
if (is_array($item)) {
|
||||
return (string) ($item['key'] ?? '');
|
||||
}
|
||||
|
||||
return (string) $item;
|
||||
})
|
||||
->filter()
|
||||
return collect($features)
|
||||
->filter(fn ($value) => (bool) $value)
|
||||
->keys()
|
||||
->map(fn ($value) => $labels[$value] ?? $value)
|
||||
->implode(', ');
|
||||
}
|
||||
|
||||
@@ -226,35 +181,45 @@ class PackageResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Name')
|
||||
TextColumn::make('name_translations.de')
|
||||
->label('Name (DE)')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('type')
|
||||
->label('Type')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'endcustomer' => 'info',
|
||||
'reseller' => 'warning',
|
||||
default => 'gray',
|
||||
}),
|
||||
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('Price')
|
||||
->label('Preis')
|
||||
->money('EUR')
|
||||
->sortable(),
|
||||
IconColumn::make('max_photos')
|
||||
->label('Max Photos')
|
||||
->icon('heroicon-o-photo')
|
||||
->color('primary'),
|
||||
TextColumn::make('max_photos')
|
||||
->label('Fotos')
|
||||
->sortable(),
|
||||
TextColumn::make('max_guests')
|
||||
->label('Gäste')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('features')
|
||||
->label('Features')
|
||||
->formatStateUsing(fn ($state) => static::formatFeaturesForDisplay($state))
|
||||
->limit(50),
|
||||
->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(),
|
||||
])
|
||||
@@ -265,13 +230,6 @@ class PackageResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
@@ -280,4 +238,19 @@ class PackageResource extends Resource
|
||||
'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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,4 @@ use Filament\Resources\Pages\CreateRecord;
|
||||
class CreatePackage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresFromRepeaterItems($data['features'] ?? []);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,19 +17,4 @@ class EditPackage extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresToRepeaterItems($data['features'] ?? null);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresFromRepeaterItems($data['features'] ?? []);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
90
app/Http/Controllers/LegalPageController.php
Normal file
90
app/Http/Controllers/LegalPageController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\LegalPage;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use League\CommonMark\Environment\Environment;
|
||||
use League\CommonMark\Extension\Autolink\AutolinkExtension;
|
||||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
||||
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
|
||||
use League\CommonMark\Extension\Table\TableExtension;
|
||||
use League\CommonMark\Extension\TaskList\TaskListExtension;
|
||||
use League\CommonMark\MarkdownConverter;
|
||||
|
||||
class LegalPageController extends Controller
|
||||
{
|
||||
public function show(?string $slug = null): Response
|
||||
{
|
||||
$resolvedSlug = $this->resolveSlug($slug);
|
||||
|
||||
$page = LegalPage::query()
|
||||
->where('slug', $resolvedSlug)
|
||||
->where('is_published', true)
|
||||
->orderByDesc('version')
|
||||
->first();
|
||||
|
||||
if (! $page) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$locale = app()->getLocale();
|
||||
$title = $page->title[$locale]
|
||||
?? $page->title[$page->locale_fallback]
|
||||
?? $page->title['de']
|
||||
?? $page->title['en']
|
||||
?? Str::title($resolvedSlug);
|
||||
|
||||
$bodyMarkdown = $page->body_markdown[$locale]
|
||||
?? $page->body_markdown[$page->locale_fallback]
|
||||
?? reset($page->body_markdown)
|
||||
?? '';
|
||||
|
||||
$effectiveFrom = optional($page->effective_from);
|
||||
|
||||
return Inertia::render('legal/Show', [
|
||||
'seoTitle' => $title . ' - ' . config('app.name', 'Fotospiel'),
|
||||
'title' => $title,
|
||||
'content' => $this->convertMarkdownToHtml($bodyMarkdown),
|
||||
'effectiveFrom' => $effectiveFrom ? $effectiveFrom->toDateString() : null,
|
||||
'effectiveFromLabel' => $effectiveFrom
|
||||
? __('legal.effective_from', ['date' => $effectiveFrom->translatedFormat('d. F Y')])
|
||||
: null,
|
||||
'versionLabel' => __('legal.version', ['version' => $page->version]),
|
||||
'slug' => $resolvedSlug,
|
||||
]);
|
||||
}
|
||||
|
||||
private function resolveSlug(?string $slug): string
|
||||
{
|
||||
$slug = strtolower($slug ?? '');
|
||||
|
||||
$aliases = [
|
||||
'imprint' => 'impressum',
|
||||
'privacy' => 'datenschutz',
|
||||
'terms' => 'agb',
|
||||
];
|
||||
|
||||
return $aliases[$slug] ?? $slug ?: 'impressum';
|
||||
}
|
||||
|
||||
private function convertMarkdownToHtml(string $markdown): string
|
||||
{
|
||||
$environment = new Environment([
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
|
||||
$environment->addExtension(new CommonMarkCoreExtension());
|
||||
$environment->addExtension(new TableExtension());
|
||||
$environment->addExtension(new AutolinkExtension());
|
||||
$environment->addExtension(new StrikethroughExtension());
|
||||
$environment->addExtension(new TaskListExtension());
|
||||
|
||||
$converter = new MarkdownConverter($environment);
|
||||
|
||||
return trim((string) $converter->convert($markdown));
|
||||
}
|
||||
}
|
||||
@@ -480,14 +480,22 @@ class MarketingController extends Controller
|
||||
|
||||
public function packagesIndex()
|
||||
{
|
||||
$endcustomerPackages = Package::where('type', 'endcustomer')->orderBy('price')->get()->map(function ($p) {
|
||||
return $p->append(['features', 'limits']);
|
||||
});
|
||||
$resellerPackages = Package::where('type', 'reseller')->orderBy('price')->get()->map(function ($p) {
|
||||
return $p->append(['features', 'limits']);
|
||||
});
|
||||
$endcustomerPackages = Package::where('type', 'endcustomer')
|
||||
->orderBy('price')
|
||||
->get()
|
||||
->map(fn (Package $package) => $this->presentPackage($package))
|
||||
->values();
|
||||
|
||||
return Inertia::render('marketing/Packages', compact('endcustomerPackages', 'resellerPackages'));
|
||||
$resellerPackages = Package::where('type', 'reseller')
|
||||
->orderBy('price')
|
||||
->get()
|
||||
->map(fn (Package $package) => $this->presentPackage($package))
|
||||
->values();
|
||||
|
||||
return Inertia::render('marketing/Packages', [
|
||||
'endcustomerPackages' => $endcustomerPackages,
|
||||
'resellerPackages' => $resellerPackages,
|
||||
]);
|
||||
}
|
||||
|
||||
public function occasionsType($type)
|
||||
@@ -508,5 +516,170 @@ class MarketingController extends Controller
|
||||
|
||||
return Inertia::render('marketing/Occasions', ['type' => $type]);
|
||||
}
|
||||
}
|
||||
|
||||
private function presentPackage(Package $package): array
|
||||
{
|
||||
$package->append('limits');
|
||||
|
||||
$packageArray = $package->toArray();
|
||||
$features = $packageArray['features'] ?? [];
|
||||
$features = $this->normaliseFeatures($features);
|
||||
|
||||
$locale = app()->getLocale();
|
||||
$name = $this->resolveTranslation($package->name_translations ?? null, $package->name ?? '', $locale);
|
||||
$descriptionTemplate = $this->resolveTranslation($package->description_translations ?? null, $package->description ?? '', $locale);
|
||||
|
||||
$replacements = $this->buildPlaceholderReplacements($package);
|
||||
|
||||
$description = trim($this->applyPlaceholders($descriptionTemplate, $replacements));
|
||||
|
||||
$table = $package->description_table ?? [];
|
||||
if (is_string($table)) {
|
||||
$decoded = json_decode($table, true);
|
||||
$table = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
$table = array_map(function (array $row) use ($replacements) {
|
||||
return [
|
||||
'title' => trim($this->applyPlaceholders($row['title'] ?? '', $replacements)),
|
||||
'value' => trim($this->applyPlaceholders($row['value'] ?? '', $replacements)),
|
||||
];
|
||||
}, $table);
|
||||
$table = array_values($table);
|
||||
|
||||
$galleryDuration = $replacements['{{gallery_duration}}'] ?? null;
|
||||
|
||||
return [
|
||||
'id' => $package->id,
|
||||
'name' => $name,
|
||||
'slug' => $package->slug,
|
||||
'type' => $package->type,
|
||||
'price' => $package->price,
|
||||
'description' => $description,
|
||||
'description_breakdown' => $table,
|
||||
'gallery_duration_label' => $galleryDuration,
|
||||
'events' => $package->type === 'endcustomer' ? 1 : ($package->max_events_per_year ?? null),
|
||||
'features' => $features,
|
||||
'limits' => $package->limits,
|
||||
'max_photos' => $package->max_photos,
|
||||
'max_guests' => $package->max_guests,
|
||||
'max_tasks' => $package->max_tasks,
|
||||
'gallery_days' => $package->gallery_days,
|
||||
'max_events_per_year' => $package->max_events_per_year,
|
||||
'watermark_allowed' => (bool) $package->watermark_allowed,
|
||||
'branding_allowed' => (bool) $package->branding_allowed,
|
||||
];
|
||||
}
|
||||
|
||||
private function buildPlaceholderReplacements(Package $package): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'{{max_photos}}' => $this->formatCount($package->max_photos, [
|
||||
'de' => 'unbegrenzt viele',
|
||||
'en' => 'unlimited',
|
||||
]),
|
||||
'{{max_guests}}' => $this->formatCount($package->max_guests, [
|
||||
'de' => 'beliebig viele',
|
||||
'en' => 'any number of',
|
||||
]),
|
||||
'{{max_tasks}}' => $this->formatCount($package->max_tasks, [
|
||||
'de' => 'individuelle',
|
||||
'en' => 'custom',
|
||||
]),
|
||||
'{{max_events_per_year}}' => $this->formatCount($package->max_events_per_year, [
|
||||
'de' => 'unbegrenzte',
|
||||
'en' => 'unlimited',
|
||||
]),
|
||||
'{{gallery_duration}}' => $this->formatGalleryDuration($package->gallery_days),
|
||||
];
|
||||
}
|
||||
|
||||
private function applyPlaceholders(string $template, array $replacements): string
|
||||
{
|
||||
if ($template === '') {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return str_replace(array_keys($replacements), array_values($replacements), $template);
|
||||
}
|
||||
|
||||
private function formatCount(?int $value, array $fallbackByLocale): string
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
if ($value === null) {
|
||||
return $fallbackByLocale[$locale] ?? reset($fallbackByLocale) ?? '';
|
||||
}
|
||||
|
||||
$decimal = $locale === 'de' ? ',' : '.';
|
||||
$thousands = $locale === 'de' ? '.' : ',';
|
||||
|
||||
return number_format($value, 0, $decimal, $thousands);
|
||||
}
|
||||
|
||||
private function formatGalleryDuration(?int $days): string
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
if (!$days || $days <= 0) {
|
||||
return $locale === 'en' ? 'permanent' : 'dauerhaft';
|
||||
}
|
||||
|
||||
if ($days % 30 === 0) {
|
||||
$months = (int) ($days / 30);
|
||||
if ($locale === 'en') {
|
||||
return $months === 1 ? '1 month' : $months . ' months';
|
||||
}
|
||||
|
||||
return $months === 1 ? '1 Monat' : $months . ' Monate';
|
||||
}
|
||||
|
||||
return $locale === 'en' ? $days . ' days' : $days . ' Tage';
|
||||
}
|
||||
|
||||
private function normaliseFeatures(mixed $features): array
|
||||
{
|
||||
if (is_string($features)) {
|
||||
$decoded = json_decode($features, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$features = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
if (! is_array($features)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($features as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$list[] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_string($key) && (bool) $value) {
|
||||
$list[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter($list, fn ($item) => is_string($item) && $item !== '')));
|
||||
}
|
||||
|
||||
private function resolveTranslation(mixed $value, string $fallback, string $locale): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$value = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return trim((string) ($value[$locale] ?? $value['en'] ?? $value['de'] ?? $fallback));
|
||||
}
|
||||
|
||||
return trim((string) ($value ?? $fallback));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ class Package extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'name_translations',
|
||||
'slug',
|
||||
'type',
|
||||
'price',
|
||||
'max_photos',
|
||||
@@ -25,6 +27,8 @@ class Package extends Model
|
||||
'expires_after',
|
||||
'features',
|
||||
'description',
|
||||
'description_translations',
|
||||
'description_table',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -38,6 +42,9 @@ class Package extends Model
|
||||
'watermark_allowed' => 'boolean',
|
||||
'branding_allowed' => 'boolean',
|
||||
'features' => 'array',
|
||||
'name_translations' => 'array',
|
||||
'description_translations' => 'array',
|
||||
'description_table' => 'array',
|
||||
];
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user