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:
90
app/Support/WatermarkConfigResolver.php
Normal file
90
app/Support/WatermarkConfigResolver.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class WatermarkConfigResolver
|
||||
{
|
||||
public static function determineBrandingAllowed(Event $event): bool
|
||||
{
|
||||
$event->loadMissing('eventPackage.package');
|
||||
|
||||
return $event->eventPackage?->package?->branding_allowed === true;
|
||||
}
|
||||
|
||||
public static function determinePolicy(Event $event): string
|
||||
{
|
||||
$event->loadMissing('eventPackage.package');
|
||||
|
||||
return $event->eventPackage?->package?->watermark_allowed === false ? 'none' : 'basic';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{type:string, policy:string, asset?:string, position?:string, opacity?:float, scale?:float, padding?:int}
|
||||
*/
|
||||
public static function resolve(Event $event): array
|
||||
{
|
||||
$policy = self::determinePolicy($event);
|
||||
|
||||
if ($policy === 'none') {
|
||||
return [
|
||||
'type' => 'none',
|
||||
'policy' => $policy,
|
||||
];
|
||||
}
|
||||
|
||||
$baseSetting = WatermarkSetting::query()->first();
|
||||
$base = [
|
||||
'asset' => $baseSetting?->asset ?? config('watermark.base.asset', 'branding/fotospiel-watermark.png'),
|
||||
'position' => $baseSetting?->position ?? config('watermark.base.position', 'bottom-right'),
|
||||
'opacity' => $baseSetting?->opacity ?? config('watermark.base.opacity', 0.25),
|
||||
'scale' => $baseSetting?->scale ?? config('watermark.base.scale', 0.2),
|
||||
'padding' => $baseSetting?->padding ?? config('watermark.base.padding', 16),
|
||||
];
|
||||
|
||||
$event->loadMissing('eventPackage.package', 'tenant');
|
||||
$brandingAllowed = self::determineBrandingAllowed($event);
|
||||
$eventWatermark = Arr::get($event->settings, 'watermark', []);
|
||||
$tenantWatermark = Arr::get($event->tenant?->settings, 'watermark', []);
|
||||
$serveOriginals = (bool) Arr::get($event->settings, 'watermark_serve_originals', false);
|
||||
|
||||
$mode = $brandingAllowed
|
||||
? ($eventWatermark['mode'] ?? $tenantWatermark['mode'] ?? 'base')
|
||||
: 'base';
|
||||
|
||||
if ($mode === 'off' && $policy === 'basic') {
|
||||
$mode = 'base';
|
||||
}
|
||||
|
||||
if ($mode === 'off') {
|
||||
return [
|
||||
'type' => 'none',
|
||||
'policy' => $policy,
|
||||
];
|
||||
}
|
||||
|
||||
$source = $mode === 'custom' && $brandingAllowed ? ($eventWatermark ?: $tenantWatermark) : [];
|
||||
|
||||
$asset = $source['asset'] ?? $base['asset'] ?? null;
|
||||
$position = $source['position'] ?? $base['position'] ?? 'bottom-right';
|
||||
$opacity = (float) ($source['opacity'] ?? $base['opacity'] ?? 0.25);
|
||||
$scale = (float) ($source['scale'] ?? $base['scale'] ?? 0.2);
|
||||
$padding = (int) ($source['padding'] ?? $base['padding'] ?? 16);
|
||||
|
||||
$clamp = static fn (float $value, float $min, float $max) => max($min, min($max, $value));
|
||||
|
||||
return [
|
||||
'type' => $mode === 'custom' && $brandingAllowed ? 'custom' : 'base',
|
||||
'policy' => $policy,
|
||||
'asset' => $asset,
|
||||
'position' => $position,
|
||||
'opacity' => $clamp($opacity, 0.0, 1.0),
|
||||
'scale' => $clamp($scale, 0.05, 1.0),
|
||||
'padding' => max(0, $padding),
|
||||
'serve_originals' => $serveOriginals,
|
||||
];
|
||||
}
|
||||
}
|
||||
use App\Models\WatermarkSetting;
|
||||
Reference in New Issue
Block a user