Deploy Ladill QR Plus / deploy (push) Successful in 1m15s
Store per-account preferences in qr_settings and pre-fill the create flow with saved type and brand styling. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Qr\QrStyleDefaults;
|
|
use App\Support\Qr\QrTypeCatalog;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/** Per-account QR Plus preferences (notifications and new-code defaults). */
|
|
class QrSetting extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'notify_email',
|
|
'product_updates',
|
|
'low_balance_alerts',
|
|
'default_type',
|
|
'default_style',
|
|
];
|
|
|
|
protected $casts = [
|
|
'product_updates' => 'boolean',
|
|
'low_balance_alerts' => 'boolean',
|
|
'default_style' => 'array',
|
|
];
|
|
|
|
/** @return list<string> */
|
|
public static function storableStyleKeys(): array
|
|
{
|
|
return [
|
|
'foreground',
|
|
'background',
|
|
'error_correction',
|
|
'margin',
|
|
'module_style',
|
|
'finder_outer',
|
|
'finder_inner',
|
|
'frame_style',
|
|
'frame_text',
|
|
'frame_color',
|
|
'gradient_type',
|
|
'gradient_color1',
|
|
'gradient_color2',
|
|
'gradient_rotation',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function resolvedDefaultType(): string
|
|
{
|
|
$type = (string) ($this->default_type ?? QrCode::TYPE_URL);
|
|
|
|
return in_array($type, QrTypeCatalog::plusTypes(), true) ? $type : QrCode::TYPE_URL;
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function resolvedDefaultStyle(): array
|
|
{
|
|
$stored = collect($this->default_style ?? [])
|
|
->only(self::storableStyleKeys())
|
|
->filter(fn ($value) => $value !== null && $value !== '')
|
|
->all();
|
|
|
|
return QrStyleDefaults::merge($stored !== [] ? $stored : null);
|
|
}
|
|
|
|
/** @param array<string, mixed>|null $input */
|
|
public static function sanitizeDefaultStyle(?array $input): ?array
|
|
{
|
|
if ($input === null) {
|
|
return null;
|
|
}
|
|
|
|
$merged = QrStyleDefaults::merge(
|
|
collect($input)->only(self::storableStyleKeys())->all(),
|
|
);
|
|
|
|
return collect($merged)->only(self::storableStyleKeys())->all();
|
|
}
|
|
}
|