event photo wasserzeichen umgesetzt. Event admins können eigene einsetzen (als branding) falls das Paket es erlaubt. der Super Admin kann für die günstigen Pakete eigene Wasserzeichen erzwingen
This commit is contained in:
@@ -258,6 +258,7 @@ class EventResource extends Resource
|
||||
'create' => Pages\CreateEvent::route('/create'),
|
||||
'view' => Pages\ViewEvent::route('/{record}'),
|
||||
'edit' => Pages\EditEvent::route('/{record}/edit'),
|
||||
'watermark' => Pages\ManageWatermark::route('/{record}/watermark'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
141
app/Filament/Resources/EventResource/Pages/ManageWatermark.php
Normal file
141
app/Filament/Resources/EventResource/Pages/ManageWatermark.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\EventResource\Pages;
|
||||
|
||||
use App\Filament\Resources\EventResource;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ManageWatermark extends Page
|
||||
{
|
||||
protected static string $resource = EventResource::class;
|
||||
|
||||
protected string $view = 'filament.resources.event-resource.pages.manage-watermark';
|
||||
|
||||
public ?string $watermark_mode = 'base';
|
||||
public ?string $watermark_asset = null;
|
||||
public string $watermark_position = 'bottom-right';
|
||||
public float $watermark_opacity = 0.25;
|
||||
public float $watermark_scale = 0.2;
|
||||
public int $watermark_padding = 16;
|
||||
public bool $serve_originals = false;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$event = $this->record;
|
||||
$settings = $event->settings ?? [];
|
||||
$watermark = Arr::get($settings, 'watermark', []);
|
||||
|
||||
$this->watermark_mode = $watermark['mode'] ?? 'base';
|
||||
$this->watermark_asset = $watermark['asset'] ?? null;
|
||||
$this->watermark_position = $watermark['position'] ?? 'bottom-right';
|
||||
$this->watermark_opacity = (float) ($watermark['opacity'] ?? 0.25);
|
||||
$this->watermark_scale = (float) ($watermark['scale'] ?? 0.2);
|
||||
$this->watermark_padding = (int) ($watermark['padding'] ?? 16);
|
||||
$this->serve_originals = (bool) Arr::get($settings, 'watermark_serve_originals', false);
|
||||
}
|
||||
|
||||
protected function getForms(): array
|
||||
{
|
||||
return [
|
||||
'form' => $this->form(
|
||||
$this->makeForm()
|
||||
->schema([
|
||||
Forms\Components\Fieldset::make(__('filament-watermark.heading'))
|
||||
->schema([
|
||||
Forms\Components\Select::make('watermark_mode')
|
||||
->label(__('filament-watermark.mode.label'))
|
||||
->options([
|
||||
'base' => __('filament-watermark.mode.base'),
|
||||
'custom' => __('filament-watermark.mode.custom'),
|
||||
'off' => __('filament-watermark.mode.off'),
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\FileUpload::make('watermark_asset')
|
||||
->label(__('filament-watermark.asset'))
|
||||
->disk('public')
|
||||
->directory('branding')
|
||||
->preserveFilenames()
|
||||
->image()
|
||||
->visible(fn (callable $get) => $get('watermark_mode') === 'custom'),
|
||||
Forms\Components\Select::make('watermark_position')
|
||||
->label(__('filament-watermark.position'))
|
||||
->options([
|
||||
'top-left' => 'Top Left',
|
||||
'top-right' => 'Top Right',
|
||||
'bottom-left' => 'Bottom Left',
|
||||
'bottom-right' => 'Bottom Right',
|
||||
'center' => 'Center',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('watermark_opacity')
|
||||
->label(__('filament-watermark.opacity'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1)
|
||||
->step(0.05)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('watermark_scale')
|
||||
->label(__('filament-watermark.scale'))
|
||||
->numeric()
|
||||
->minValue(0.05)
|
||||
->maxValue(1)
|
||||
->step(0.05)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('watermark_padding')
|
||||
->label(__('filament-watermark.padding'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->required(),
|
||||
Forms\Components\Toggle::make('serve_originals')
|
||||
->label(__('filament-watermark.serve_originals'))
|
||||
->helperText('Nur Admin/Owner: falls aktiviert, werden Originale statt watermarked ausgeliefert.')
|
||||
->default(false),
|
||||
])
|
||||
->columns(2),
|
||||
])
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$event = $this->record;
|
||||
$package = $event->eventPackage?->package;
|
||||
|
||||
$brandingAllowed = $package?->branding_allowed === true;
|
||||
$policy = $package?->watermark_allowed === false ? 'none' : 'basic';
|
||||
|
||||
if (! $brandingAllowed && $this->watermark_mode === 'custom') {
|
||||
Notification::make()->title('Branding nicht erlaubt für dieses Paket')->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($policy === 'basic' && $this->watermark_mode === 'off') {
|
||||
Notification::make()->title('Kein Wasserzeichen ist in diesem Paket nicht erlaubt')->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $event->settings ?? [];
|
||||
$settings['watermark'] = [
|
||||
'mode' => $this->watermark_mode,
|
||||
'asset' => $this->watermark_asset,
|
||||
'position' => $this->watermark_position,
|
||||
'opacity' => (float) $this->watermark_opacity,
|
||||
'scale' => (float) $this->watermark_scale,
|
||||
'padding' => (int) $this->watermark_padding,
|
||||
];
|
||||
$settings['watermark_serve_originals'] = $this->serve_originals;
|
||||
|
||||
$event->forceFill(['settings' => $settings])->save();
|
||||
|
||||
Notification::make()
|
||||
->title(__('filament-watermark.saved'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
103
app/Filament/SuperAdmin/Pages/WatermarkSettingsPage.php
Normal file
103
app/Filament/SuperAdmin/Pages/WatermarkSettingsPage.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\SuperAdmin\Pages;
|
||||
|
||||
use App\Models\WatermarkSetting;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class WatermarkSettingsPage extends Page
|
||||
{
|
||||
protected static null|string|\BackedEnum $navigationIcon = 'heroicon-o-sparkles';
|
||||
|
||||
protected string $view = 'filament.super-admin.pages.watermark-settings-page';
|
||||
|
||||
protected static null|string|\UnitEnum $navigationGroup = 'Branding';
|
||||
|
||||
protected static ?int $navigationSort = 20;
|
||||
|
||||
public ?string $asset = null;
|
||||
public string $position = 'bottom-right';
|
||||
public float $opacity = 0.25;
|
||||
public float $scale = 0.2;
|
||||
public int $padding = 16;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$settings = WatermarkSetting::query()->first();
|
||||
|
||||
if ($settings) {
|
||||
$this->asset = $settings->asset;
|
||||
$this->position = $settings->position;
|
||||
$this->opacity = (float) $settings->opacity;
|
||||
$this->scale = (float) $settings->scale;
|
||||
$this->padding = (int) $settings->padding;
|
||||
}
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\FileUpload::make('asset')
|
||||
->label('Basis-Wasserzeichen (PNG/SVG empfohlen)')
|
||||
->disk('public')
|
||||
->directory('branding')
|
||||
->preserveFilenames()
|
||||
->image()
|
||||
->required(),
|
||||
Forms\Components\Select::make('position')
|
||||
->label('Position')
|
||||
->options([
|
||||
'top-left' => 'Oben links',
|
||||
'top-right' => 'Oben rechts',
|
||||
'bottom-left' => 'Unten links',
|
||||
'bottom-right' => 'Unten rechts',
|
||||
'center' => 'Zentriert',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('opacity')
|
||||
->label('Opacity (0–1)')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1)
|
||||
->step(0.05)
|
||||
->default(0.25)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('scale')
|
||||
->label('Skalierung (0–1, relativ zur Bildbreite)')
|
||||
->numeric()
|
||||
->minValue(0.05)
|
||||
->maxValue(1)
|
||||
->step(0.05)
|
||||
->default(0.2)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('padding')
|
||||
->label('Padding (px)')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(16)
|
||||
->required(),
|
||||
])->columns(2);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$settings = WatermarkSetting::query()->firstOrNew([]);
|
||||
$settings->asset = $this->asset;
|
||||
$settings->position = $this->position;
|
||||
$settings->opacity = $this->opacity;
|
||||
$settings->scale = $this->scale;
|
||||
$settings->padding = $this->padding;
|
||||
$settings->save();
|
||||
|
||||
Notification::make()
|
||||
->title('Wasserzeichen aktualisiert')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user