Deploy Ladill Events / deploy (push) Successful in 1m39s
Upload logo in account settings and prefer it over Ladill product marks in event notification headers. Co-authored-by: Cursor <cursoragent@cursor.com>
91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\QrSetting;
|
|
use App\Models\User;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AccountBranding
|
|
{
|
|
public static function forUser(User $user): QrSetting
|
|
{
|
|
return $user->getOrCreateQrSetting();
|
|
}
|
|
|
|
public static function forOwnerRef(string $ownerPublicId): ?QrSetting
|
|
{
|
|
$user = User::query()->where('public_id', $ownerPublicId)->first();
|
|
|
|
return $user ? $user->getOrCreateQrSetting() : null;
|
|
}
|
|
|
|
public static function companyName(?QrSetting $settings, ?User $user = null): string
|
|
{
|
|
if ($user) {
|
|
return (string) ($user->name ?: 'Company');
|
|
}
|
|
|
|
if ($settings?->user) {
|
|
return (string) ($settings->user->name ?: 'Company');
|
|
}
|
|
|
|
if ($settings?->user_id) {
|
|
$owner = User::query()->find($settings->user_id);
|
|
|
|
return (string) ($owner?->name ?: 'Company');
|
|
}
|
|
|
|
return 'Company';
|
|
}
|
|
|
|
public static function hasCustomLogo(?QrSetting $settings): bool
|
|
{
|
|
return $settings !== null
|
|
&& $settings->logo_path !== null
|
|
&& Storage::disk('public')->exists($settings->logo_path);
|
|
}
|
|
|
|
public static function emailLogoUrl(?QrSetting $settings): ?string
|
|
{
|
|
if (! self::hasCustomLogo($settings)) {
|
|
return null;
|
|
}
|
|
|
|
$ext = strtolower(pathinfo((string) $settings->logo_path, PATHINFO_EXTENSION));
|
|
if ($ext === 'svg') {
|
|
return null;
|
|
}
|
|
|
|
$version = $settings->updated_at?->getTimestamp() ?? time();
|
|
|
|
return Storage::disk('public')->url($settings->logo_path).'?v='.$version;
|
|
}
|
|
|
|
public static function logoUrl(?QrSetting $settings): ?string
|
|
{
|
|
if (! self::hasCustomLogo($settings)) {
|
|
return null;
|
|
}
|
|
|
|
$version = $settings->updated_at?->getTimestamp() ?? time();
|
|
|
|
return Storage::disk('public')->url($settings->logo_path).'?v='.$version;
|
|
}
|
|
|
|
public static function storeLogo(QrSetting $settings, UploadedFile $file): string
|
|
{
|
|
self::deleteStoredLogo($settings);
|
|
|
|
return $file->store('events/accounts/'.$settings->user_id, 'public');
|
|
}
|
|
|
|
public static function deleteStoredLogo(QrSetting $settings): void
|
|
{
|
|
if ($settings->logo_path) {
|
|
Storage::disk('public')->delete($settings->logo_path);
|
|
}
|
|
}
|
|
}
|